def test_call_with_deferrred(self): self.test_value = None self.setup_cli_reactor() self.setup_exit(0) com = Commander(self.deferred_callback) ns = self.get_sample_namespace() self.mocker.replay() com(ns) self.assertEqual(self.test_value, 42)
def test_verbose_successful(self): self.test_value = None self.setup_cli_reactor() self.setup_exit(0) com = Commander(self.deferred_callback) ns = self.get_sample_namespace() ns.verbose = True self.mocker.replay() com(ns) self.assertEqual(self.test_value, 42)
def test_call_with_deferrred_exception(self): self.test_value = None self.setup_cli_reactor() err = self.capture_stream("stderr") self.setup_exit(1) com = Commander(self.deferred_callback_with_exception) ns = self.get_sample_namespace() self.mocker.replay() com(ns) # verify that the exception message is all that comes out of stderr self.assertEqual(err.getvalue(), "Some generic error condition\n")
def test_verbose_error_with_traceback(self): self.test_value = None self.setup_cli_reactor() err = self.capture_stream("stderr") self.setup_exit(1) com = Commander(self.deferred_callback_with_exception) ns = self.get_sample_namespace() ns.verbose = True self.mocker.replay() com(ns) self.assertIn("traceback", err.getvalue())
def test_run_invalid_call(self): c = Commander(time.time) # called with invalid options self.failUnlessRaises(ValueError, c, None)
def test_invalid_callback(self): # non callable callback self.failUnlessRaises(ValueError, Commander, time.daylight) # valid callback Commander(time.time)