def test_swim_client_test_schedule_task_that_is_cancelled(self): # Given mock_task = MockScheduleTask.get_mock_schedule_task() with SwimClient() as swim_client: # When actual = swim_client._schedule_task(mock_task.async_infinite_cancel_execute) # Then self.assertIsInstance(actual, futures.Future) self.assertTrue(actual.cancelled())
async def test_swim_client_test_schedule_task(self): # Given mock_task = MockScheduleTask.get_mock_schedule_task() with SwimClient() as swim_client: # When actual = swim_client.schedule_task(mock_task.async_execute, 'foo') while not actual.done(): pass # Then self.assertEqual(1, mock_task.call_count) self.assertEqual('foo', mock_task.message) self.assertIsInstance(actual, futures.Future)
def test_swim_client_test_schedule_task_that_raises_exception(self, mock_warn_tb, mock_warn): # Given mock_task = MockScheduleTask.get_mock_schedule_task() with SwimClient(debug=True) as swim_client: # When actual = swim_client._schedule_task(mock_task.async_exception_execute, 'foo') while not actual.done(): pass # Then mock_warn_tb.assert_called_once() mock_warn.assert_called_once() self.assertEqual('Mock async execute exception', mock_warn.call_args_list[0][0][0]) self.assertEqual(1, mock_task.call_count) self.assertEqual('foo', mock_task.message) self.assertIsInstance(actual, futures.Future)
def test_swim_client_test_schedule_task_exception_debug(self, mock_print_tb, mock_warn): # Given mock_task = MockScheduleTask.get_mock_schedule_task() original_run = asyncio.run_coroutine_threadsafe with patch('asyncio.run_coroutine_threadsafe', new_callable=MockRunWithExceptionOnce) as mock_run: mock_exception_once = MockExceptionOnce.get_mock_exception_once() mock_exception_once.actual_function = original_run mock_run.side_effect = mock_exception_once.side_effect # When with SwimClient(debug=True) as swim_client: actual = swim_client._schedule_task(mock_task.sync_execute, 'foo') self.assertEqual('Mock exception', mock_warn.call_args_list[0][0][0]) mock_print_tb.assert_called_once() self.assertIsNone(actual)
def setUp(self): MockWebsocket.clear() MockScheduleTask.clear() MockExceptionOnce.clear() asyncio.get_event_loop().stop() asyncio.get_event_loop().close()