Rietveld Code Review Tool
Help | Bug tracker | Discussion group | Source code | Sign in
(31735)

Side by Side Diff: Lib/test/test_concurrent_futures.py

Issue 16510: Using appropriate checks in tests
Patch Set: Created 5 years, 8 months ago
Left:
Right:
Use n/p to move between diff chunks; N/P to move between comments. Please Sign in to add in-line comments.
Jump to:
View unified diff | Download patch
« no previous file with comments | « Lib/test/test_complex.py ('k') | Lib/test/test_configparser.py » ('j') | no next file with comments »
Toggle Intra-line Diffs ('i') | Expand Comments ('e') | Collapse Comments ('c') | Show Comments Hide Comments ('s')
OLDNEW
1 import test.support 1 import test.support
2 2
3 # Skip tests if _multiprocessing wasn't built. 3 # Skip tests if _multiprocessing wasn't built.
4 test.support.import_module('_multiprocessing') 4 test.support.import_module('_multiprocessing')
5 # Skip tests if sem_open implementation is broken. 5 # Skip tests if sem_open implementation is broken.
6 test.support.import_module('multiprocessing.synchronize') 6 test.support.import_module('multiprocessing.synchronize')
7 # import threading after _multiprocessing to raise a more revelant error 7 # import threading after _multiprocessing to raise a more revelant error
8 # message: "No module named _multiprocessing". _multiprocessing is not compiled 8 # message: "No module named _multiprocessing". _multiprocessing is not compiled
9 # without thread support. 9 # without thread support.
10 test.support.import_module('threading') 10 test.support.import_module('threading')
(...skipping 637 matching lines...) Expand 10 before | Expand all | Expand 10 after
648 648
649 def test_exception_with_timeout(self): 649 def test_exception_with_timeout(self):
650 self.assertRaises(futures.TimeoutError, 650 self.assertRaises(futures.TimeoutError,
651 PENDING_FUTURE.exception, timeout=0) 651 PENDING_FUTURE.exception, timeout=0)
652 self.assertRaises(futures.TimeoutError, 652 self.assertRaises(futures.TimeoutError,
653 RUNNING_FUTURE.exception, timeout=0) 653 RUNNING_FUTURE.exception, timeout=0)
654 self.assertRaises(futures.CancelledError, 654 self.assertRaises(futures.CancelledError,
655 CANCELLED_FUTURE.exception, timeout=0) 655 CANCELLED_FUTURE.exception, timeout=0)
656 self.assertRaises(futures.CancelledError, 656 self.assertRaises(futures.CancelledError,
657 CANCELLED_AND_NOTIFIED_FUTURE.exception, timeout=0) 657 CANCELLED_AND_NOTIFIED_FUTURE.exception, timeout=0)
658 self.assertTrue(isinstance(EXCEPTION_FUTURE.exception(timeout=0), 658 self.assertIsInstance(EXCEPTION_FUTURE.exception(timeout=0), OSError)
659 OSError))
660 self.assertEqual(SUCCESSFUL_FUTURE.exception(timeout=0), None) 659 self.assertEqual(SUCCESSFUL_FUTURE.exception(timeout=0), None)
661 660
662 def test_exception_with_success(self): 661 def test_exception_with_success(self):
663 def notification(): 662 def notification():
664 # Wait until the main thread is waiting for the exception. 663 # Wait until the main thread is waiting for the exception.
665 time.sleep(1) 664 time.sleep(1)
666 with f1._condition: 665 with f1._condition:
667 f1._state = FINISHED 666 f1._state = FINISHED
668 f1._exception = OSError() 667 f1._exception = OSError()
669 f1._condition.notify_all() 668 f1._condition.notify_all()
670 669
671 f1 = create_future(state=PENDING) 670 f1 = create_future(state=PENDING)
672 t = threading.Thread(target=notification) 671 t = threading.Thread(target=notification)
673 t.start() 672 t.start()
674 673
675 self.assertTrue(isinstance(f1.exception(timeout=5), OSError)) 674 self.assertIsInstance(f1.exception(timeout=5), OSError)
676 675
677 @test.support.reap_threads 676 @test.support.reap_threads
678 def test_main(): 677 def test_main():
679 try: 678 try:
680 test.support.run_unittest(__name__) 679 test.support.run_unittest(__name__)
681 finally: 680 finally:
682 test.support.reap_children() 681 test.support.reap_children()
683 682
684 if __name__ == "__main__": 683 if __name__ == "__main__":
685 test_main() 684 test_main()
OLDNEW
« no previous file with comments | « Lib/test/test_complex.py ('k') | Lib/test/test_configparser.py » ('j') | no next file with comments »

RSS Feeds Recent Issues | This issue
This is Rietveld 894c83f36cb7+