Beispiel #1
0
 def testCancelMatchFail4(self):
     handle = util.cancellable()
     self.assertFalse(handle.match(CancelledError()))
     self.assertFalse(handle.match(CancelledError))
     self.assertFalse(handle.match(1))
     self.assertFalse(handle.match("fpp"))
     self.assertFalse(handle.match(None))
Beispiel #2
0
    def testCancelSelf(self):
        handle = util.cancellable()
        c = stackless.channel()

        def foo():
            with handle:
                handle.cancel()

        self.assertRaises(CancelledError, foo)
Beispiel #3
0
    def testCancelFail2(self):
        handle = util.cancellable()

        def foo():
            with handle:
                return

        foo()
        handle.cancel()
        self.assertFalse(handle.cancelled())
Beispiel #4
0
    def testCancelMatchFail3(self):
        handle1 = util.cancellable()
        handle2 = util.cancellable()
        c = stackless.channel()

        def foo():
            with handle1:
                with handle2:
                    c.receive()

        def cancellor(handle):
            handle.cancel("foo", "bar")

        t = stackless.tasklet(cancellor)(handle1)
        try:
            foo()
        except CancelledError as e:
            self.assertFalse(handle2.match(e))
            self.assertTrue(handle1.match(e))
Beispiel #5
0
    def testCancel(self):
        handle = util.cancellable()
        c = stackless.channel()

        def foo():
            with handle:
                c.receive()

        def cancellor(handle):
            handle.cancel("foo", "bar")

        t = stackless.tasklet(cancellor)(handle)
        self.assertRaises(CancelledError, foo)
Beispiel #6
0
    def testCancelArgs(self):
        handle = util.cancellable()
        c = stackless.channel()

        def foo():
            with handle:
                c.receive()

        def cancellor(handle):
            handle.cancel("foo", "bar")

        t = stackless.tasklet(cancellor)(handle)
        try:
            foo()
        except CancelledError as e:
            self.assertEqual(e.args, ("foo", "bar"))
Beispiel #7
0
 def testSelf(self):
     handle = util.cancellable()
     with handle as h:
         self.assertTrue(handle is h)
Beispiel #8
0
 def testCancelFail(self):
     handle = util.cancellable()
     handle.cancel()
     self.assertFalse(handle.cancelled())