Example #1
0
    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)
Example #2
0
    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)
Example #3
0
    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")
Example #4
0
    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())
Example #5
0
 def test_run_invalid_call(self):
     c = Commander(time.time)
     # called with invalid options
     self.failUnlessRaises(ValueError, c, None)
Example #6
0
 def test_invalid_callback(self):
     # non callable callback
     self.failUnlessRaises(ValueError, Commander, time.daylight)
     # valid callback
     Commander(time.time)