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

Method test_run_stringflags

Lib/test/test_capi/test_run.py:40–71  ·  view source on GitHub ↗
(self)

Source from the content-addressed store, hash-verified

38 # PyRun_FileFlags (may be a macro)
39
40 def test_run_stringflags(self):
41 # Test PyRun_StringFlags().
42 # XXX: fopen() uses different path encoding than Python on Windows.
43 def run(s, *args):
44 return _testcapi.run_stringflags(s, Py_file_input, *args)
45 source = b'a\n'
46
47 self.assertIsNone(run(b'a\n', dict(a=1)))
48 self.assertIsNone(run(b'a\n', dict(a=1), {}))
49 self.assertIsNone(run(b'a\n', {}, dict(a=1)))
50 self.assertIsNone(run(b'a\n', {}, UserDict(a=1)))
51
52 self.assertRaises(NameError, run, b'a\n', {})
53 self.assertRaises(NameError, run, b'a\n', {}, {})
54 self.assertRaises(TypeError, run, b'a\n', dict(a=1), [])
55 self.assertRaises(TypeError, run, b'a\n', dict(a=1), 1)
56
57 self.assertIsNone(run(b'a\n', DictSubclass(a=1)))
58 self.assertIsNone(run(b'a\n', DictSubclass(), dict(a=1)))
59 self.assertRaises(NameError, run, b'a\n', DictSubclass())
60
61 self.assertIsNone(run(b'\xc3\xa4\n', {'\xe4': 1}))
62 self.assertRaises(SyntaxError, run, b'\xe4\n', {})
63
64 self.assertRaises(SystemError, run, b'a\n', NULL)
65 self.assertRaises(SystemError, run, b'a\n', NULL, {})
66 self.assertRaises(SystemError, run, b'a\n', NULL, dict(a=1))
67 self.assertRaises(SystemError, run, b'a\n', UserDict())
68 self.assertRaises(SystemError, run, b'a\n', UserDict(), {})
69 self.assertRaises(SystemError, run, b'a\n', UserDict(), dict(a=1))
70
71 # CRASHES run(NULL, {})
72
73 def test_run_fileexflags(self):
74 # Test PyRun_FileExFlags().

Callers

nothing calls this directly

Calls 5

UserDictClass · 0.90
assertIsNoneMethod · 0.80
DictSubclassClass · 0.70
runFunction · 0.50
assertRaisesMethod · 0.45

Tested by

no test coverage detected