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

Method test_file_to_source

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

Source from the content-addressed store, hash-verified

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

Callers

nothing calls this directly

Calls 11

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

Tested by

no test coverage detected