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

Method _check_relative_imports

Lib/test/test_runpy.py:400–438  ·  view source on GitHub ↗
(self, depth, run_name=None)

Source from the content-addressed store, hash-verified

398 if verbose > 1: print(" Added nephew module:", nephew_fname)
399
400 def _check_relative_imports(self, depth, run_name=None):
401 contents = r"""\
402from __future__ import absolute_import
403from . import sibling
404from ..uncle.cousin import nephew
405"""
406 pkg_dir, mod_fname, mod_name, mod_spec = (
407 self._make_pkg(contents, depth))
408 if run_name is None:
409 expected_name = mod_name
410 else:
411 expected_name = run_name
412 try:
413 self._add_relative_modules(pkg_dir, contents, depth)
414 pkg_name = mod_name.rpartition('.')[0]
415 if verbose > 1: print("Running from source:", mod_name)
416 d1 = run_module(mod_name, run_name=run_name) # Read from source
417 self.assertEqual(d1["__name__"], expected_name)
418 self.assertEqual(d1["__package__"], pkg_name)
419 self.assertIn("sibling", d1)
420 self.assertIn("nephew", d1)
421 del d1 # Ensure __loader__ entry doesn't keep file open
422 importlib.invalidate_caches()
423 __import__(mod_name)
424 os.remove(mod_fname)
425 if not sys.dont_write_bytecode:
426 make_legacy_pyc(mod_fname)
427 unload(mod_name) # In case the loader caches paths
428 if verbose > 1: print("Running from compiled:", mod_name)
429 importlib.invalidate_caches()
430 d2 = run_module(mod_name, run_name=run_name) # Read from bytecode
431 self.assertEqual(d2["__name__"], expected_name)
432 self.assertEqual(d2["__package__"], pkg_name)
433 self.assertIn("sibling", d2)
434 self.assertIn("nephew", d2)
435 del d2 # Ensure __loader__ entry doesn't keep file open
436 finally:
437 self._del_pkg(pkg_dir)
438 if verbose > 1: print("Module executed successfully")
439
440 def test_run_module(self):
441 for depth in range(4):

Callers 2

Calls 13

_make_pkgMethod · 0.95
_add_relative_modulesMethod · 0.95
_del_pkgMethod · 0.95
run_moduleFunction · 0.90
make_legacy_pycFunction · 0.90
unloadFunction · 0.90
assertInMethod · 0.80
printFunction · 0.50
__import__Function · 0.50
rpartitionMethod · 0.45
assertEqualMethod · 0.45
invalidate_cachesMethod · 0.45

Tested by

no test coverage detected