Skip to content

Commit 59f97e0

Browse files
committed
test: add some additional tests
1 parent a0209ee commit 59f97e0

File tree

3 files changed

+59
-7
lines changed

3 files changed

+59
-7
lines changed

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

Lines changed: 6 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -1,3 +1,4 @@
1+
from copy import deepcopy
12
from pathlib import Path
23

34
import pytest
@@ -193,20 +194,25 @@ def target_tasks_method(full_task_graph, parameters, graph_config):
193194

194195
@pytest.fixture
195196
def make_transform_config(parameters, graph_config):
197+
default_graph_config = graph_config
198+
196199
def inner(
197200
kind_config=None,
198201
kind_dependencies_tasks=None,
202+
graph_config=None,
199203
extra_params=None,
200204
extra_graph_config=None,
201205
):
202206
kind_config = kind_config or {}
203207
kind_dependencies_tasks = kind_dependencies_tasks or {}
208+
graph_config = graph_config or deepcopy(default_graph_config)
204209
if extra_params:
205210
parameters.update(extra_params)
206211
if extra_graph_config:
207212
# We need this intermediate variable because `GraphConfig` is
208213
# frozen and we can't set attributes on it.
209214
new_graph_config = merge(graph_config._config, extra_graph_config)
215+
graph_config._config.clear()
210216
graph_config._config.update(new_graph_config)
211217

212218
return TransformConfig(

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-1d0c10d2cdc5a6f1acd71c0b363719b15805bcdd809ad7b459a43796203ff2c4",
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"}]

test/test_util_cached_tasks.py

Lines changed: 3 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -190,7 +190,9 @@ def test_add_optimization(
190190
cache_type = "cache-type"
191191
cache_name = "cache-name"
192192

193-
config = make_transform_config(None, None, extra_params, extra_graph_config)
193+
config = make_transform_config(
194+
None, None, extra_params=extra_params, extra_graph_config=extra_graph_config
195+
)
194196

195197
try:
196198
add_optimization(

0 commit comments

Comments
 (0)