diff options
Diffstat (limited to 'tests')
| -rw-r--r-- | tests/test_subcmds_sync.py | 37 |
1 files changed, 19 insertions, 18 deletions
diff --git a/tests/test_subcmds_sync.py b/tests/test_subcmds_sync.py index a6be0807f..b3726d2d1 100644 --- a/tests/test_subcmds_sync.py +++ b/tests/test_subcmds_sync.py | |||
| @@ -552,35 +552,36 @@ class GCProjectsTest(unittest.TestCase): | |||
| 552 | def test_GCProjects_skip_gc(self, mock_progress): | 552 | def test_GCProjects_skip_gc(self, mock_progress): |
| 553 | """Test that it skips GC if opt.auto_gc is False.""" | 553 | """Test that it skips GC if opt.auto_gc is False.""" |
| 554 | self.opt.auto_gc = False | 554 | self.opt.auto_gc = False |
| 555 | self.cmd._SetPreciousObjectsState = mock.Mock() | 555 | with mock.patch.object( |
| 556 | self.cmd._GCProjects([self.project], self.opt, None) | 556 | sync.Sync, "_SetPreciousObjectsState" |
| 557 | self.cmd._SetPreciousObjectsState.assert_called_once_with( | 557 | ) as mock_set_state: |
| 558 | self.project, self.opt | 558 | self.cmd._GCProjects([self.project], self.opt, None) |
| 559 | ) | 559 | mock_set_state.assert_called_once_with(self.project, self.opt) |
| 560 | self.assertFalse(self.project.bare_git.gc.called) | 560 | self.assertFalse(self.project.bare_git.gc.called) |
| 561 | 561 | ||
| 562 | @mock.patch("subcmds.sync.Progress") | 562 | @mock.patch("subcmds.sync.Progress") |
| 563 | def test_GCProjects_sequential(self, mock_progress): | 563 | def test_GCProjects_sequential(self, mock_progress): |
| 564 | """Test sequential GC (jobs < 2).""" | 564 | """Test sequential GC (jobs < 2).""" |
| 565 | self.cmd._SetPreciousObjectsState = mock.Mock() | 565 | with mock.patch.object(sync.Sync, "_SetPreciousObjectsState"): |
| 566 | self.cmd._GCProjects([self.project], self.opt, None) | 566 | self.cmd._GCProjects([self.project], self.opt, None) |
| 567 | self.project.config.SetString.assert_called_once_with( | 567 | self.project.bare_git.gc.assert_called_once_with( |
| 568 | "gc.autoDetach", "false" | 568 | "--auto", config={"gc.autoDetach": "false"} |
| 569 | ) | 569 | ) |
| 570 | self.project.bare_git.gc.assert_called_once_with("--auto") | 570 | # Verify that gc.autoDetach was not permanently set in config. |
| 571 | for call in self.project.config.SetString.call_args_list: | ||
| 572 | self.assertNotEqual(call.args[0], "gc.autoDetach") | ||
| 571 | 573 | ||
| 572 | @mock.patch("subcmds.sync.Progress") | 574 | @mock.patch("subcmds.sync.Progress") |
| 573 | def test_GCProjects_parallel(self, mock_progress): | 575 | def test_GCProjects_parallel(self, mock_progress): |
| 574 | """Test parallel GC (jobs >= 2).""" | 576 | """Test parallel GC (jobs >= 2).""" |
| 575 | self.opt.jobs = 2 | 577 | self.opt.jobs = 2 |
| 576 | self.cmd._SetPreciousObjectsState = mock.Mock() | 578 | with mock.patch.object(sync.Sync, "_SetPreciousObjectsState"): |
| 577 | 579 | with mock.patch("subcmds.sync._threading.Thread") as mock_thread: | |
| 578 | with mock.patch("subcmds.sync._threading.Thread") as mock_thread: | 580 | mock_t = mock.MagicMock() |
| 579 | mock_t = mock.MagicMock() | 581 | mock_thread.return_value = mock_t |
| 580 | mock_thread.return_value = mock_t | 582 | err_event = mock.Mock() |
| 581 | err_event = mock.Mock() | 583 | err_event.is_set.return_value = False |
| 582 | err_event.is_set.return_value = False | 584 | self.cmd._GCProjects([self.project], self.opt, err_event) |
| 583 | self.cmd._GCProjects([self.project], self.opt, err_event) | ||
| 584 | 585 | ||
| 585 | self.assertTrue(mock_thread.called) | 586 | self.assertTrue(mock_thread.called) |
| 586 | 587 | ||
