Bug 1711441 [wpt PR 29015] - WritableStreamDefaultController should now be exposed...
[gecko.git] / taskcluster / test / conftest.py
blob83f044fd7ef64e2bd091b780d3985519caf7ac8a
1 # Any copyright is dedicated to the public domain.
2 # http://creativecommons.org/publicdomain/zero/1.0/
4 from __future__ import absolute_import
6 import json
7 import logging
8 import os
10 import pytest
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")
23 def responses():
24 rsps_logger.setLevel(logging.WARNING)
25 with RequestsMock(assert_all_requests_are_fired=False) as rsps:
26 yield rsps
29 @pytest.fixture(scope="session")
30 def datadir():
31 return os.path.join(here, "data")
34 @pytest.fixture(scope="session")
35 def create_tgg(responses, datadir):
37 # Setup logging.
38 lm = LoggingManager()
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.
47 mock_requests = {}
49 # bugbug /push/schedules
50 url = BUGBUG_BASE_URL + "/push/{project}/{head_rev}/schedules".format(
51 **tgg.parameters
53 mock_requests[url] = "bugbug-push-schedules.json"
55 # files changed
56 url = "{head_repository}/json-automationrelevance/{head_rev}".format(
57 **tgg.parameters
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:
70 responses.add(
71 responses.GET,
72 url,
73 json=json.load(fh),
74 status=200,
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")
80 return tgg
82 return inner
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)
91 return tgg
94 @pytest.fixture(scope="module")
95 def params(tgg):
96 return tgg.parameters
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")
110 def filter_tasks():
111 def inner(graph, func):
112 return filter(func, graph.tasks.values())
114 return inner
117 @pytest.fixture(scope="session")
118 def print_dependents():
119 def inner(graph, label, indent=""):
120 if indent == "":
121 print(f"Dependent graph for {label}:")
123 dependents = set()
124 for task in graph.tasks.values():
125 if label in task.dependencies.values():
126 dependents.add(task.label)
128 print(f"{indent}{label}")
129 if dependents:
130 for dep in sorted(dependents):
131 inner(graph, dep, indent=indent + " ")
133 return inner