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

Method test_invalid_syntax

Lib/test/test__interpreters.py:958–980  ·  view source on GitHub ↗
(self)

Source from the content-addressed store, hash-verified

956 """)
957
958 def test_invalid_syntax(self):
959 script = dedent("""
960 x = 1 + 2
961 y = 2 + 4
962 z = 4 + 8
963
964 # missing close paren
965 print("spam"
966
967 if x + y + z < 20:
968 ...
969 """)
970
971 with self.subTest('script'):
972 with self.assertRaises(SyntaxError):
973 _interpreters.run_string(self.id, script)
974
975 with self.subTest('module'):
976 modname = 'spam_spam_spam'
977 filename = self.add_module(modname, script)
978 self.assert_run_failed(SyntaxError, f"""
979 import {modname}
980 """)
981
982 def test_NameError(self):
983 self.assert_run_failed(NameError, """

Callers

nothing calls this directly

Calls 5

add_moduleMethod · 0.95
assert_run_failedMethod · 0.95
dedentFunction · 0.90
subTestMethod · 0.45
assertRaisesMethod · 0.45

Tested by

no test coverage detected