(self)
| 741 | |
| 742 | @unittest.expectedFailure # TODO: RUSTPYTHON |
| 743 | def test_comments(self): |
| 744 | # These aren't comments, since they're in strings. |
| 745 | d = {'#': 'hash'} |
| 746 | self.assertEqual(f'{"#"}', '#') |
| 747 | self.assertEqual(f'{d["#"]}', 'hash') |
| 748 | |
| 749 | self.assertAllRaise(SyntaxError, "'{' was never closed", |
| 750 | ["f'{1#}'", # error because everything after '#' is a comment |
| 751 | "f'{#}'", |
| 752 | "f'one: {1#}'", |
| 753 | "f'{1# one} {2 this is a comment still#}'", |
| 754 | ]) |
| 755 | self.assertAllRaise(SyntaxError, r"f-string: unmatched '\)'", |
| 756 | ["f'{)#}'", # When wrapped in parens, this becomes |
| 757 | # '()#)'. Make sure that doesn't compile. |
| 758 | ]) |
| 759 | self.assertEqual(f'''A complex trick: { |
| 760 | 2 # two |
| 761 | }''', 'A complex trick: 2') |
| 762 | self.assertEqual(f''' |
| 763 | { |
| 764 | 40 # forty |
| 765 | + # plus |
| 766 | 2 # two |
| 767 | }''', '\n42') |
| 768 | self.assertEqual(f''' |
| 769 | { |
| 770 | 40 # forty |
| 771 | + # plus |
| 772 | 2 # two |
| 773 | }''', '\n42') |
| 774 | |
| 775 | self.assertEqual(f''' |
| 776 | # this is not a comment |
| 777 | { # the following operation it's |
| 778 | 3 # this is a number |
| 779 | * 2}''', '\n# this is not a comment\n6') |
| 780 | self.assertEqual(f''' |
| 781 | {# f'a {comment}' |
| 782 | 86 # constant |
| 783 | # nothing more |
| 784 | }''', '\n86') |
| 785 | |
| 786 | self.assertAllRaise(SyntaxError, r"f-string: valid expression required before '}'", |
| 787 | ["""f''' |
| 788 | { |
| 789 | # only a comment |
| 790 | }''' |
| 791 | """, # this is equivalent to f'{}' |
| 792 | ]) |
| 793 | |
| 794 | def test_many_expressions(self): |
| 795 | # Create a string with many expressions in it. Note that |
nothing calls this directly
no test coverage detected