Ejemplo n.º 1
0
    def run_tests(self, **kwargs):
        MachCommandBase._activate_virtualenv(self)

        from pathlib import Path
        from mozperftest.runner import _setup_path
        from mozperftest.utils import install_package, temporary_env

        # include in sys.path all deps
        _setup_path()

        try:
            import black  # noqa
        except ImportError:
            # install the tests scripts in the virtualenv
            # this step will be removed once Bug 1635573 is done
            # so we don't have to hit pypi or our internal mirror at all
            pydeps = Path(self.topsrcdir, "third_party", "python")

            for name in (
                    # installing pyrsistent and attrs so we don't pick newer ones
                    str(pydeps / "pyrsistent"),
                    str(pydeps / "attrs"),
                    "coverage",
                    "black",
                    "flake8",
            ):
                install_package(self.virtualenv_manager, name)

        here = Path(__file__).parent.resolve()
        if not ON_TRY:
            # formatting the code with black
            assert self._run_python_script("black", str(here))

        # checking flake8 correctness
        assert self._run_python_script("flake8", str(here))

        # running pytest with coverage
        # coverage is done in three steps:
        # 1/ coverage erase => erase any previous coverage data
        # 2/ coverage run pytest ... => run the tests and collect info
        # 3/ coverage report => generate the report
        tests = here / "tests"
        import pytest

        with temporary_env(COVERAGE_RCFILE=str(here / ".coveragerc")):
            assert self._run_python_script("coverage",
                                           "erase",
                                           label="remove old coverage data")
            args = [
                "run",
                pytest.__file__,
                "-xs",
                str(tests.resolve()),
            ]
            assert self._run_python_script("coverage",
                                           *args,
                                           label="running tests")
            if not self._run_python_script("coverage", "report", display=True):
                raise ValueError("Coverage is too low!")
Ejemplo n.º 2
0
    def run_tests(self, **kwargs):
        MachCommandBase.activate_virtualenv(self)

        from pathlib import Path
        from mozperftest.utils import temporary_env

        with temporary_env(COVERAGE_RCFILE=str(Path(HERE, ".coveragerc")),
                           RUNNING_TESTS="YES"):
            self._run_tests(**kwargs)
Ejemplo n.º 3
0
def run_tests(command_context, **kwargs):
    command_context.activate_virtualenv()

    from pathlib import Path
    from mozperftest.utils import temporary_env

    with temporary_env(COVERAGE_RCFILE=str(Path(HERE, ".coveragerc")),
                       RUNNING_TESTS="YES"):
        _run_tests(command_context, **kwargs)
Ejemplo n.º 4
0
def test_test_runner(*mocked):
    # simulating on try to run the paths parser
    old = mach_commands.ON_TRY
    mach_commands.ON_TRY = True
    with _get_command(PerftestTests) as test, silence(test), temporary_env(
            MOZ_AUTOMATION="1"):
        test.run_tests(tests=[EXAMPLE_TESTS_DIR])

    mach_commands.ON_TRY = old
Ejemplo n.º 5
0
def running_on_try(on_try=True):
    old = utils.ON_TRY
    utils.ON_TRY = on_try
    try:
        if on_try:
            with utils.temporary_env(MOZ_AUTOMATION="1"):
                yield
        else:
            yield
    finally:
        utils.ON_TRY = old
Ejemplo n.º 6
0
def test_install_url(*mocked):
    url = "https://here/tarball/" + "".join(
        [random.choice(string.hexdigits[:-6]) for c in range(40)])
    mach, metadata, env = get_running_env(browsertime_install_url=url)
    browser = env.layers[TEST]
    env.set_arg("tests", [EXAMPLE_TEST])

    try:
        with temporary_env(MOZ_AUTOMATION="1"), browser as b, silence():
            b(metadata)
    finally:
        shutil.rmtree(mach._mach_context.state_dir)

    assert mach.run_process.call_count == 1
Ejemplo n.º 7
0
def test_install_url(*mocked):
    url = "https://here/tarball/" + "".join(
        [random.choice(string.hexdigits[:-6]) for c in range(40)])
    mach, metadata, env = get_running_env(
        browsertime_install_url=url,
        tests=[EXAMPLE_TEST],
        browsertime_no_window_recorder=False,
        browsertime_viewport_size="1234x567",
    )
    browser = env.layers[TEST]
    sys = env.layers[SYSTEM]

    try:
        with sys as s, temporary_env(
                MOZ_AUTOMATION="1"), browser as b, silence():
            b(s(metadata))
    finally:
        shutil.rmtree(mach._mach_context.state_dir)

    assert mach.run_process.call_count == 1
Ejemplo n.º 8
0
    def run_tests(self, **kwargs):
        MachCommandBase._activate_virtualenv(self)

        from pathlib import Path
        from mozperftest.runner import _setup_path
        from mozperftest.utils import install_package, temporary_env

        skip_linters = kwargs.get("skip_linters", False)

        # include in sys.path all deps
        _setup_path()
        try:
            import coverage  # noqa
        except ImportError:
            pydeps = Path(self.topsrcdir, "third_party", "python")
            vendors = ["coverage"]
            if skip_linters:
                pypis = []
            else:
                pypis = ["flake8"]

            # if we're not on try we want to install black
            if not ON_TRY and not skip_linters:
                pypis.append("black")

            # these are the deps we are getting from pypi
            for dep in pypis:
                install_package(self.virtualenv_manager, dep)

            # pip-installing dependencies that require compilation or special setup
            for dep in vendors:
                install_package(self.virtualenv_manager, str(Path(pydeps,
                                                                  dep)))

        here = Path(__file__).parent.resolve()
        if not ON_TRY and not skip_linters:
            # formatting the code with black
            assert self._run_python_script("black", str(here))

        # checking flake8 correctness
        if not (ON_TRY and sys.platform == "darwin") and not skip_linters:
            assert self._run_python_script("flake8", str(here))

        # running pytest with coverage
        # coverage is done in three steps:
        # 1/ coverage erase => erase any previous coverage data
        # 2/ coverage run pytest ... => run the tests and collect info
        # 3/ coverage report => generate the report
        tests_dir = Path(here, "tests").resolve()
        tests = kwargs.get("tests", [])
        if tests == []:
            tests = str(tests_dir)
            run_coverage_check = not skip_linters
        else:
            run_coverage_check = False

            def _get_test(test):
                if Path(test).exists():
                    return str(test)
                return str(tests_dir / test)

            tests = " ".join([_get_test(test) for test in tests])

        import pytest

        with temporary_env(COVERAGE_RCFILE=str(here / ".coveragerc")):
            if run_coverage_check:
                assert self._run_python_script(
                    "coverage", "erase", label="remove old coverage data")
            args = [
                "run",
                pytest.__file__,
                "-xs",
                tests,
            ]
            assert self._run_python_script("coverage",
                                           *args,
                                           label="running tests")
            if run_coverage_check and not self._run_python_script(
                    "coverage", "report", display=True):
                raise ValueError("Coverage is too low!")
Ejemplo n.º 9
0
def test_xvfb_env(*mocked):
    with temporary_env(DISPLAY=None):
        with mock.patch("subprocess.Popen") as mocked, xvfb():
            mocked.assert_called()
        assert "DISPLAY" not in os.environ
Ejemplo n.º 10
0
def test_xvfb(*mocked):
    with temporary_env(DISPLAY="ME"):
        with mock.patch("subprocess.Popen") as mocked, xvfb():
            mocked.assert_called()
        assert os.environ["DISPLAY"] == "ME"