diff options
Diffstat (limited to 'tests')
| -rw-r--r-- | tests/test_project.py | 46 | ||||
| -rw-r--r-- | tests/test_subcmds_upload.py | 39 |
2 files changed, 82 insertions, 3 deletions
diff --git a/tests/test_project.py b/tests/test_project.py index f65e83f95..82a90a6dc 100644 --- a/tests/test_project.py +++ b/tests/test_project.py | |||
| @@ -137,6 +137,48 @@ class ReviewableBranchTests(unittest.TestCase): | |||
| 137 | 137 | ||
| 138 | self.assertTrue(rb.current) | 138 | self.assertTrue(rb.current) |
| 139 | 139 | ||
| 140 | def test_ignore_remote_commits(self) -> None: | ||
| 141 | """Check ignore_remote_commits excludes commits in refs/remotes/*.""" | ||
| 142 | with utils_for_test.TempGitTree() as tempdir: | ||
| 143 | fakeproj = FakeProject(tempdir) | ||
| 144 | |||
| 145 | with open(os.path.join(tempdir, "readme"), "w") as fp: | ||
| 146 | fp.write("init") | ||
| 147 | fakeproj.work_git.add("readme") | ||
| 148 | fakeproj.work_git.commit("-mInit") | ||
| 149 | |||
| 150 | # Create an upstream commit and record it under refs/remotes/. | ||
| 151 | fakeproj.work_git.checkout("-b", "upstream") | ||
| 152 | with open(os.path.join(tempdir, "upstream.txt"), "w") as fp: | ||
| 153 | fp.write("upstream") | ||
| 154 | fakeproj.work_git.add("upstream.txt") | ||
| 155 | fakeproj.work_git.commit("-mUpstream change") | ||
| 156 | fakeproj.work_git.update_ref( | ||
| 157 | "refs/remotes/upstream/main", "refs/heads/upstream" | ||
| 158 | ) | ||
| 159 | |||
| 160 | # Merge the remote branch into work on top of main. | ||
| 161 | fakeproj.work_git.checkout("-b", "work", "main") | ||
| 162 | fakeproj.work_git.merge( | ||
| 163 | "--no-ff", "-mMerge upstream", "refs/remotes/upstream/main" | ||
| 164 | ) | ||
| 165 | |||
| 166 | rb_default = project.ReviewableBranch( | ||
| 167 | fakeproj, fakeproj.config.GetBranch("work"), "main" | ||
| 168 | ) | ||
| 169 | self.assertEqual(2, len(rb_default.commits)) | ||
| 170 | self.assertEqual(2, len(rb_default.unabbrev_commits)) | ||
| 171 | |||
| 172 | rb_ignored = project.ReviewableBranch( | ||
| 173 | fakeproj, | ||
| 174 | fakeproj.config.GetBranch("work"), | ||
| 175 | "main", | ||
| 176 | ignore_remote_commits=True, | ||
| 177 | ) | ||
| 178 | self.assertEqual(1, len(rb_ignored.commits)) | ||
| 179 | self.assertIn("Merge upstream", rb_ignored.commits[0]) | ||
| 180 | self.assertEqual(1, len(rb_ignored.unabbrev_commits)) | ||
| 181 | |||
| 140 | 182 | ||
| 141 | class ProjectTests(unittest.TestCase): | 183 | class ProjectTests(unittest.TestCase): |
| 142 | """Check Project behavior.""" | 184 | """Check Project behavior.""" |
| @@ -1277,7 +1319,9 @@ class ProjectTests(unittest.TestCase): | |||
| 1277 | ) as mock_get_up: | 1319 | ) as mock_get_up: |
| 1278 | res = proj.GetUploadableBranches("feature") | 1320 | res = proj.GetUploadableBranches("feature") |
| 1279 | self.assertEqual(res, [mock_rb]) | 1321 | self.assertEqual(res, [mock_rb]) |
| 1280 | mock_get_up.assert_called_once_with("feature") | 1322 | mock_get_up.assert_called_once_with( |
| 1323 | "feature", ignore_remote_commits=False | ||
| 1324 | ) | ||
| 1281 | 1325 | ||
| 1282 | def _get_derived_subproject_url(self, submodule_url): | 1326 | def _get_derived_subproject_url(self, submodule_url): |
| 1283 | with tempfile.TemporaryDirectory(prefix="repo-tests") as tempdir: | 1327 | with tempfile.TemporaryDirectory(prefix="repo-tests") as tempdir: |
diff --git a/tests/test_subcmds_upload.py b/tests/test_subcmds_upload.py index 4c9008f55..53cc651a1 100644 --- a/tests/test_subcmds_upload.py +++ b/tests/test_subcmds_upload.py | |||
| @@ -116,11 +116,46 @@ def test_GatherOne_returns_resolved_current_branch( | |||
| 116 | "get_parallel_context", | 116 | "get_parallel_context", |
| 117 | lambda: {"projects": [project]}, | 117 | lambda: {"projects": [project]}, |
| 118 | ) | 118 | ) |
| 119 | opt = mock.MagicMock(current_branch=True) | 119 | opt = mock.MagicMock(current_branch=True, ignore_remote_commits=False) |
| 120 | 120 | ||
| 121 | assert upload.Upload._GatherOne(opt, 0) == (0, [branch], "topic") | 121 | assert upload.Upload._GatherOne(opt, 0) == (0, [branch], "topic") |
| 122 | 122 | ||
| 123 | project.GetUploadableBranch.assert_called_once_with("topic") | 123 | project.GetUploadableBranch.assert_called_once_with( |
| 124 | "topic", ignore_remote_commits=False | ||
| 125 | ) | ||
| 126 | |||
| 127 | |||
| 128 | def test_GatherOne_forwards_ignore_remote_commits( | ||
| 129 | cmd: upload.Upload, | ||
| 130 | monkeypatch: pytest.MonkeyPatch, | ||
| 131 | ) -> None: | ||
| 132 | """_GatherOne forwards --ignore-remote-commits to project methods.""" | ||
| 133 | project = mock.MagicMock() | ||
| 134 | project.CurrentBranch = "topic" | ||
| 135 | branch = mock.sentinel.branch | ||
| 136 | project.GetUploadableBranch.return_value = branch | ||
| 137 | project.GetUploadableBranches.return_value = [branch] | ||
| 138 | monkeypatch.setattr( | ||
| 139 | upload.Upload, | ||
| 140 | "get_parallel_context", | ||
| 141 | lambda: {"projects": [project]}, | ||
| 142 | ) | ||
| 143 | |||
| 144 | opt_cbr, _ = cmd.OptionParser.parse_args( | ||
| 145 | ["--cbr", "--ignore-remote-commits"] | ||
| 146 | ) | ||
| 147 | assert upload.Upload._GatherOne(opt_cbr, 0) == (0, [branch], "topic") | ||
| 148 | project.GetUploadableBranch.assert_called_once_with( | ||
| 149 | "topic", ignore_remote_commits=True | ||
| 150 | ) | ||
| 151 | |||
| 152 | opt_br, _ = cmd.OptionParser.parse_args( | ||
| 153 | ["--br", "topic", "--ignore-remote-commits"] | ||
| 154 | ) | ||
| 155 | assert upload.Upload._GatherOne(opt_br, 0) == (0, [branch], None) | ||
| 156 | project.GetUploadableBranches.assert_called_once_with( | ||
| 157 | "topic", ignore_remote_commits=True | ||
| 158 | ) | ||
| 124 | 159 | ||
| 125 | 160 | ||
| 126 | def _create_mock_branch( | 161 | def _create_mock_branch( |
