def test_new_task_unknown(self): """ Cannot create a new task from an unknown name. It must raise a KeyError exception (just like `TaskRegistry.get`). """ with self.assertRaises(UnknownTaskName): new_task('dummy')
def test_new_task_bad_inputs(self): """ Trying to create a new asyncio task with invalid inputs must raise a `TypeError` exception. """ # 1 (mandatory) positional argument (None) passed to the coroutine # whereas the coroutine takes no argument with self.assertRaisesRegex(TypeError, 'positional argument'): new_task('task-bad-coro')
def test_new_task_ok(self): """ Various cases which must lead to create asyncio tasks successfully. """ # Create a task from a task holder task = new_task('my-task-holder') self.assertIsInstance(task, asyncio.Task) # Create a task from a simple coroutine task = new_task('my-coro-task') self.assertIsInstance(task, asyncio.Task)
def test_new_task_bad_holder(self): """ Trying to create a new task from an invalid task holder may raise various exceptions. Ensure those exceptions are raised by `new_task`. """ # Cannot create a task with `__init__` has an invalid signature with self.assertRaisesRegex(TypeError, 'positional argument'): new_task('task-bad-inputs', config={'hello': 'world'}) # Cannot create a task when `__init__` raises an exception with self.assertRaises(MyDummyError): new_task('task-init-exc')