diff options
Diffstat (limited to 'tests/test_subcmds_sync.py')
| -rw-r--r-- | tests/test_subcmds_sync.py | 55 |
1 files changed, 7 insertions, 48 deletions
diff --git a/tests/test_subcmds_sync.py b/tests/test_subcmds_sync.py index 13f3f873..aad713f2 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 | |||
| 14 | """Unittests for the subcmds/sync.py module.""" | 15 | """Unittests for the subcmds/sync.py module.""" |
| 15 | 16 | ||
| 16 | import unittest | ||
| 17 | from unittest import mock | 17 | from unittest import mock |
| 18 | 18 | ||
| 19 | import pytest | 19 | import pytest |
| @@ -21,14 +21,17 @@ import pytest | |||
| 21 | from subcmds import sync | 21 | from subcmds import sync |
| 22 | 22 | ||
| 23 | 23 | ||
| 24 | @pytest.mark.parametrize('use_superproject, cli_args, result', [ | 24 | @pytest.mark.parametrize( |
| 25 | 'use_superproject, cli_args, result', | ||
| 26 | [ | ||
| 25 | (True, ['--current-branch'], True), | 27 | (True, ['--current-branch'], True), |
| 26 | (True, ['--no-current-branch'], True), | 28 | (True, ['--no-current-branch'], True), |
| 27 | (True, [], True), | 29 | (True, [], True), |
| 28 | (False, ['--current-branch'], True), | 30 | (False, ['--current-branch'], True), |
| 29 | (False, ['--no-current-branch'], False), | 31 | (False, ['--no-current-branch'], False), |
| 30 | (False, [], None), | 32 | (False, [], None), |
| 31 | ]) | 33 | ] |
| 34 | ) | ||
| 32 | def test_get_current_branch_only(use_superproject, cli_args, result): | 35 | def test_get_current_branch_only(use_superproject, cli_args, result): |
| 33 | """Test Sync._GetCurrentBranchOnly logic. | 36 | """Test Sync._GetCurrentBranchOnly logic. |
| 34 | 37 | ||
| @@ -38,49 +41,5 @@ def test_get_current_branch_only(use_superproject, cli_args, result): | |||
| 38 | cmd = sync.Sync() | 41 | cmd = sync.Sync() |
| 39 | opts, _ = cmd.OptionParser.parse_args(cli_args) | 42 | opts, _ = cmd.OptionParser.parse_args(cli_args) |
| 40 | 43 | ||
| 41 | with mock.patch('git_superproject.UseSuperproject', | 44 | with mock.patch('git_superproject.UseSuperproject', return_value=use_superproject): |
| 42 | return_value=use_superproject): | ||
| 43 | assert cmd._GetCurrentBranchOnly(opts, cmd.manifest) == result | 45 | 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)) | ||
