Esempio n. 1
0
    def testEventHash(self):
        a = _Event(0.5, None)
        b = _Event(1, None)
        b2 = _Event(1, None)
        b2._run_at = b._run_at
        b3 = _Event(1, 2)
        b3._run_at = b._run_at
        c = _Event(1, 4)
        c._run_at = b._run_at

        self.assertEqual(hash(a), hash(a))
        self.assertNotEqual(hash(a), hash(b))
        self.assertEqual(hash(b), hash(b2))
        self.assertNotEqual(hash(b), hash(b3))
        self.assertNotEqual(hash(b), hash(c))
Esempio n. 2
0
    def testEventCmp(self):
        a = _Event(0.5, a_func)
        # b/b2/b3/c have same timing to test comparisons of
        # callback (b==b2 and b!=b3)
        b = _Event(1, b_func)
        b2 = _Event(1, b_func)
        b2._run_at = b._run_at
        b3 = _Event(1, a_func)
        b3._run_at = b._run_at
        c = _Event(1, c_func)
        c._run_at = b._run_at

        self.assertEqual(b, b2)
        self.assertNotEqual(b, b3)
        self.assertTrue(a != b)
        self.assertFalse(b != b2)
        self.assertTrue(b == b2)
        self.assertTrue(a < b)
        self.assertTrue(a <= b)
        self.assertTrue(b > a)
        self.assertTrue(b >= a)

        self.assertFalse(a == b2)
        self.assertFalse(b < a)
        self.assertFalse(b <= a)
        self.assertFalse(a > b)
        self.assertFalse(a >= b)
        self.assertTrue(b3 < c)
        self.assertFalse(c < b3)

        s = sorted([c, a, b, b3])
        self.assertEqual(s, [a, b3, b, c])

        s = "teststring"
        self.assertNotEqual(a, s)
        self.assertEqual(a.__lt__(s), NotImplemented)
        self.assertEqual(a.__ne__(s), True)
        self.assertEqual(a.__eq__(s), False)