Skip to content

Commit 867356c

Browse files
committed
test: add some additional tests
1 parent 2bd5762 commit 867356c

File tree

2 files changed

+54
-6
lines changed

2 files changed

+54
-6
lines changed

packages/pytest-taskgraph/src/pytest_taskgraph/fixtures/gen.py

Lines changed: 4 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -193,14 +193,18 @@ def target_tasks_method(full_task_graph, parameters, graph_config):
193193

194194
@pytest.fixture
195195
def make_transform_config(parameters, graph_config):
196+
default_graph_config = graph_config
197+
196198
def inner(
197199
kind_config=None,
198200
kind_dependencies_tasks=None,
201+
graph_config=None,
199202
extra_params=None,
200203
extra_graph_config=None,
201204
):
202205
kind_config = kind_config or {}
203206
kind_dependencies_tasks = kind_dependencies_tasks or {}
207+
graph_config = graph_config or default_graph_config
204208
if extra_params:
205209
parameters.update(extra_params)
206210
if extra_graph_config:

test/test_transforms_run_run_task.py

Lines changed: 50 additions & 6 deletions
Original file line numberDiff line numberDiff line change
@@ -236,14 +236,18 @@ def inner(task, **kwargs):
236236

237237
caches = result["worker"][key]
238238
caches = [c for c in caches if "cache-name" in c]
239-
print("Dumping for copy/paste:")
239+
print("Dumping caches for copy/paste:")
240240
pprint(caches, indent=2)
241241

242+
env = result["worker"]["env"]
243+
print("Dumping env for copy/paste:")
244+
pprint(env, indent=2)
245+
242246
# Create a new schema object with just the part relevant to caches.
243247
partial_schema = Schema(payload_builders[impl].schema.schema[key])
244248
validate_schema(partial_schema, caches, "validation error")
245249

246-
return caches
250+
return caches, env
247251

248252
return inner
249253

@@ -254,12 +258,16 @@ def test_caches_enabled(run_caches):
254258
"use-caches": True,
255259
}
256260
}
257-
caches = run_caches(task)
261+
caches, env = run_caches(task)
258262
assert len(caches) == len(CACHES)
259263
cache_names = {c["cache-name"] for c in caches}
260264
for name, cfg in CACHES.items():
261265
if "cache_name" in cfg:
262266
continue
267+
268+
if "env" in cfg:
269+
assert cfg["env"] in env
270+
assert env[cfg["env"]] == f"{{task_workdir}}/.task-cache/{name}"
263271
assert name in cache_names
264272

265273

@@ -269,7 +277,7 @@ def test_caches_disabled(run_caches):
269277
"use-caches": False,
270278
}
271279
}
272-
assert run_caches(task) == []
280+
assert run_caches(task)[0] == []
273281

274282

275283
def test_caches_explicit(run_caches):
@@ -278,7 +286,7 @@ def test_caches_explicit(run_caches):
278286
"use-caches": ["cargo"],
279287
}
280288
}
281-
assert run_caches(task) == [
289+
assert run_caches(task)[0] == [
282290
{"cache-name": "cargo", "directory": ".task-cache/cargo"}
283291
]
284292

@@ -287,5 +295,41 @@ def test_caches_project_explicit(run_caches):
287295
caches = run_caches(
288296
{},
289297
extra_graph_config={"taskgraph": {"run": {"use-caches": ["cargo"]}}},
290-
)
298+
)[0]
291299
assert caches == [{"cache-name": "cargo", "directory": ".task-cache/cargo"}]
300+
301+
302+
def test_checkout_cache_name_multiple_repos(graph_config, run_caches):
303+
graph_config._config["taskgraph"]["repositories"] = {
304+
"foo": {
305+
"name": "Foo",
306+
"project-regex": "some-project",
307+
"default-repository": True,
308+
"default-ref": "foo",
309+
"type": "git",
310+
},
311+
"bar": {
312+
"name": "Bar",
313+
"project-regex": "other-project",
314+
"default-repository": False,
315+
"default-ref": "bar",
316+
"type": "git",
317+
},
318+
}
319+
caches = run_caches(
320+
{"run": {"checkout": {"foo": {}}, "use-caches": ["checkout"]}},
321+
graph_config=graph_config,
322+
)[0]
323+
assert caches == [
324+
{
325+
"cache-name": "checkouts-repos-299b346080c0dca622b70ba47481fc6d79931c4ccaf9e13d7a2ccf6ce4eb9b2a",
326+
"directory": "checkouts",
327+
}
328+
]
329+
330+
331+
def test_checkout_cache_name_sparse(run_caches):
332+
caches = run_caches({"run": {"sparse-profile": "foo", "use-caches": ["checkout"]}})[
333+
0
334+
]
335+
assert caches == [{"cache-name": "checkouts-sparse", "directory": "checkouts"}]

0 commit comments

Comments
 (0)