def test_python_change_regenerate_everything(self): """If a Python file changes, we should attempt to rebuild everything.""" # We don't want to mutate files in the source directory because we want # to be able to build from a read-only filesystem. So, we install a # dummy module and rewrite the metadata to say it comes from the source # directory. # # Hacking imp to accept a MockedFile doesn't appear possible. So for # the first iteration we read from a temp file. The second iteration # doesn't need to import, so we are fine with a mocked file. fake_path = mozpath.join(OUR_DIR, 'fakemodule.py') with NamedTemporaryFile('wt') as fh: fh.write('# Original content') fh.flush() mod = imp.load_source('mozwebidlcodegen.fakemodule', fh.name) mod.__file__ = fake_path args = self._get_manager_args() m1 = WebIDLCodegenManager(**args) with MockedOpen({fake_path: '# Original content'}): try: result = m1.generate_build_files() l = len(result.inputs) with open(fake_path, 'wt') as fh: fh.write('# Modified content') m2 = WebIDLCodegenManager(**args) result = m2.generate_build_files() self.assertEqual(len(result.inputs), l) result = m2.generate_build_files() self.assertEqual(len(result.inputs), 0) finally: del sys.modules['mozwebidlcodegen.fakemodule']
def test_unknown_state_version(self): """Loading a state file with a too new version resets state.""" args = self._get_manager_args() p = args['state_path'] with open(p, 'wb') as fh: json.dump({ 'version': WebIDLCodegenManagerState.VERSION + 1, 'foobar': '1', }, fh) manager = WebIDLCodegenManager(**args) self.assertEqual(manager._state['version'], WebIDLCodegenManagerState.VERSION) self.assertNotIn('foobar', manager._state)
def test_unknown_state_version(self): """Loading a state file with a too new version resets state.""" args = self._get_manager_args() p = args["state_path"] with io.open(p, "w", newline="\n") as fh: json.dump( { "version": WebIDLCodegenManagerState.VERSION + 1, "foobar": "1", }, fh, ) manager = WebIDLCodegenManager(**args) self.assertEqual(manager._state["version"], WebIDLCodegenManagerState.VERSION) self.assertNotIn("foobar", manager._state)
def _get_manager(self): return WebIDLCodegenManager(**self._get_manager_args())