Beispiel #1
0
 def test_run_one(self):
     func = self.func("Toronto")
     x = Cleanups()
     cleanup = x.add(func)
     self.assertIsInstance(cleanup, Cleanup)
     x.run()
     func.assertInvocation()
Beispiel #2
0
 def test_args(self):
     func1 = self.func("Preston")
     func2 = self.func("Galt")
     func3 = self.func("Hespler")
     x = Cleanups()
     x.add(func1, 1, 2, "3")
     x.add(func2, key1="value1", key2=2)
     x.add(func3, 9, 8, "7", key6="six", key5=5)
     x.run()
     func1.assertInvocation(1, 2, "3")
     func2.assertInvocation(key1="value1", key2=2)
     func3.assertInvocation(9, 8, "7", key6="six", key5=5)
Beispiel #3
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")
Beispiel #4
0
 def test_remove_multiple(self):
     func1 = self.func("Guelph")
     func2 = self.func("Hamilton")
     func3 = self.func("Brantford")
     x = Cleanups()
     c1 = x.add(func1)
     c2 = x.add(func2)
     x.add(func3)
     x.remove(c1)
     x.remove(c2)
     x.run()
     func1.assertNotInvoked()
     func2.assertNotInvoked()
     func3.assertInvoked()
Beispiel #5
0
 def test_remove_one(self):
     func = self.func("Cambridge")
     x = Cleanups()
     c1 = x.add(func)
     x.remove(c1)
     x.run()
     func.assertNotInvoked()
Beispiel #6
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')")
Beispiel #7
0
 def test_context_manager(self):
     func1 = self.func("London")
     func2 = self.func("Mississauga")
     with Cleanups() as x:
         x.add(func1)
         func1.assertNotInvoked()
         x.add(func2)
         func2.assertNotInvoked()
     func1.assertInvocation()
     func2.assertInvocation()
Beispiel #8
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)
Beispiel #9
0
 def test_listener(self):
     func = self.func("Brampton")
     x = Cleanups()
     cleanup = x.add(func)
     listener = CleanupListenerHelper(self)
     x.add_listener(listener)
     x.run()
     func.assertInvoked()
     listener.starting.assertInvocation(listener, x, cleanup)
     listener.completed.assertInvocation(listener, x, cleanup, None)
     listener.failed.assertNotInvoked()
     listener.starting.assertInvokedBefore(func)
     func.assertInvokedBefore(listener.completed)
Beispiel #10
0
 def test_run_multiple(self):
     func1 = self.func("Kitchener")
     func2 = self.func("Waterloo")
     x = Cleanups()
     x.add(func1)
     x.add(func2)
     x.run()
     func1.assertInvocation()
     func2.assertInvocation()
     func2.assertInvokedBefore(func1)
Beispiel #11
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)
Beispiel #12
0
    def test_global_listener(self):
        func1 = self.func("Burlington")
        func2 = self.func("Stouffville")
        x1 = Cleanups()
        x2 = Cleanups()
        cleanup1 = x1.add(func1)
        cleanup2 = x1.add(func2)
        listener = CleanupListenerHelper(self)
        Cleanups.add_global_listener(listener)
        x1.run()
        x2.run()
        func1.assertInvoked()
        func2.assertInvoked()
        listener.starting.assertInvocationCount(2)
        listener.completed.assertInvocationCount(2)
        listener.failed.assertNotInvoked()

        listener.starting.invocations[0].assertInvokedBefore(func2.invocation)
        func2.invocation.assertInvokedBefore(listener.completed.invocations[0])
        listener.completed.invocations[0].assertInvokedBefore(
            listener.starting.invocations[1])
        listener.starting.invocations[1].assertInvokedBefore(func1.invocation)
        func1.invocation.assertInvokedBefore(listener.completed.invocations[1])