def test_on_idle_with_commits_and_merges(self): mocked_sync = MagicMock() mocked_syncing = MagicMock() mocked_commit = MagicMock() mocked_syncing.is_set.return_value = False with patch.multiple("gitfs.worker.sync", syncing=mocked_syncing, writers=MagicMock(value=0)): worker = SyncWorker("name", "email", "name", "email", strategy="strategy") worker.commits = "commits" worker.commit = mocked_commit worker.sync = mocked_sync commits = worker.on_idle() mocked_commit.assert_called_once_with("commits") assert mocked_syncing.set.call_count == 1 assert mocked_sync.call_count == 1 assert commits is None
def test_switch_to_idle_mode(self): mocked_queue = MagicMock() mocked_idle = MagicMock(side_effect=ValueError) mocked_idle_event = MagicMock() mocked_queue.get.side_effect = Empty() with patch.multiple("gitfs.worker.sync", idle=mocked_idle_event): worker = SyncWorker( "name", "email", "name", "email", strategy="strategy", commit_queue=mocked_queue, ) worker.on_idle = mocked_idle worker.timeout = 1 worker.min_idle_times = -1 with pytest.raises(ValueError): worker.work() mocked_queue.get.assert_called_once_with(timeout=1, block=True) assert mocked_idle_event.set.call_count == 1 assert mocked_idle.call_count == 1
def test_run(self): mocked_queue = MagicMock() mocked_idle = MagicMock(side_effect=ValueError) mocked_queue.get.side_effect = Empty() worker = SyncWorker("name", "email", "name", "email", strategy="strategy", commit_queue=mocked_queue) worker.on_idle = mocked_idle worker.timeout = 1 with pytest.raises(ValueError): worker.run() mocked_queue.get.assert_called_once_with(timeout=1, block=True) assert mocked_idle.call_count == 1
def test_work(self): mocked_queue = MagicMock() mocked_idle = MagicMock(side_effect=ValueError) mocked_queue.get.side_effect = Empty() worker = SyncWorker("name", "email", "name", "email", strategy="strategy", commit_queue=mocked_queue) worker.on_idle = mocked_idle worker.timeout = 1 with pytest.raises(ValueError): worker.work() mocked_queue.get.assert_called_once_with(timeout=1, block=True) assert mocked_idle.call_count == 1
def test_switch_to_idle_mode(self): mocked_queue = MagicMock() mocked_idle = MagicMock(side_effect=ValueError) mocked_idle_event = MagicMock() mocked_queue.get.side_effect = Empty() with patch.multiple('gitfs.worker.sync', idle=mocked_idle_event): worker = SyncWorker("name", "email", "name", "email", strategy="strategy", commit_queue=mocked_queue) worker.on_idle = mocked_idle worker.timeout = 1 worker.min_idle_times = -1 with pytest.raises(ValueError): worker.work() mocked_queue.get.assert_called_once_with(timeout=1, block=True) assert mocked_idle_event.set.call_count == 1 assert mocked_idle.call_count == 1
def test_on_idle_with_commits_and_merges(self): mocked_sync = MagicMock() mocked_syncing = MagicMock() mocked_commit = MagicMock() mocked_syncing.is_set.return_value = False with patch.multiple("gitfs.worker.sync", syncing=mocked_syncing, writers=0): worker = SyncWorker("name", "email", "name", "email", strategy="strategy") worker.commits = "commits" worker.commit = mocked_commit worker.sync = mocked_sync commits = worker.on_idle() mocked_commit.assert_called_once_with("commits") assert mocked_syncing.set.call_count == 1 assert mocked_sync.call_count == 1 assert commits is None