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

Method test_file_to_source

Lib/test/test_import/__init__.py:620–641  ·  view source on GitHub ↗
(self)

Source from the content-addressed store, hash-verified

618
619 @skip_if_dont_write_bytecode
620 def test_file_to_source(self):
621 # check if __file__ points to the source file where available
622 source = TESTFN + ".py"
623 with open(source, "w", encoding='utf-8') as f:
624 f.write("test = None\n")
625
626 sys.path.insert(0, os.curdir)
627 try:
628 mod = __import__(TESTFN)
629 self.assertEndsWith(mod.__file__, '.py')
630 os.remove(source)
631 del sys.modules[TESTFN]
632 make_legacy_pyc(source)
633 importlib.invalidate_caches()
634 mod = __import__(TESTFN)
635 base, ext = os.path.splitext(mod.__file__)
636 self.assertEqual(ext, '.pyc')
637 finally:
638 del sys.path[0]
639 remove_files(TESTFN)
640 if TESTFN in sys.modules:
641 del sys.modules[TESTFN]
642
643 def test_import_by_filename(self):
644 path = os.path.abspath(TESTFN)

Callers

nothing calls this directly

Calls 11

make_legacy_pycFunction · 0.90
__import__Function · 0.85
remove_filesFunction · 0.85
assertEndsWithMethod · 0.80
splitextMethod · 0.80
openFunction · 0.50
writeMethod · 0.45
insertMethod · 0.45
removeMethod · 0.45
invalidate_cachesMethod · 0.45
assertEqualMethod · 0.45

Tested by

no test coverage detected