(self)
| 1461 | self.assertEqual(mod.func_filename, target) |
| 1462 | |
| 1463 | def test_foreign_code(self): |
| 1464 | compiled_name = self.compiled_name or (self.file_name + 'c') |
| 1465 | py_compile.compile(self.file_name, compiled_name) |
| 1466 | with open(compiled_name, "rb") as f: |
| 1467 | header = f.read(16) |
| 1468 | code = marshal.load(f) |
| 1469 | constants = list(code.co_consts) |
| 1470 | foreign_code = importlib.import_module.__code__ |
| 1471 | pos = constants.index(1000) |
| 1472 | constants[pos] = foreign_code |
| 1473 | code = code.replace(co_consts=tuple(constants)) |
| 1474 | with open(compiled_name, "wb") as f: |
| 1475 | f.write(header) |
| 1476 | marshal.dump(code, f) |
| 1477 | if not self.compiled_name: |
| 1478 | os.remove(self.file_name) |
| 1479 | mod = self.import_module() |
| 1480 | self.assertEqual(mod.constant.co_filename, foreign_code.co_filename) |
| 1481 | |
| 1482 | |
| 1483 | class PathsTests(unittest.TestCase): |
nothing calls this directly
no test coverage detected