コード例 #1
0
 def test_run_args(self):
     func = FunctionSimulator(self, name="Acton")
     args = (1, 2)
     kwargs = {"a": 1, "b": 2, "c": 3}
     x = Cleanup(None, 0, func, args, kwargs)
     x.run()
     func.assertInvocation(*args, **kwargs)
     x.run()
     func.assertInvocationCount(2)
     func.invocations[1].assertArgs(*args, **kwargs)
コード例 #2
0
    def test_run_normal(self):
        func = FunctionSimulator(self, retval=450, name="York")
        args = ()
        kwargs = {}
        x = Cleanup(None, 0, func, args, kwargs)
        actual_retval = x.run()
        func.assertInvocation()
        self.assertEqual(actual_retval, func.retval)

        actual_retval = x.run()
        func.assertInvocationCount(2)
        self.assertEqual(actual_retval, func.retval)
コード例 #3
0
    def test_run_exception(self):
        exception = KeyError("message")
        func = FunctionSimulator(self, exception=exception, name="Etobicoke")
        args = ()
        kwargs = {}
        x = Cleanup(None, 0, func, args, kwargs)
        with self.assertRaises(type(func.exception)) as cm:
            x.run()
        self.assertIs(cm.exception, func.exception)

        with self.assertRaises(type(func.exception)) as cm:
            x.run()
        func.assertInvocationCount(2)
        self.assertIs(cm.exception, func.exception)