1 # This Source Code Form is subject to the terms of the Mozilla Public
2 # License, v. 2.0. If a copy of the MPL was not distributed with this
3 # file, You can obtain one at http://mozilla.org/MPL/2.0/.
5 from __future__
import absolute_import
, print_function
, unicode_literals
11 from unittest
.mock
import MagicMock
12 from moztest
.resolve
import TestResolver
13 from taskgraph
.graph
import Graph
14 from taskgraph
.task
import Task
15 from taskgraph
.taskgraph
import TaskGraph
17 from tryselect
import push
22 if not hasattr(request
.module
, "TASKS"):
24 "'tg' fixture used from a module that didn't define the TASKS variable"
27 tasks
= request
.module
.TASKS
29 task
.setdefault("task", {})
30 task
["task"].setdefault("tags", {})
32 tasks
= {t
["label"]: Task(**t
) for t
in tasks
}
33 return TaskGraph(tasks
, Graph(tasks
.keys(), set()))
37 def patch_resolver(monkeypatch
):
38 def inner(suites
, tests
):
39 def fake_test_metadata(*args
, **kwargs
):
42 monkeypatch
.setattr(TestResolver
, "resolve_metadata", fake_test_metadata
)
47 @pytest.fixture(autouse
=True)
48 def patch_vcs(monkeypatch
):
50 "path": push
.vcs
.path
,
53 mock
.configure_mock(**attrs
)
54 monkeypatch
.setattr(push
, "vcs", mock
)
57 @pytest.fixture(scope
="session")
59 import mach_initialize
60 from mach
.config
import ConfigSettings
61 from tryselect
.tasks
import build
63 mach
= mach_initialize
.initialize(build
.topsrcdir
)
66 mach
.settings
= ConfigSettings()
72 def pytest_generate_tests(metafunc
):
74 fixture
in metafunc
.fixturenames
75 for fixture
in ("task_config", "args", "expected")
79 for task_config
, tests
in metafunc
.module
.TASK_CONFIG_TESTS
.items():
80 for args
, expected
in tests
:
81 yield (task_config
, args
, expected
)
83 tests
= list(load_tests())
84 ids
= ["{} {}".format(t
[0], " ".join(t
[1])).strip() for t
in tests
]
85 metafunc
.parametrize("task_config,args,expected", tests
, ids
=ids
)
88 fixture
in metafunc
.fixturenames
for fixture
in ("shared_name", "shared_preset")
90 preset_path
= os
.path
.join(
91 push
.build
.topsrcdir
, "tools", "tryselect", "try_presets.yml"
93 with
open(preset_path
, "r") as fh
:
94 presets
= list(yaml
.safe_load(fh
).items())
96 ids
= [p
[0] for p
in presets
]
98 # Mark fuzzy presets on Windows xfail due to fzf not being installed.
100 for i
, preset
in enumerate(presets
):
101 if preset
[1]["selector"] == "fuzzy":
102 presets
[i
] = pytest
.param(*preset
, marks
=pytest
.mark
.xfail
)
104 metafunc
.parametrize("shared_name,shared_preset", presets
, ids
=ids
)