Skip to content

Commit fa9b647

Browse files
committed
Use assert* comparison methods in test_timer_comparison
1 parent e3eba8c commit fa9b647

File tree

1 file changed

+41
-35
lines changed

1 file changed

+41
-35
lines changed

Lib/test/test_asyncio/test_events.py

+41-35
Original file line numberDiff line numberDiff line change
@@ -2653,33 +2653,38 @@ def callback(*args):
26532653

26542654
h1 = asyncio.TimerHandle(when, callback, (), self.loop)
26552655
h2 = asyncio.TimerHandle(when, callback, (), self.loop)
2656-
# TODO: Use assertLess etc.
2657-
self.assertFalse(h1 < h2)
2658-
self.assertFalse(h2 < h1)
2659-
self.assertTrue(h1 <= h2)
2660-
self.assertTrue(h2 <= h1)
2661-
self.assertFalse(h1 > h2)
2662-
self.assertFalse(h2 > h1)
2663-
self.assertTrue(h1 >= h2)
2664-
self.assertTrue(h2 >= h1)
2665-
self.assertTrue(h1 == h2)
2666-
self.assertFalse(h1 != h2)
2656+
with self.assertRaises(AssertionError):
2657+
self.assertLess(h1, h2)
2658+
self.assertLess(h2, h1)
2659+
self.assertGreater(h1, h2)
2660+
self.assertGreater(h2, h1)
2661+
self.assertNotEqual(h1, h2)
2662+
2663+
self.assertLessEqual(h1, h2)
2664+
self.assertLessEqual(h2, h1)
2665+
self.assertGreaterEqual(h1, h2)
2666+
self.assertGreaterEqual(h2, h1)
2667+
self.assertEqual(h1, h2)
26672668

26682669
h2.cancel()
2669-
self.assertFalse(h1 == h2)
2670+
with self.assertRaises(AssertionError):
2671+
self.assertEqual(h1, h2)
2672+
self.assertNotEqual(h1, h2)
26702673

26712674
h1 = asyncio.TimerHandle(when, callback, (), self.loop)
26722675
h2 = asyncio.TimerHandle(when + 10.0, callback, (), self.loop)
2673-
self.assertTrue(h1 < h2)
2674-
self.assertFalse(h2 < h1)
2675-
self.assertTrue(h1 <= h2)
2676-
self.assertFalse(h2 <= h1)
2677-
self.assertFalse(h1 > h2)
2678-
self.assertTrue(h2 > h1)
2679-
self.assertFalse(h1 >= h2)
2680-
self.assertTrue(h2 >= h1)
2681-
self.assertFalse(h1 == h2)
2682-
self.assertTrue(h1 != h2)
2676+
with self.assertRaises(AssertionError):
2677+
self.assertLess(h2, h1)
2678+
self.assertLessEqual(h2, h1)
2679+
self.assertGreater(h1, h2)
2680+
self.assertGreaterEqual(h1, h2)
2681+
self.assertEqual(h1, h2)
2682+
2683+
self.assertLess(h1, h2)
2684+
self.assertGreater(h2, h1)
2685+
self.assertLessEqual(h1, h2)
2686+
self.assertGreaterEqual(h2, h1)
2687+
self.assertNotEqual(h1, h2)
26832688

26842689
h3 = asyncio.Handle(callback, (), self.loop)
26852690
self.assertIs(NotImplemented, h1.__eq__(h3))
@@ -2693,19 +2698,20 @@ def callback(*args):
26932698
h1 <= ()
26942699
with self.assertRaises(TypeError):
26952700
h1 >= ()
2696-
self.assertFalse(h1 == ())
2697-
self.assertTrue(h1 != ())
2698-
2699-
self.assertTrue(h1 == ALWAYS_EQ)
2700-
self.assertFalse(h1 != ALWAYS_EQ)
2701-
self.assertTrue(h1 < LARGEST)
2702-
self.assertFalse(h1 > LARGEST)
2703-
self.assertTrue(h1 <= LARGEST)
2704-
self.assertFalse(h1 >= LARGEST)
2705-
self.assertFalse(h1 < SMALLEST)
2706-
self.assertTrue(h1 > SMALLEST)
2707-
self.assertFalse(h1 <= SMALLEST)
2708-
self.assertTrue(h1 >= SMALLEST)
2701+
with self.assertRaises(AssertionError):
2702+
self.assertEqual(h1, ())
2703+
self.assertNotEqual(h1, ALWAYS_EQ)
2704+
self.assertGreater(h1, LARGEST)
2705+
self.assertGreaterEqual(h1, LARGEST)
2706+
self.assertLess(h1, SMALLEST)
2707+
self.assertLessEqual(h1, SMALLEST)
2708+
2709+
self.assertNotEqual(h1, ())
2710+
self.assertEqual(h1, ALWAYS_EQ)
2711+
self.assertLess(h1, LARGEST)
2712+
self.assertLessEqual(h1, LARGEST)
2713+
self.assertGreaterEqual(h1, SMALLEST)
2714+
self.assertGreater(h1, SMALLEST)
27092715

27102716

27112717
class AbstractEventLoopTests(unittest.TestCase):

0 commit comments

Comments
 (0)