(self)
| 866 | self.assertEqual(f'{x} {x}', '1 2') |
| 867 | |
| 868 | def test_missing_expression(self): |
| 869 | self.assertAllRaise(SyntaxError, |
| 870 | "f-string: valid expression required before '}'", |
| 871 | ["f'{}'", |
| 872 | "f'{ }'" |
| 873 | "f' {} '", |
| 874 | "f'{10:{ }}'", |
| 875 | "f' { } '", |
| 876 | |
| 877 | # The Python parser ignores also the following |
| 878 | # whitespace characters in additional to a space. |
| 879 | "f'''{\t\f\r\n}'''", |
| 880 | ]) |
| 881 | |
| 882 | self.assertAllRaise(SyntaxError, |
| 883 | "f-string: valid expression required before '!'", |
| 884 | ["f'{!r}'", |
| 885 | "f'{ !r}'", |
| 886 | "f'{!}'", |
| 887 | "f'''{\t\f\r\n!a}'''", |
| 888 | |
| 889 | # Catch empty expression before the |
| 890 | # missing closing brace. |
| 891 | "f'{!'", |
| 892 | "f'{!s:'", |
| 893 | |
| 894 | # Catch empty expression before the |
| 895 | # invalid conversion. |
| 896 | "f'{!x}'", |
| 897 | "f'{ !xr}'", |
| 898 | "f'{!x:}'", |
| 899 | "f'{!x:a}'", |
| 900 | "f'{ !xr:}'", |
| 901 | "f'{ !xr:a}'", |
| 902 | ]) |
| 903 | |
| 904 | self.assertAllRaise(SyntaxError, |
| 905 | "f-string: valid expression required before ':'", |
| 906 | ["f'{:}'", |
| 907 | "f'{ :!}'", |
| 908 | "f'{:2}'", |
| 909 | "f'''{\t\f\r\n:a}'''", |
| 910 | "f'{:'", |
| 911 | "F'{[F'{:'}[F'{:'}]]]", |
| 912 | ]) |
| 913 | |
| 914 | self.assertAllRaise(SyntaxError, |
| 915 | "f-string: valid expression required before '='", |
| 916 | ["f'{=}'", |
| 917 | "f'{ =}'", |
| 918 | "f'{ =:}'", |
| 919 | "f'{ =!}'", |
| 920 | "f'''{\t\f\r\n=}'''", |
| 921 | "f'{='", |
| 922 | ]) |
| 923 | |
| 924 | # Different error message is raised for other whitespace characters. |
| 925 | self.assertAllRaise(SyntaxError, r"invalid non-printable character U\+00A0", |
nothing calls this directly
no test coverage detected