1 # Any copyright is dedicated to the public domain.
2 # http://creativecommons.org/publicdomain/zero/1.0/
4 from __future__
import absolute_import
11 from mach
.logging
import LoggingManager
12 from responses
import RequestsMock
, logger
as rsps_logger
14 from taskgraph
.generator
import TaskGraphGenerator
15 from taskgraph
.parameters
import parameters_loader
16 from taskgraph
.util
.hg
import PUSHLOG_PUSHES_TMPL
17 from taskgraph
.util
.bugbug
import BUGBUG_BASE_URL
19 here
= os
.path
.abspath(os
.path
.dirname(__file__
))
22 @pytest.fixture(scope
="session")
24 rsps_logger
.setLevel(logging
.WARNING
)
25 with
RequestsMock(assert_all_requests_are_fired
=False) as rsps
:
29 @pytest.fixture(scope
="session")
31 return os
.path
.join(here
, "data")
34 @pytest.fixture(scope
="session")
35 def create_tgg(responses
, datadir
):
39 lm
.add_terminal_logging()
41 def inner(parameters
=None, overrides
=None):
42 params
= parameters_loader(parameters
, strict
=False, overrides
=overrides
)
43 tgg
= TaskGraphGenerator(None, params
)
45 # Mock out certain requests as they may depend on a revision that does
46 # not exist on hg.mozilla.org.
49 # bugbug /push/schedules
50 url
= BUGBUG_BASE_URL
+ "/push/{project}/{head_rev}/schedules".format(
53 mock_requests
[url
] = "bugbug-push-schedules.json"
56 url
= "{head_repository}/json-automationrelevance/{head_rev}".format(
59 mock_requests
[url
] = "automationrelevance.json"
61 url
= PUSHLOG_PUSHES_TMPL
.format(
62 repository
=tgg
.parameters
["head_repository"],
63 push_id_start
=int(tgg
.parameters
["pushlog_id"]) - 2,
64 push_id_end
=int(tgg
.parameters
["pushlog_id"]) - 1,
66 mock_requests
[url
] = "pushes.json"
68 for url
, filename
in mock_requests
.items():
69 with
open(os
.path
.join(datadir
, filename
)) as fh
:
77 # Still allow other real requests.
78 responses
.add_passthru("https://hg.mozilla.org")
79 responses
.add_passthru("https://firefox-ci-tc.services.mozilla.com")
85 @pytest.fixture(scope
="module")
86 def tgg(request
, create_tgg
):
87 if not hasattr(request
.module
, "PARAMS"):
88 pytest
.fail("'tgg' fixture requires a module-level 'PARAMS' variable")
90 tgg
= create_tgg(overrides
=request
.module
.PARAMS
)
94 @pytest.fixture(scope
="module")
99 @pytest.fixture(scope
="module")
100 def full_task_graph(tgg
):
101 return tgg
.full_task_graph
104 @pytest.fixture(scope
="module")
105 def optimized_task_graph(full_task_graph
, tgg
):
106 return tgg
.optimized_task_graph
109 @pytest.fixture(scope
="session")
111 def inner(graph
, func
):
112 return filter(func
, graph
.tasks
.values())
117 @pytest.fixture(scope
="session")
118 def print_dependents():
119 def inner(graph
, label
, indent
=""):
121 print(f
"Dependent graph for {label}:")
124 for task
in graph
.tasks
.values():
125 if label
in task
.dependencies
.values():
126 dependents
.add(task
.label
)
128 print(f
"{indent}{label}")
130 for dep
in sorted(dependents
):
131 inner(graph
, dep
, indent
=indent
+ " ")