MCPcopy Index your code
hub / github.com/python/cpython / test_comments

Method test_comments

Lib/test/test_fstring.py:738–787  ·  view source on GitHub ↗
(self)

Source from the content-addressed store, hash-verified

736 ])
737
738 def test_comments(self):
739 # These aren't comments, since they're in strings.
740 d = {'#': 'hash'}
741 self.assertEqual(f'{"#"}', '#')
742 self.assertEqual(f'{d["#"]}', 'hash')
743
744 self.assertAllRaise(SyntaxError, "'{' was never closed",
745 ["f'{1#}'", # error because everything after '#' is a comment
746 "f'{#}'",
747 "f'one: {1#}'",
748 "f'{1# one} {2 this is a comment still#}'",
749 ])
750 self.assertAllRaise(SyntaxError, r"f-string: unmatched '\)'",
751 ["f'{)#}'", # When wrapped in parens, this becomes
752 # '()#)'. Make sure that doesn't compile.
753 ])
754 self.assertEqual(f'''A complex trick: {
7552 # two
756}''', 'A complex trick: 2')
757 self.assertEqual(f'''
758{
75940 # forty
760+ # plus
7612 # two
762}''', '\n42')
763 self.assertEqual(f'''
764{
76540 # forty
766+ # plus
7672 # two
768}''', '\n42')
769
770 self.assertEqual(f'''
771# this is not a comment
772{ # the following operation it's
7733 # this is a number
774* 2}''', '\n# this is not a comment\n6')
775 self.assertEqual(f'''
776{# f'a {comment}'
77786 # constant
778# nothing more
779}''', '\n86')
780
781 self.assertAllRaise(SyntaxError, r"f-string: valid expression required before '}'",
782 ["""f'''
783{
784# only a comment
785}'''
786""", # this is equivalent to f'{}'
787 ])
788
789 def test_many_expressions(self):
790 # Create a string with many expressions in it. Note that

Callers

nothing calls this directly

Calls 2

assertEqualMethod · 0.95
assertAllRaiseMethod · 0.95

Tested by

no test coverage detected