Debian Codegraph @

python/mozversioncontrol/test/test_get_mozilla_remote_args.py

raw
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/.
4
5 from unittest import mock
6
7 import mozunit
8 import pytest
9
10 from mozversioncontrol import get_repository_object
11
12 STEPS = {
13 "hg": [],
14 "git": [
15 "git remote add blah https://example.com/blah",
16 """
17 git remote add unified hg::https://hg.mozilla.org/mozilla-unified
18 git remote add central hg::https://hg.mozilla.org/central
19 git remote add try hg::https://hg.mozilla.org/try
20 git remote add firefox https://github.com/mozilla-firefox/firefox
21 """,
22 ],
23 "jj": [],
24 }
25
26
27 @pytest.mark.parametrize(
28 "is_cinnabar,expected_remotes",
29 (
30 (
31 True,
32 [
33 "--remotes=central",
34 "--remotes=unified",
35 ],
36 ),
37 (False, ["--remotes=firefox"]),
38 ),
39 )
40 def test_get_mozilla_remote_args(is_cinnabar, expected_remotes, repo):
41 # Test is only relevant for Git.
42 if not repo.vcs == "git":
43 return
44
45 repo.execute_next_step()
46
47 vcs = get_repository_object(repo.dir)
48 vcs.is_cinnabar_repo = mock.MagicMock(name="is_cinnabar_repo")
49 vcs.is_cinnabar_repo.return_value = is_cinnabar
50
51 remotes = vcs.get_mozilla_remote_args()
52
53 assert remotes == [
54 "--remotes"
55 ], "Default `--remotes` passed without finding official remote."
56
57 repo.execute_next_step()
58
59 remotes = sorted(vcs.get_mozilla_remote_args())
60
61 assert (
62 remotes == expected_remotes
63 ), "Multiple non-try remote arguments should be found."
64
65
66 if __name__ == "__main__":
67 mozunit.main()