| 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 | |
| 1436 | class PathsTests(unittest.TestCase): |