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

Method test_import

Lib/test/test_compileall.py:1121–1146  ·  view source on GitHub ↗
(self)

Source from the content-addressed store, hash-verified

1119 self.assertFalse(filecmp.cmp(pycs[1], pycs[2], shallow=True))
1120
1121 def test_import(self):
1122 # Test that import updates a single pyc file when pyc files already
1123 # exists and the script content changed
1124 with self.temporary_directory():
1125 script = self.make_script(self.create_code(), name="module")
1126 self.compile_dir()
1127 # All three levels have the same inode
1128 self.check_hardlinks(script)
1129
1130 pycs = get_pycs(script)
1131 inode = os.stat(pycs[0]).st_ino
1132
1133 # Change of the module content
1134 script = self.make_script("print(0)", name="module")
1135
1136 # Import the module in Python with -O (optimization level 1)
1137 script_helper.assert_python_ok(
1138 "-O", "-c", "import module", __isolated=False, PYTHONPATH=self.path
1139 )
1140
1141 # Only opt-1.pyc is changed
1142 self.assertEqual(inode, os.stat(pycs[0]).st_ino)
1143 self.assertEqual(inode, os.stat(pycs[2]).st_ino)
1144 self.assertFalse(is_hardlink(pycs[1], pycs[2]))
1145 # opt-1.pyc and opt-2.pyc have different content
1146 self.assertFalse(filecmp.cmp(pycs[1], pycs[2], shallow=True))
1147
1148
1149class HardlinkDedupTestsWithSourceEpoch(HardlinkDedupTestsBase,

Callers

nothing calls this directly

Calls 11

temporary_directoryMethod · 0.95
make_scriptMethod · 0.95
create_codeMethod · 0.95
compile_dirMethod · 0.95
check_hardlinksMethod · 0.95
get_pycsFunction · 0.85
is_hardlinkFunction · 0.85
assert_python_okMethod · 0.80
assertFalseMethod · 0.80
statMethod · 0.45
assertEqualMethod · 0.45

Tested by

no test coverage detected