async def test_async_unknown_command_without_error_handler(self): for iface in ('sync', 'async'): self.cmdmgr.active_interface = iface with self.assertRaises(CmdNotFoundError) as cm: await self.cmdmgr.run_async('foo bar baz') self.assertEqual(self.cb_success.calls, 0) self.assertEqual(self.cb_error.calls, 0) assertIsException(cm.exception, CmdError, 'foo')
def test_argparser_error(self): process = self.div_sync(['10', '2', '--frobnicate'], loop=None, on_success=self.cb_success, on_error=self.cb_error) self.assertEqual(process.finished, True) self.assertEqual(process.success, False) assertIsException(process.exception, CmdArgError, '--frobnicate') self.assertEqual(self.cb_success.calls, 0) self.assertEqual(self.cb_error.calls, 1) assert self.cb_error.args[0][0] is process.exception, \ '{!r} is not {!r}'.format(self.cb_error.args[0][0], process.exception)
async def test_async_unknown_command_with_error_handler(self): for iface in ('sync', 'async'): self.cmdmgr.active_interface = iface success = await self.cmdmgr.run_async('foo', on_success=self.cb_success, on_error=self.cb_error) self.assertEqual(success, False) self.assertEqual(self.cb_success.calls, 0) self.assertEqual(self.cb_error.calls, 1) exc = self.cb_error.args[0][0] assertIsException(exc, CmdError, 'foo') self.cb_success.reset() self.cb_error.reset()
async def test_async_command_raises_CmdError(self): for iface in ('sync', 'async'): self.cmdmgr.active_interface = iface # Without error handler with self.assertRaises(CmdError) as cm: await self.cmdmgr.run_async('error "Oops"') self.assertEqual(self.cb_success.calls, 0) self.assertEqual(self.cb_error.calls, 0) self.assertIn('Oops', str(cm.exception)) # With error handler success = await self.cmdmgr.run_async('error "No!"', on_success=self.cb_success, on_error=self.cb_error) self.assertEqual(success, False) self.assertEqual(self.cb_success.calls, 0) self.assertEqual(self.cb_error.calls, 1) exc = self.cb_error.args[0][0] assertIsException(exc, CmdError, 'No!') self.cb_success.reset() self.cb_error.reset()