示例#1
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)
示例#2
0
 def test_starting(self):
     x = DebugCleanupListener(f=self.tempfile())
     self.assertIsNone(x.starting(None, None))
     x.log = FunctionSimulator(self, name="log")
     cleanups = Cleanups()
     cleanup = Cleanup(cleanups, 123, None, [], {})
     x.starting(cleanups, cleanup)
     x.log.assertInvocation("Starting cleanup operation: 123")
示例#3
0
 def test_completed(self):
     x = DebugCleanupListener(f=self.tempfile())
     self.assertIsNone(x.completed(None, None, None))
     x.log = FunctionSimulator(self, name="log")
     cleanups = Cleanups()
     cleanup = Cleanup(cleanups, 234, None, [], {})
     x.completed(cleanups, cleanup, "abc")
     x.log.assertInvocation("Cleanup operation completed successfully: " +
                            "234 (returned 'abc')")
示例#4
0
 def test_failed(self):
     self.set_traceback_print_exception_to_simulator()
     x = DebugCleanupListener(f=self.tempfile())
     self.assertIsNone(x.failed(None, None, [1, 2, 3]))
     x.log = FunctionSimulator(self, name="log")
     cleanups = Cleanups()
     cleanup = Cleanup(cleanups, 345, None, [], {})
     exc_info = (6, 7, 8)
     traceback.print_exception.reset()
     x.failed(cleanups, cleanup, exc_info)
     x.log.assertInvocation("Cleanup operation FAILED: 345 (7)")
     traceback.print_exception.assertInvocation(*exc_info)
示例#5
0
    def test__init__(self):
        cleanups = Cleanups()
        id = 5
        retval = [1, 2, 3]
        func = FunctionSimulator(self, retval=retval, name="Vaughn")
        args = ["A", "b", "C"]
        kwargs = [("d", "D"), ("z", "A")]
        x = Cleanup(cleanups, id, func, args, kwargs)

        self.assertIs(x.cleanups, cleanups)
        self.assertEquals(x.id, id)
        self.assertIs(x.func, func)
        self.assertEquals(x.args, tuple(args))
        self.assertIsInstance(x.args, tuple)
        self.assertEquals(x.kwargs, dict(kwargs))
        self.assertIsInstance(x.kwargs, dict)
        self.assertIsNone(x.name)

        with self.assertRaises(TypeError):
            Cleanup(cleanups, id, func, 5, kwargs)
        with self.assertRaises(TypeError):
            Cleanup(cleanups, id, func, [], 5)
示例#6
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)
示例#7
0
 def test__str__(self):
     x = Cleanup(None, 20, None, (), {})
     self.assertEqual(str(x), "20")
     x.name = "Scarborough"
     self.assertEqual(str(x), "20: Scarborough")
     x.id = 5
     self.assertEqual(str(x), "5: Scarborough")
     x.id = None
     self.assertEqual(str(x), "None: Scarborough")
     x.name = None
     self.assertEqual(str(x), "None")
示例#8
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)