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

Function test_import_statement

Lib/test/audit-tests.py:727–753  ·  view source on GitHub ↗
()

Source from the content-addressed store, hash-verified

725 )
726
727def test_import_statement():
728 import importlib # noqa: F401
729 # Set __package__ so relative imports work
730 with swap_item(globals(), "__package__", "test"):
731 with TestHook() as hook:
732 import importlib # noqa: F401
733 import email # noqa: F401
734 import pythoninfo # noqa: F401
735 from .audit_test_data import submodule # noqa: F401
736 import test.audit_test_data.submodule2 # noqa: F401
737 import _testcapi # noqa: F401
738
739 actual = [a for e, a in hook.seen if e == "import"]
740 # Import statement ordering is different because the package is
741 # loaded first and then the submodule
742 assertSequenceEqual(
743 [
744 ("email", None, sys.path, sys.meta_path, sys.path_hooks),
745 ("pythoninfo", None, sys.path, sys.meta_path, sys.path_hooks),
746 ("test.audit_test_data", None, sys.path, sys.meta_path, sys.path_hooks),
747 ("test.audit_test_data.submodule", None, sys.path, sys.meta_path, sys.path_hooks),
748 ("test.audit_test_data.submodule2", None, sys.path, sys.meta_path, sys.path_hooks),
749 ("_testcapi", None, sys.path, sys.meta_path, sys.path_hooks),
750 ("_testcapi", unittest.mock.ANY, None, None, None)
751 ],
752 actual,
753 )
754
755if __name__ == "__main__":
756 from test.support import suppress_msvcrt_asserts

Callers

nothing calls this directly

Calls 3

swap_itemFunction · 0.90
assertSequenceEqualFunction · 0.85
TestHookClass · 0.70

Tested by

no test coverage detected

Used in the wild real call sites across dependent graphs

searching dependent graphs…