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

Method test_run_package_init_exceptions

Lib/test/test_runpy.py:457–483  ·  view source on GitHub ↗
(self)

Source from the content-addressed store, hash-verified

455 self._check_package(depth)
456
457 def test_run_package_init_exceptions(self):
458 # These were previously wrapped in an ImportError; see Issue 14285
459 result = self._make_pkg("", 1, "__main__")
460 pkg_dir, _, mod_name, _ = result
461 mod_name = mod_name.replace(".__main__", "")
462 self.addCleanup(self._del_pkg, pkg_dir)
463 init = os.path.join(pkg_dir, "__runpy_pkg__", "__init__.py")
464
465 exceptions = (ImportError, AttributeError, TypeError, ValueError)
466 for exception in exceptions:
467 name = exception.__name__
468 with self.subTest(name):
469 source = "raise {0}('{0} in __init__.py.')".format(name)
470 with open(init, "wt", encoding="ascii") as mod_file:
471 mod_file.write(source)
472 try:
473 run_module(mod_name)
474 except exception as err:
475 self.assertNotIn("finding spec", format(err))
476 else:
477 self.fail("Nothing raised; expected {}".format(name))
478 try:
479 run_module(mod_name + ".submodule")
480 except exception as err:
481 self.assertNotIn("finding spec", format(err))
482 else:
483 self.fail("Nothing raised; expected {}".format(name))
484
485 def test_submodule_imported_warning(self):
486 pkg_dir, _, mod_name, _ = self._make_pkg("", 1)

Callers

nothing calls this directly

Calls 12

_make_pkgMethod · 0.95
run_moduleFunction · 0.90
formatFunction · 0.85
addCleanupMethod · 0.80
assertNotInMethod · 0.80
openFunction · 0.50
replaceMethod · 0.45
joinMethod · 0.45
subTestMethod · 0.45
formatMethod · 0.45
writeMethod · 0.45
failMethod · 0.45

Tested by

no test coverage detected