Backed out changeset f53842753805 (bug 1804872) for causing reftest failures on 15535...
[gecko.git] / taskcluster / test / test_generate_params.py
blob87f1fe341cf784f68cd3f183cab21b82025a1f6c
1 import json
2 import os
3 import subprocess
5 import pytest
6 from gecko_taskgraph import GECKO
7 from mozunit import main
8 from taskgraph.taskgraph import TaskGraph
10 pytestmark = pytest.mark.slow
11 PARAMS_DIR = os.path.join(GECKO, "taskcluster", "test", "params")
14 @pytest.fixture(scope="module")
15 def get_graph_from_spec(tmpdir_factory):
16 outdir = tmpdir_factory.mktemp("graphs")
18 # Use a mach subprocess to leverage the auto parallelization of
19 # parameters when specifying a directory.
20 cmd = [
21 "./mach",
22 "taskgraph",
23 "morphed",
24 "--json",
25 f"--parameters={PARAMS_DIR}",
26 f"--output-file={outdir}/graph.json",
28 subprocess.run(cmd, cwd=GECKO)
29 assert len(outdir.listdir()) > 0
31 def inner(param_spec):
32 outfile = f"{outdir}/graph_{param_spec}.json"
33 with open(outfile) as fh:
34 output = fh.read()
35 try:
36 return TaskGraph.from_json(json.loads(output))[1]
37 except ValueError:
38 return output
40 return inner
43 @pytest.mark.parametrize(
44 "param_spec", [os.path.splitext(p)[0] for p in os.listdir(PARAMS_DIR)]
46 def test_generate_graphs(get_graph_from_spec, param_spec):
47 ret = get_graph_from_spec(param_spec)
48 if isinstance(ret, str):
49 print(ret)
50 pytest.fail("An exception was raised during graph generation!")
52 assert isinstance(ret, TaskGraph)
53 assert len(ret.tasks) > 0
56 if __name__ == "__main__":
57 main()