def test_connect_and_fire(self): coro = CoroutineMock() coro.return_value = True signal = SyncAdHocSignal() signal.connect(coro) run_coroutine(signal.fire(1, 2, foo="bar")) self.assertSequenceEqual([ unittest.mock.call(1, 2, foo="bar"), ], coro.mock_calls)
def test_connect_and_fire(self): coro = CoroutineMock() coro.return_value = True signal = SyncAdHocSignal() signal.connect(coro) run_coroutine(signal.fire(1, 2, foo="bar")) self.assertSequenceEqual( [ unittest.mock.call(1, 2, foo="bar"), ], coro.mock_calls )
def test_fire_removes_on_false_result(self): coro = CoroutineMock() coro.return_value = False signal = SyncAdHocSignal() signal.connect(coro) run_coroutine(signal.fire(1, 2, foo="bar")) self.assertSequenceEqual([ unittest.mock.call(1, 2, foo="bar"), ], coro.mock_calls) coro.reset_mock() run_coroutine(signal.fire(1, 2, foo="bar")) self.assertSequenceEqual([], coro.mock_calls)
def test_ordered_calls(self): calls = [] def make_coro(i): @asyncio.coroutine def coro(): nonlocal calls calls.append(i) return coro coros = [make_coro(i) for i in range(3)] signal = SyncAdHocSignal() for coro in reversed(coros): signal.connect(coro) run_coroutine(signal.fire()) self.assertSequenceEqual([2, 1, 0], calls)
def test_ordered_calls(self): calls = [] def make_coro(i): @asyncio.coroutine def coro(): nonlocal calls calls.append(i) return coro coros = [make_coro(i) for i in range(3)] signal = SyncAdHocSignal() for coro in reversed(coros): signal.connect(coro) run_coroutine(signal.fire()) self.assertSequenceEqual( [2, 1, 0], calls )
def test_fire_removes_on_false_result(self): coro = CoroutineMock() coro.return_value = False signal = SyncAdHocSignal() signal.connect(coro) run_coroutine(signal.fire(1, 2, foo="bar")) self.assertSequenceEqual( [ unittest.mock.call(1, 2, foo="bar"), ], coro.mock_calls ) coro.reset_mock() run_coroutine(signal.fire(1, 2, foo="bar")) self.assertSequenceEqual( [ ], coro.mock_calls )