summaryrefslogtreecommitdiffstats
path: root/testing/raptor/test/conftest.py
blob: e5ba0ac96cd7e2df8384393bda5edd4fd9019499 (plain)
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
63
64
65
66
67
68
69
70
71
72
73
74
75
76
77
78
79
80
81
82
83
84
85
86
87
88
89
90
91
92
93
94
95
96
97
98
99
100
101
102
103
104
105
106
107
108
109
110
111
112
113
114
115
116
117
118
119
120
121
122
123
124
125
126
127
128
129
130
131
132
133
134
135
136
137
138
139
140
141
142
143
144
145
146
147
148
149
150
151
152
153
154
155
156
157
158
159
import json
import os
import sys
from argparse import Namespace

import pytest

# need this so the raptor unit tests can find raptor/raptor classes
here = os.path.abspath(os.path.dirname(__file__))
raptor_dir = os.path.join(os.path.dirname(here), "raptor")
sys.path.insert(0, raptor_dir)

from browsertime import Browsertime
from perftest import Perftest


@pytest.fixture
def options(request):
    opts = {
        "app": "firefox",
        "binary": "path/to/dummy/browser",
        "browsertime_visualmetrics": False,
        "extra_prefs": {},
    }

    if hasattr(request.module, "OPTIONS"):
        opts.update(request.module.OPTIONS)
    return opts


@pytest.fixture
def browsertime_options(options):
    options["browsertime_node"] = "browsertime_node"
    options["browsertime_browsertimejs"] = "browsertime_browsertimejs"
    options["browsertime_ffmpeg"] = "browsertime_ffmpeg"
    options["browsertime_geckodriver"] = "browsertime_geckodriver"
    options["browsertime_chromedriver"] = "browsertime_chromedriver"
    options["browsertime_video"] = "browsertime_video"
    options["browsertime_visualmetrics"] = "browsertime_visualmetrics"
    options["browsertime_no_ffwindowrecorder"] = "browsertime_no_ffwindowrecorder"
    return options


@pytest.fixture
def mock_test():
    return {
        "name": "raptor-firefox-tp6",
        "test_url": "/dummy/url",
        "secondary_url": "/dummy/url-2",
    }


@pytest.fixture(scope="session")
def get_prefs():
    def _inner(browser):
        import raptor

        prefs_dir = os.path.join(raptor.__file__, "preferences")
        with open(os.path.join(prefs_dir, "{}.json".format(browser)), "r") as fh:
            return json.load(fh)


@pytest.fixture(scope="session")
def filedir():
    return os.path.join(here, "files")


@pytest.fixture
def get_binary():
    from moztest.selftest import fixtures

    def inner(app):
        if app != "firefox":
            pytest.xfail(reason="{} support not implemented".format(app))

        binary = fixtures.binary()
        if not binary:
            pytest.skip("could not find a {} binary".format(app))
        return binary

    return inner


@pytest.fixture
def create_args():
    args = Namespace(
        app="firefox",
        test="browsertime-tp6-unittest",
        binary="path/to/binary",
        gecko_profile=False,
        extra_profiler_run=False,
        debug_mode=False,
        page_cycles=None,
        page_timeout=None,
        test_url_params=None,
        host=None,
        run_local=True,
        browsertime=True,
        cold=False,
        live_sites=False,
        enable_marionette_trace=False,
        collect_perfstats=False,
        chimera=False,
    )

    def inner(**kwargs):
        for next_arg in kwargs:
            print(next_arg)
            print(kwargs[next_arg])
            setattr(args, next_arg, kwargs[next_arg])
        return args

    return inner


@pytest.fixture(scope="module")
def ConcretePerftest():
    class PerftestImplementation(Perftest):
        def check_for_crashes(self):
            super(PerftestImplementation, self).check_for_crashes()

        def clean_up(self):
            super(PerftestImplementation, self).clean_up()

        def run_test(self, test, timeout):
            super(PerftestImplementation, self).run_test(test, timeout)

        def run_test_setup(self, test):
            super(PerftestImplementation, self).run_test_setup(test)

        def run_test_teardown(self, test):
            super(PerftestImplementation, self).run_test_teardown(test)

        def set_browser_test_prefs(self):
            super(PerftestImplementation, self).set_browser_test_prefs()

        def get_browser_meta(self):
            return (), ()

        def setup_chrome_args(self, test):
            super(PerftestImplementation, self).setup_chrome_args(test)

    return PerftestImplementation


@pytest.fixture(scope="module")
def ConcreteBrowsertime():
    class BrowsertimeImplementation(Browsertime):
        @property
        def browsertime_args(self):
            return []

        def get_browser_meta(self):
            return (), ()

        def setup_chrome_args(self, test):
            super(BrowsertimeImplementation, self).setup_chrome_args(test)

    return BrowsertimeImplementation