def __init__(self,
              mach_cmd,
              flavor="desktop-browser",
              hooks=None,
              **kwargs):
     MachEnvironment.__init__(self, mach_cmd, flavor, hooks, **kwargs)
     self.runs = 0
Esempio n. 2
0
def get_running_env(**kwargs):
    from mozbuild.base import MozbuildObject

    config = MozbuildObject.from_environment()
    mach_cmd = MagicMock()

    def get_binary_path(*args):
        return ""

    mach_cmd.get_binary_path = get_binary_path
    mach_cmd.topsrcdir = config.topsrcdir
    mach_cmd.topobjdir = config.topobjdir
    mach_cmd.distdir = config.distdir
    mach_cmd._mach_context = MagicMock()
    mach_cmd._mach_context.state_dir = tempfile.mkdtemp()
    mach_cmd.run_process.return_value = 0

    mach_args = {
        "flavor": "desktop-browser",
        "test_objects": None,
        "resolve_tests": True,
        "browsertime-clobber": False,
        "browsertime-install-url": None,
    }
    mach_args.update(kwargs)
    hooks = Hooks(mach_cmd, mach_args.pop("hooks", None))
    env = MachEnvironment(mach_cmd, hooks=hooks, **mach_args)
    metadata = Metadata(mach_cmd, env, "desktop-browser")
    return mach_cmd, metadata, env
Esempio n. 3
0
def test_layers():
    mach = MagicMock()
    factories = [_TestLayer, _TestLayer2, _TestLayer3]
    env = MachEnvironment(
        mach, no_test3=True, test_arg1="ok", test2=True, test2_arg2="2"
    )

    with Layers(env, mach, factories) as layers:
        # layer3 was deactivated with test3=False
        assert len(layers.layers) == 2
        layers.info("info")
        layers.debug("debug")
        layers.warning("warning")
        assert layers.get_arg("--test2")
        assert layers.get_arg("test-arg1") == "ok"
        layers.set_arg("test-arg1", "two")
        assert layers.get_arg("test-arg1") == "two"
        layers.set_arg("--test-arg1", 1)
        assert layers.get_arg("test-arg1") == 1
        assert layers.get_layer("test2").name == "test2"
        assert layers.get_layer("test3") is None
        assert layers.name == "test + test2"
        with pytest.raises(KeyError):
            layers.set_arg("another", 1)

    for layer in layers:
        assert layer.called == 2
Esempio n. 4
0
def get_running_env(**kwargs):
    from mozbuild.base import MozbuildObject

    config = MozbuildObject.from_environment()
    mach_cmd = MagicMock()

    def get_binary_path(*args):
        return ""

    def run_pip(args):
        pip = Path(sys.executable).parent / "pip"
        subprocess.check_call(
            [str(pip)] + args,
            stderr=subprocess.STDOUT,
            cwd=config.topsrcdir,
            universal_newlines=True,
        )

    mach_cmd.get_binary_path = get_binary_path
    mach_cmd.topsrcdir = config.topsrcdir
    mach_cmd.topobjdir = config.topobjdir
    mach_cmd.distdir = config.distdir
    mach_cmd._mach_context = MagicMock()
    mach_cmd._mach_context.state_dir = tempfile.mkdtemp()
    mach_cmd.run_process.return_value = 0
    mach_cmd.virtualenv_manager = MagicMock()
    mach_cmd.virtualenv_manager.python_path = sys.executable
    mach_cmd.virtualenv_manager.bin_path = Path(sys.executable).parent
    mach_cmd.virtualenv_manager._run_pip = run_pip

    mach_args = {
        "flavor": "desktop-browser",
        "test_objects": None,
        "resolve_tests": True,
        "browsertime-clobber": False,
        "browsertime-install-url": None,
    }
    mach_args.update(kwargs)
    hooks = Hooks(mach_cmd, mach_args.pop("hooks", None))
    tests = mach_args.get("tests", [])
    if len(tests) > 0:
        script = ScriptInfo(tests[0])
    else:
        script = None
    env = MachEnvironment(mach_cmd, hooks=hooks, **mach_args)
    metadata = Metadata(mach_cmd, env, "desktop-browser", script)
    return mach_cmd, metadata, env
Esempio n. 5
0
def test_layer():
    mach = MagicMock()
    env = MachEnvironment(mach, test=True, test_arg1="ok")

    with _TestLayer(env, mach) as layer:
        layer.info("info")
        layer.warning("warning")
        layer.debug("debug")
        assert layer.get_arg("test")
        assert layer.get_arg("arg1") == "ok"
        assert layer.get_arg("test-arg1") == "ok"
        layer.set_arg("arg1", "two")
        assert layer.get_arg("test-arg1") == "two"
        layer.set_arg("test-arg1", 1)
        assert layer.get_arg("test-arg1") == 1
        with pytest.raises(KeyError):
            layer.set_arg("another", 1)

        layer(object())

    assert layer.called == 2
Esempio n. 6
0
def get_running_env(**kwargs):
    from mozbuild.base import MozbuildObject

    config = MozbuildObject.from_environment()
    mach_cmd = MagicMock()
    mach_cmd.get_binary_path = lambda: ""
    mach_cmd.topsrcdir = config.topsrcdir
    mach_cmd.topobjdir = config.topobjdir
    mach_cmd._mach_context = MagicMock()
    mach_cmd._mach_context.state_dir = tempfile.mkdtemp()

    mach_args = {
        "flavor": "script",
        "test_objects": None,
        "resolve_tests": True,
        "browsertime-clobber": False,
        "browsertime-install-url": None,
    }
    mach_args.update(kwargs)
    env = MachEnvironment(mach_cmd, **mach_args)
    metadata = Metadata(mach_cmd, env, "script")
    return mach_cmd, metadata, env
Esempio n. 7
0
def test_layers():
    env = MachEnvironment(mock.MagicMock())
    assert env.get_layer("browsertime").name == "browsertime"
Esempio n. 8
0
def _get_env(hooks_path):
    return MachEnvironment(mock.MagicMock(),
                           hooks=Hooks(mock.MagicMock(), hooks_path))
Esempio n. 9
0
def test_run_hooks():
    hooks = str(Path(HERE, "data", "hook.py"))
    env = MachEnvironment(mock.MagicMock(), hooks=hooks)
    assert env.run_hook("doit") == "OK"
Esempio n. 10
0
def test_run_hooks_url():
    hooks = "http://somewhere/hooks.py"
    env = MachEnvironment(mock.MagicMock(), hooks=hooks)
    assert env.run_hook("doit") == "OK"
Esempio n. 11
0
def test_bad_hooks():
    hooks = "Idontexists"
    with pytest.raises(IOError):
        MachEnvironment(mock.MagicMock(), hooks=hooks)