MCPcopy Index your code
hub / github.com/RustPython/RustPython / test_end_of_numerical_literals

Method test_end_of_numerical_literals

Lib/test/test_grammar.py:139–177  ·  view source on GitHub ↗
(self)

Source from the content-addressed store, hash-verified

137
138 @unittest.expectedFailure # TODO: RUSTPYTHON
139 def test_end_of_numerical_literals(self):
140 def check(test, error=False):
141 with self.subTest(expr=test):
142 if error:
143 with warnings.catch_warnings(record=True) as w:
144 with self.assertRaisesRegex(SyntaxError,
145 r'invalid \w+ literal'):
146 compile(test, "<testcase>", "eval")
147 self.assertEqual(w, [])
148 else:
149 self.check_syntax_warning(test,
150 errtext=r'invalid \w+ literal')
151
152 for num in "0xf", "0o7", "0b1", "9", "0", "1.", "1e3", "1j":
153 compile(num, "<testcase>", "eval")
154 check(f"{num}and x", error=(num == "0xf"))
155 check(f"{num}or x", error=(num == "0"))
156 check(f"{num}in x")
157 check(f"{num}not in x")
158 check(f"{num}if x else y")
159 check(f"x if {num}else y", error=(num == "0xf"))
160 check(f"[{num}for x in ()]")
161 check(f"{num}spam", error=True)
162
163 # gh-88943: Invalid non-ASCII character following a numerical literal.
164 with self.assertRaisesRegex(SyntaxError, r"invalid character '⁄' \(U\+2044\)"):
165 compile(f"{num}⁄7", "<testcase>", "eval")
166
167 with self.assertWarnsRegex(SyntaxWarning, r'invalid \w+ literal'):
168 compile(f"{num}is x", "<testcase>", "eval")
169 with warnings.catch_warnings():
170 warnings.simplefilter('error', SyntaxWarning)
171 with self.assertRaisesRegex(SyntaxError,
172 r'invalid \w+ literal'):
173 compile(f"{num}is x", "<testcase>", "eval")
174
175 check("[0x1ffor x in ()]")
176 check("[0x1for x in ()]")
177 check("[0xfor x in ()]")
178
179 def test_string_literals(self):
180 x = ''; y = ""; self.assertTrue(len(x) == 0 and x == y)

Callers

nothing calls this directly

Calls 4

assertRaisesRegexMethod · 0.80
assertWarnsRegexMethod · 0.80
checkFunction · 0.70
compileFunction · 0.50

Tested by

no test coverage detected