Check that compileall recreates bytecode when the new metadata is used.
(self, metadata)
| 107 | self.assertTrue(compileall.compile_file(self.source_path)) |
| 108 | |
| 109 | def recreation_check(self, metadata): |
| 110 | """Check that compileall recreates bytecode when the new metadata is |
| 111 | used.""" |
| 112 | if os.environ.get('SOURCE_DATE_EPOCH'): |
| 113 | raise unittest.SkipTest('SOURCE_DATE_EPOCH is set') |
| 114 | py_compile.compile(self.source_path) |
| 115 | self.assertEqual(*self.timestamp_metadata()) |
| 116 | with open(self.bc_path, 'rb') as file: |
| 117 | bc = file.read()[len(metadata):] |
| 118 | with open(self.bc_path, 'wb') as file: |
| 119 | file.write(metadata) |
| 120 | file.write(bc) |
| 121 | self.assertNotEqual(*self.timestamp_metadata()) |
| 122 | compileall.compile_dir(self.directory, force=False, quiet=True) |
| 123 | self.assertTrue(*self.timestamp_metadata()) |
| 124 | |
| 125 | def test_mtime(self): |
| 126 | # Test a change in mtime leads to a new .pyc. |
no test coverage detected