1 # Any copyright is dedicated to the public domain.
2 # http://creativecommons.org/publicdomain/zero/1.0/
9 from gecko_taskgraph
.util
.bugbug
import BUGBUG_BASE_URL
10 from gecko_taskgraph
.util
.hg
import PUSHLOG_PUSHES_TMPL
11 from responses
import RequestsMock
12 from responses
import logger
as rsps_logger
13 from taskgraph
.generator
import TaskGraphGenerator
14 from taskgraph
.parameters
import parameters_loader
16 here
= os
.path
.abspath(os
.path
.dirname(__file__
))
19 @pytest.fixture(scope
="session")
21 rsps_logger
.setLevel(logging
.WARNING
)
22 with
RequestsMock(assert_all_requests_are_fired
=False) as rsps
:
26 @pytest.fixture(scope
="session")
28 return os
.path
.join(here
, "data")
31 @pytest.fixture(scope
="session")
32 def create_tgg(responses
, datadir
):
33 def inner(parameters
=None, overrides
=None):
34 params
= parameters_loader(parameters
, strict
=False, overrides
=overrides
)
35 tgg
= TaskGraphGenerator(None, params
)
37 # Mock out certain requests as they may depend on a revision that does
38 # not exist on hg.mozilla.org.
41 # bugbug /push/schedules
42 url
= BUGBUG_BASE_URL
+ "/push/{project}/{head_rev}/schedules".format(
45 mock_requests
[url
] = "bugbug-push-schedules.json"
48 url
= "{head_repository}/json-automationrelevance/{head_rev}".format(
51 mock_requests
[url
] = "automationrelevance.json"
53 url
= PUSHLOG_PUSHES_TMPL
.format(
54 repository
=tgg
.parameters
["head_repository"],
55 push_id_start
=int(tgg
.parameters
["pushlog_id"]) - 2,
56 push_id_end
=int(tgg
.parameters
["pushlog_id"]) - 1,
58 mock_requests
[url
] = "pushes.json"
60 for url
, filename
in mock_requests
.items():
61 with
open(os
.path
.join(datadir
, filename
)) as fh
:
69 # Still allow other real requests.
70 responses
.add_passthru("https://hg.mozilla.org")
71 responses
.add_passthru("https://firefox-ci-tc.services.mozilla.com")
77 @pytest.fixture(scope
="module")
78 def tgg(request
, create_tgg
):
79 if not hasattr(request
.module
, "PARAMS"):
80 pytest
.fail("'tgg' fixture requires a module-level 'PARAMS' variable")
82 tgg
= create_tgg(overrides
=request
.module
.PARAMS
)
86 @pytest.fixture(scope
="module")
87 def tgg_new_config(request
, create_tgg
):
88 if not hasattr(request
.module
, "PARAMS_NEW_CONFIG"):
90 "'tgg_new_config' fixture requires a module-level 'PARAMS' variable"
93 tgg
= create_tgg(overrides
=request
.module
.PARAMS_NEW_CONFIG
)
97 @pytest.fixture(scope
="module")
102 @pytest.fixture(scope
="module")
103 def full_task_graph(tgg
):
104 return tgg
.full_task_graph
107 @pytest.fixture(scope
="module")
108 def optimized_task_graph(full_task_graph
, tgg
):
109 return tgg
.optimized_task_graph
112 @pytest.fixture(scope
="module")
113 def full_task_graph_new_config(tgg_new_config
):
114 return tgg_new_config
.full_task_graph
117 @pytest.fixture(scope
="module")
118 def optimized_task_graph_new_config(full_task_graph
, tgg_new_config
):
119 return tgg_new_config
.optimized_task_graph
122 @pytest.fixture(scope
="session")
124 def inner(graph
, func
):
125 return filter(func
, graph
.tasks
.values())
130 @pytest.fixture(scope
="session")
131 def print_dependents():
132 def inner(graph
, label
, indent
=""):
134 print(f
"Dependent graph for {label}:")
137 for task
in graph
.tasks
.values():
138 if label
in task
.dependencies
.values():
139 dependents
.add(task
.label
)
141 print(f
"{indent}{label}")
143 for dep
in sorted(dependents
):
144 inner(graph
, dep
, indent
=indent
+ " ")