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

Method test_foreign_code

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

Source from the content-addressed store, hash-verified

1417 self.assertEqual(mod.func_filename, target)
1418
1419 def test_foreign_code(self):
1420 py_compile.compile(self.file_name)
1421 with open(self.compiled_name, "rb") as f:
1422 header = f.read(16)
1423 code = marshal.load(f)
1424 constants = list(code.co_consts)
1425 foreign_code = importlib.import_module.__code__
1426 pos = constants.index(1000)
1427 constants[pos] = foreign_code
1428 code = code.replace(co_consts=tuple(constants))
1429 with open(self.compiled_name, "wb") as f:
1430 f.write(header)
1431 marshal.dump(code, f)
1432 mod = self.import_module()
1433 self.assertEqual(mod.constant.co_filename, foreign_code.co_filename)
1434
1435
1436class PathsTests(unittest.TestCase):

Callers

nothing calls this directly

Calls 11

import_moduleMethod · 0.95
listClass · 0.85
openFunction · 0.50
compileMethod · 0.45
readMethod · 0.45
loadMethod · 0.45
indexMethod · 0.45
replaceMethod · 0.45
writeMethod · 0.45
dumpMethod · 0.45
assertEqualMethod · 0.45

Tested by

no test coverage detected