def setup(self): """Install browsertime and visualmetrics.py prerequisites and the Node.js package. """ node = self.get_arg("node") if node is not None: os.environ["NODEJS"] = node super(BrowsertimeRunner, self).setup() install_url = self.get_arg("install-url") tests = self.get_arg("tests", []) if len(tests) != 1: # we don't support auto-discovery (no test passed) or multiple # tests here yet. raise NotImplementedError() self._test_script = ScriptInfo(tests[0]) # installing Python deps on the fly for dep in ("Pillow==%s" % PILLOW_VERSION, "pyssim==%s" % PYSSIM_VERSION): install_package(self.virtualenv_manager, dep, ignore_failure=True) # check if the browsertime package has been deployed correctly # for this we just check for the browsertime directory presence if (self.visualmetrics_py.exists() and self.browsertime_js.exists() and not self.get_arg("clobber")): return # preparing ~/.mozbuild/browsertime for file in ("package.json", "package-lock.json"): src = BROWSERTIME_SRC_ROOT / file target = self.state_path / file # Overwrite the existing files shutil.copyfile(str(src), str(target)) package_json_path = self.state_path / "package.json" if install_url is not None: self.info( "Updating browsertime node module version in {package_json_path} " "to {install_url}", install_url=install_url, package_json_path=str(package_json_path), ) expr = r"/tarball/[a-f0-9]{40}$" if not re.search(expr, install_url): raise ValueError( "New upstream URL does not end with {}: '{}'".format( expr[:-1], install_url)) with package_json_path.open() as f: existing_body = json.loads( f.read(), object_pairs_hook=collections.OrderedDict) existing_body["devDependencies"]["browsertime"] = install_url updated_body = json.dumps(existing_body) with package_json_path.open("w") as f: f.write(updated_body) self._setup_node_packages(package_json_path)
def test_scriptinfo_failure(): bad_example = HERE / "data" / "failing-samples" / "perftest_doc_failure_example.js" with pytest.raises(MissingFieldError): ScriptInfo(bad_example)
def run_tests(mach_cmd, **kwargs): """This tests runner can be used directly via main or via Mach. When the --on-try option is used, the test runner looks at the `PERFTEST_OPTIONS` environment variable that contains all options passed by the user via a ./mach perftest --push-to-try call. """ _setup_path() on_try = kwargs.pop("on_try", False) # trying to get the arguments from the task params if on_try: try_options = json.loads(os.environ["PERFTEST_OPTIONS"]) kwargs.update(try_options) from mozperftest.utils import build_test_list from mozperftest import MachEnvironment, Metadata from mozperftest.hooks import Hooks hooks = Hooks(mach_cmd, kwargs.pop("hooks", None)) verbose = kwargs.get("verbose", False) log_level = logging.DEBUG if verbose else logging.INFO # If we run through mach, we just want to set the level # of the existing termminal handler. # Otherwise, we're adding it. if mach_cmd.log_manager.terminal_handler is not None: mach_cmd.log_manager.terminal_handler.level = log_level else: mach_cmd.log_manager.add_terminal_logging(level=log_level) mach_cmd.log_manager.enable_all_structured_loggers() mach_cmd.log_manager.enable_unstructured() try: hooks.run("before_iterations", kwargs) for iteration in range(kwargs.get("test_iterations", 1)): flavor = kwargs["flavor"] kwargs["tests"], tmp_dir = build_test_list( kwargs["tests"], randomized=flavor != "doc") try: # XXX this doc is specific to browsertime scripts # maybe we want to move it if flavor == "doc": from mozperftest.test.browsertime.script import ScriptInfo for test in kwargs["tests"]: print(ScriptInfo(test)) return env = MachEnvironment(mach_cmd, hooks=hooks, **kwargs) metadata = Metadata(mach_cmd, env, flavor) hooks.run("before_runs", env) try: with env.frozen() as e: e.run(metadata) finally: hooks.run("after_runs", env) finally: if tmp_dir is not None: shutil.rmtree(tmp_dir) finally: hooks.cleanup()
def test_scriptinfo(): info = ScriptInfo(EXAMPLE_TEST) assert info["author"] == "N/A" display = str(info) assert "The description of the example test." in display