diff options
Diffstat (limited to 'tests')
-rw-r--r-- | tests/test_subcmds_sync.py | 55 |
1 files changed, 48 insertions, 7 deletions
diff --git a/tests/test_subcmds_sync.py b/tests/test_subcmds_sync.py index aad713f2..13f3f873 100644 --- a/tests/test_subcmds_sync.py +++ b/tests/test_subcmds_sync.py | |||
@@ -11,9 +11,9 @@ | |||
11 | # WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. | 11 | # WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. |
12 | # See the License for the specific language governing permissions and | 12 | # See the License for the specific language governing permissions and |
13 | # limitations under the License. | 13 | # limitations under the License. |
14 | |||
15 | """Unittests for the subcmds/sync.py module.""" | 14 | """Unittests for the subcmds/sync.py module.""" |
16 | 15 | ||
16 | import unittest | ||
17 | from unittest import mock | 17 | from unittest import mock |
18 | 18 | ||
19 | import pytest | 19 | import pytest |
@@ -21,17 +21,14 @@ import pytest | |||
21 | from subcmds import sync | 21 | from subcmds import sync |
22 | 22 | ||
23 | 23 | ||
24 | @pytest.mark.parametrize( | 24 | @pytest.mark.parametrize('use_superproject, cli_args, result', [ |
25 | 'use_superproject, cli_args, result', | ||
26 | [ | ||
27 | (True, ['--current-branch'], True), | 25 | (True, ['--current-branch'], True), |
28 | (True, ['--no-current-branch'], True), | 26 | (True, ['--no-current-branch'], True), |
29 | (True, [], True), | 27 | (True, [], True), |
30 | (False, ['--current-branch'], True), | 28 | (False, ['--current-branch'], True), |
31 | (False, ['--no-current-branch'], False), | 29 | (False, ['--no-current-branch'], False), |
32 | (False, [], None), | 30 | (False, [], None), |
33 | ] | 31 | ]) |
34 | ) | ||
35 | def test_get_current_branch_only(use_superproject, cli_args, result): | 32 | def test_get_current_branch_only(use_superproject, cli_args, result): |
36 | """Test Sync._GetCurrentBranchOnly logic. | 33 | """Test Sync._GetCurrentBranchOnly logic. |
37 | 34 | ||
@@ -41,5 +38,49 @@ def test_get_current_branch_only(use_superproject, cli_args, result): | |||
41 | cmd = sync.Sync() | 38 | cmd = sync.Sync() |
42 | opts, _ = cmd.OptionParser.parse_args(cli_args) | 39 | opts, _ = cmd.OptionParser.parse_args(cli_args) |
43 | 40 | ||
44 | with mock.patch('git_superproject.UseSuperproject', return_value=use_superproject): | 41 | with mock.patch('git_superproject.UseSuperproject', |
42 | return_value=use_superproject): | ||
45 | assert cmd._GetCurrentBranchOnly(opts, cmd.manifest) == result | 43 | assert cmd._GetCurrentBranchOnly(opts, cmd.manifest) == result |
44 | |||
45 | |||
46 | class GetPreciousObjectsState(unittest.TestCase): | ||
47 | """Tests for _GetPreciousObjectsState.""" | ||
48 | |||
49 | def setUp(self): | ||
50 | """Common setup.""" | ||
51 | self.cmd = sync.Sync() | ||
52 | self.project = p = mock.MagicMock(use_git_worktrees=False, | ||
53 | UseAlternates=False) | ||
54 | p.manifest.GetProjectsWithName.return_value = [p] | ||
55 | |||
56 | self.opt = mock.Mock(spec_set=['this_manifest_only']) | ||
57 | self.opt.this_manifest_only = False | ||
58 | |||
59 | def test_worktrees(self): | ||
60 | """False for worktrees.""" | ||
61 | self.project.use_git_worktrees = True | ||
62 | self.assertFalse(self.cmd._GetPreciousObjectsState(self.project, self.opt)) | ||
63 | |||
64 | def test_not_shared(self): | ||
65 | """Singleton project.""" | ||
66 | self.assertFalse(self.cmd._GetPreciousObjectsState(self.project, self.opt)) | ||
67 | |||
68 | def test_shared(self): | ||
69 | """Shared project.""" | ||
70 | self.project.manifest.GetProjectsWithName.return_value = [ | ||
71 | self.project, self.project | ||
72 | ] | ||
73 | self.assertTrue(self.cmd._GetPreciousObjectsState(self.project, self.opt)) | ||
74 | |||
75 | def test_shared_with_alternates(self): | ||
76 | """Shared project, with alternates.""" | ||
77 | self.project.manifest.GetProjectsWithName.return_value = [ | ||
78 | self.project, self.project | ||
79 | ] | ||
80 | self.project.UseAlternates = True | ||
81 | self.assertFalse(self.cmd._GetPreciousObjectsState(self.project, self.opt)) | ||
82 | |||
83 | def test_not_found(self): | ||
84 | """Project not found in manifest.""" | ||
85 | self.project.manifest.GetProjectsWithName.return_value = [] | ||
86 | self.assertFalse(self.cmd._GetPreciousObjectsState(self.project, self.opt)) | ||