Example #1
0
    def test_when_enqueue_change_call_enquenue_the_change_by_covnert_it_and_adding_it(
        self, ):
        change = mut.Change(mut.ChangeType.ADD_FILE, "path/file")
        mut.rotate_changes()
        with unittest.mock.patch.object(mut, 'extend_quiet_delay' , return_value = unittest.mock.sentinel.QUIET) as ag, \
            unittest.mock.patch.object(mut.changes, 'add' , return_value = unittest.mock.sentinel.QUIET) as icsa,\
            unittest.mock.patch.object(mut, 'event2change' , return_value = change) as ice2c:
            mut.enqueue_change(1, 2, 3, 4)

        ice2c.assert_called_once_with(1, 2, 3, 4)
        icsa.assert_called_once_with(change)
Example #2
0
    async def test_rotate_changes_replaces_the_quiet_future_and_the_changes_object(
        self, ):
        ## actuall pretty syncronous l but we need the event loop
        with \
            unittest.mock.patch('gitdrop.inotify.quiet', new = unittest.mock.sentinel.QUIET ),\
            unittest.mock.patch('gitdrop.inotify.changes', new = unittest.mock.sentinel.CHANGES ):

            #mut.quiet = unittest.mock.sentinel.QUIET
            #mut.changes = unittest.mock.sentinel.CHANGES
            rv = mut.rotate_changes()
            self.assertEqual(rv, unittest.mock.sentinel.CHANGES)
            self.assertNotEqual(mut.changes, unittest.mock.sentinel.CHANGES)
            self.assertNotEqual(mut.quiet, unittest.mock.sentinel.QUIET)
Example #3
0
    def test_inotify_mainloop_processes_changeset_when_the_future_resolves(
        self, ):
        ## Test need to run in async context so here a function for it.all
        gb = unittest.mock.MagicMock()

        class MockDaemon:
            def __init__(self, ):
                class Watch:
                    def event_gen(self, ):
                        yield (1, "", "", "")

                self.iwatch = Watch()
                self.gitbackend = gb
                self._count = 0

            @property
            def is_running(self, ):
                self._count += 1
                return not (self._count - 1)

        async def test():
            loop = asyncio.get_event_loop()
            done = loop.create_task(mut.action_loop(MockDaemon()))
            mut.quiet.set_result(None)
            await done
            # Await quiet to silence warnings
            #await mut.quiet

        mychanges = unittest.mock.MagicMock()
        mut.rotate_changes()
        with unittest.mock.patch('gitdrop.inotify.rotate_changes',
                                 return_value=mychanges) as ica:
            #test_co = next(asyncio.as_completed( [ test() ] ,timeout=10 ))
            self.loop.run_until_complete(test())
            pass
        ica.assert_called_once()
        mychanges.apply.assert_called_once()
Example #4
0
 async def actual_test():
     mut.rotate_changes()  # Initialise
     for _ in range(TEST_LOOPS):
         mut.extend_quiet_delay()
     mut.changes.anyadded.set_result(None)
     await mut.quiet
Example #5
0
 def test_after_rotate_changes_there_is_future_which_to_indicate_when_a_queit_period_is_elapsed(
     self, ):
     mut.rotate_changes()
     self.assertIsInstance(mut.quiet, asyncio.Future)