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

Method check_addmodule

Lib/test/test_capi/test_import.py:69–88  ·  view source on GitHub ↗
(self, add_module, accept_nonstr=False)

Source from the content-addressed store, hash-verified

67 # CRASHES getmodule(NULL)
68
69 def check_addmodule(self, add_module, accept_nonstr=False):
70 # create a new module
71 names = ['nonexistent']
72 if accept_nonstr:
73 names.append(b'\xff') # non-UTF-8
74 # PyImport_AddModuleObject() accepts non-string names
75 names.append(tuple(['hashable non-string']))
76 for name in names:
77 with self.subTest(name=name):
78 self.assertNotIn(name, sys.modules)
79 try:
80 module = add_module(name)
81 self.assertIsInstance(module, types.ModuleType)
82 self.assertEqual(module.__name__, name)
83 self.assertIs(module, sys.modules[name])
84 finally:
85 sys.modules.pop(name, None)
86
87 # get an existing module
88 self.check_import_loaded_module(add_module)
89
90 def test_addmoduleobject(self):
91 # Test PyImport_AddModuleObject()

Callers 3

test_addmoduleobjectMethod · 0.95
test_addmoduleMethod · 0.95
test_addmodulerefMethod · 0.95

Calls 9

add_moduleFunction · 0.85
assertNotInMethod · 0.80
assertIsInstanceMethod · 0.80
appendMethod · 0.45
subTestMethod · 0.45
assertEqualMethod · 0.45
assertIsMethod · 0.45
popMethod · 0.45

Tested by

no test coverage detected