Beispiel #1
0
    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
Beispiel #2
0
    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
Beispiel #3
0
    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