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
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
)
24 def test_try_again(monkeypatch
):
28 try_task_config
=push
.generate_try_task_config(
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
):
42 monkeypatch
.setattr(push
, "push_to_try", fake_push_to_try
)
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
)
65 try_task_config
=push
.generate_try_task_config(
68 {"use-artifact-builds": True},
72 assert not os
.path
.isfile(push
.history_path
)
73 assert again
.run() == 1
76 if __name__
== "__main__":