Bug 1754025 [wpt PR 32729] - WebKit export of https://bugs.webkit.org/show_bug.cgi...
[gecko.git] / tools / tryselect / test / test_again.py
blobffe89a796d8914b71abcab6b3908887d68b3e517
1 # This Source Code Form is subject to the terms of the Mozilla Public
2 # License, v. 2.0. If a copy of the MPL was not distributed with this
3 # file, You can obtain one at http://mozilla.org/MPL/2.0/.
5 from __future__ import absolute_import, print_function, unicode_literals
7 import os
9 import mozunit
10 import pytest
12 from six.moves import reload_module as reload
14 from tryselect import push
15 from tryselect.selectors import again
18 @pytest.fixture(autouse=True)
19 def patch_history_path(tmpdir, monkeypatch):
20 monkeypatch.setattr(push, "history_path", tmpdir.join("history.json").strpath)
21 reload(again)
24 def test_try_again(monkeypatch):
25 push.push_to_try(
26 "fuzzy",
27 "Fuzzy message",
28 try_task_config=push.generate_try_task_config(
29 "fuzzy",
30 ["foo", "bar"],
31 {"use-artifact-builds": True},
35 assert os.path.isfile(push.history_path)
36 with open(push.history_path, "r") as fh:
37 assert len(fh.readlines()) == 1
39 def fake_push_to_try(*args, **kwargs):
40 return args, kwargs
42 monkeypatch.setattr(push, "push_to_try", fake_push_to_try)
43 reload(again)
45 args, kwargs = again.run()
47 assert args[0] == "again"
48 assert args[1] == "Fuzzy message"
50 try_task_config = kwargs.pop("try_task_config")
51 assert sorted(try_task_config.get("tasks")) == sorted(["foo", "bar"])
52 assert try_task_config.get("env") == {"TRY_SELECTOR": "fuzzy"}
53 assert try_task_config.get("use-artifact-builds")
55 with open(push.history_path, "r") as fh:
56 assert len(fh.readlines()) == 1
59 def test_no_push_does_not_generate_history(tmpdir):
60 assert not os.path.isfile(push.history_path)
62 push.push_to_try(
63 "fuzzy",
64 "Fuzzy",
65 try_task_config=push.generate_try_task_config(
66 "fuzzy",
67 ["foo", "bar"],
68 {"use-artifact-builds": True},
70 dry_run=True,
72 assert not os.path.isfile(push.history_path)
73 assert again.run() == 1
76 if __name__ == "__main__":
77 mozunit.main()