Пример #1
0
    def test_bad_args(self):
        def f(a, b):
            pass

        with self.assertRaises(AssertionError):
            DelayedCall(self.EVLOOP, self.NOW, 1, ())

        with self.assertRaises(TypeError):
            DelayedCall(self.EVLOOP, self.NOW, f, (1, 2, 3))
Пример #2
0
 def call_later(self, delay, cb, *args):
     if not delay:
         return self.call_soon(cb, *args)
     now = self._timer()
     when = now + delay
     dc = DelayedCall(self, when, cb, args, check_args=self._check_args)
     heapq.heappush(self._later, dc)
     return dc
Пример #3
0
    def test_ctor(self):
        def f(a, b):
            pass

        dc = DelayedCall(self.EVLOOP, self.NOW, f, (1, 2))
        self.assertEqual(self.EVLOOP, dc.eventloop)
        self.assertEqual(self.NOW, dc.when)
        self.assertEqual(f, dc.callback)
        self.assertEqual((1, 2), dc.args)
        self.assertFalse(dc.cancelled)
Пример #4
0
 def test_cancel(self):
     dc = DelayedCall(self.EVLOOP, self.NOW, lambda:None, ())
     self.assertFalse(dc.cancelled)
     dc.cancel()
     self.assertTrue(dc.cancelled)
Пример #5
0
 def call_soon(self, cb, *args):
     dc = DelayedCall(self, 0, cb, args, check_args=self._check_args)
     self._soon.append(dc)
     return dc
Пример #6
0
    def test_ordering(self):
        def f():
            pass

        def g():
            pass

        now = self.NOW
        later = now + 1

        dc1 = DelayedCall(self.EVLOOP, now, f, ())
        dc2 = DelayedCall(self.EVLOOP, now, g, ())
        dc3 = DelayedCall(self.EVLOOP, later, f, ())
        dc4 = DelayedCall(self.EVLOOP, later, g, ())

        #compare objects
        self.assertEqual(dc1, dc1)
        self.assertNotEqual(dc1, dc2)
        self.assertNotEqual(dc1, dc3)
        self.assertNotEqual(dc1, dc4)

        self.assertLess(dc1, dc3)
        self.assertLess(dc1, dc4)
        self.assertLess(dc2, dc3)
        self.assertLess(dc2, dc4)

        self.assertLessEqual(dc1, dc1)
        self.assertLessEqual(dc1, dc3)
        self.assertLessEqual(dc1, dc4)

        self.assertGreater(dc3, dc1)
        self.assertGreater(dc3, dc2)
        self.assertGreater(dc4, dc1)
        self.assertGreater(dc4, dc2)

        self.assertGreaterEqual(dc3, dc1)
        self.assertGreaterEqual(dc3, dc2)
        self.assertGreaterEqual(dc3, dc3)
        self.assertGreaterEqual(dc3, dc4)

        # compare time
        self.assertEqual(now, dc1)
        self.assertEqual(now, dc2)
        self.assertNotEqual(now, dc3)
        self.assertNotEqual(now, dc4)

        self.assertLess(now, dc3)
        self.assertLess(now, dc4)

        self.assertLessEqual(now, dc1)
        self.assertLessEqual(now, dc2)
        self.assertLessEqual(now, dc3)
        self.assertLessEqual(now, dc4)
        self.assertLessEqual(later, dc3)
        self.assertLessEqual(later, dc4)

        self.assertGreater(later, dc1)
        self.assertGreater(later, dc2)

        self.assertGreaterEqual(later, dc1)
        self.assertGreaterEqual(later, dc2)
        self.assertGreaterEqual(later, dc3)
        self.assertGreaterEqual(later, dc4)
Пример #7
0
    def test_skip_args(self):
        def f(a, b):
            pass

        DelayedCall(self.EVLOOP, self.NOW, 1, (), check_args=False)
        DelayedCall(self.EVLOOP, self.NOW, f, (1, 2, 3), check_args=False)
Пример #8
0
 def test_cancel(self):
     dc = DelayedCall(self.EVLOOP, self.NOW, lambda: None, ())
     self.assertFalse(dc.cancelled)
     dc.cancel()
     self.assertTrue(dc.cancelled)
Пример #9
0
 def test___call__(self):
     callback = Mock()
     dc = DelayedCall(self.EVLOOP, self.NOW, callback, (1, 2, 3))
     dc()
     callback.assert_called_with(self.EVLOOP, 1, 2, 3)