def verify_bytecode(self, mock, name): assert name in mock.module_paths self.assertIn(name, mock.module_bytecode) magic = mock.module_bytecode[name][:4] self.assertEqual(magic, imp.get_magic()) mtime = importlib._r_long(mock.module_bytecode[name][4:8]) self.assertEqual(mtime, 1) source_size = mock.module_bytecode[name][8:12] self.assertEqual( len(mock.source) & 0xFFFFFFFF, importlib._r_long(source_size)) bc = mock.module_bytecode[name][12:] self.assertEqual(bc, mock.compile_bc(name))
def verify_bytecode(self, mock, name): assert name in mock.module_paths self.assertIn(name, mock.module_bytecode) magic = mock.module_bytecode[name][:4] self.assertEqual(magic, imp.get_magic()) mtime = importlib._r_long(mock.module_bytecode[name][4:8]) self.assertEqual(mtime, 1) source_size = mock.module_bytecode[name][8:12] self.assertEqual(len(mock.source) & 0xFFFFFFFF, importlib._r_long(source_size)) bc = mock.module_bytecode[name][12:] self.assertEqual(bc, mock.compile_bc(name))
def verify_bytecode(self, mock, name): assert name in mock.module_paths self.assertIn(name, mock.module_bytecode) magic = mock.module_bytecode[name][:4] self.assertEqual(magic, imp.get_magic()) mtime = importlib._r_long(mock.module_bytecode[name][4:8]) self.assertEqual(mtime, 1) bc = mock.module_bytecode[name][8:] self.assertEqual(bc, mock.compile_bc(name))
def test_old_mtime(self): # Bytecode with an older mtime should be regenerated. name = 'mod' old_mtime = PyPycLoaderMock.default_mtime - 1 mock = PyPycLoaderMock({name: os.path.join('path', 'to', 'mod')}, {name: {'path': 'path/to/mod.bytecode', 'mtime': old_mtime}}) with util.uncache(name): mock.load_module(name) self.assertTrue(name in mock.module_bytecode) mtime = importlib._r_long(mock.module_bytecode[name][4:8]) self.assertEqual(mtime, PyPycLoaderMock.default_mtime)