|
3 | 3 |
|
4 | 4 | import os |
5 | 5 | from datetime import datetime |
| 6 | +from test.fixtures.gen import make_task |
6 | 7 | from time import mktime |
7 | 8 |
|
8 | 9 | import pytest |
9 | 10 |
|
10 | | -from taskgraph.optimize.strategies import IndexSearch |
| 11 | +from taskgraph.optimize.strategies import IndexSearch, SkipUnlessChanged |
11 | 12 |
|
12 | 13 |
|
13 | 14 | @pytest.fixture |
@@ -68,3 +69,34 @@ def test_index_search(responses, params, state, expires, expected): |
68 | 69 | opt = IndexSearch() |
69 | 70 | deadline = "2021-06-07T19:03:20.482Z" |
70 | 71 | assert opt.should_replace_task({}, params, deadline, (index_path,)) == expected |
| 72 | + |
| 73 | + |
| 74 | +@pytest.mark.parametrize( |
| 75 | + "params,file_patterns,should_optimize", |
| 76 | + ( |
| 77 | + pytest.param({"files_changed": []}, ["foo.txt"], True, id="no files changed"), |
| 78 | + pytest.param( |
| 79 | + {"files_changed": ["foo.txt"]}, ["foo.txt"], False, id="files match" |
| 80 | + ), |
| 81 | + pytest.param( |
| 82 | + {"files_changed": ["foo.txt"]}, |
| 83 | + ["bar.tx", "foo.txt"], |
| 84 | + False, |
| 85 | + id="files match multiple", |
| 86 | + ), |
| 87 | + pytest.param( |
| 88 | + {"files_changed": ["bar.txt"]}, ["foo.txt"], True, id="files don't match" |
| 89 | + ), |
| 90 | + pytest.param( |
| 91 | + {"repository_type": "hg", "pushlog_id": -1, "files_changed": ["bar.txt"]}, |
| 92 | + ["foo.txt"], |
| 93 | + False, |
| 94 | + id="cron task", |
| 95 | + ), |
| 96 | + ), |
| 97 | +) |
| 98 | +def test_skip_unless_changed(params, file_patterns, should_optimize): |
| 99 | + task = make_task("task") |
| 100 | + |
| 101 | + opt = SkipUnlessChanged() |
| 102 | + assert opt.should_remove_task(task, params, file_patterns) == should_optimize |
0 commit comments