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

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

Issue 16510: Using appropriate checks in tests
Patch Set: Created 6 years, 4 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 630 matching lines...) Expand 10 before | Expand all | Expand 10 after
641 641
642 def test_exception_with_timeout(self): 642 def test_exception_with_timeout(self):
643 self.assertRaises(futures.TimeoutError, 643 self.assertRaises(futures.TimeoutError,
644 PENDING_FUTURE.exception, timeout=0) 644 PENDING_FUTURE.exception, timeout=0)
645 self.assertRaises(futures.TimeoutError, 645 self.assertRaises(futures.TimeoutError,
646 RUNNING_FUTURE.exception, timeout=0) 646 RUNNING_FUTURE.exception, timeout=0)
647 self.assertRaises(futures.CancelledError, 647 self.assertRaises(futures.CancelledError,
648 CANCELLED_FUTURE.exception, timeout=0) 648 CANCELLED_FUTURE.exception, timeout=0)
649 self.assertRaises(futures.CancelledError, 649 self.assertRaises(futures.CancelledError,
650 CANCELLED_AND_NOTIFIED_FUTURE.exception, timeout=0) 650 CANCELLED_AND_NOTIFIED_FUTURE.exception, timeout=0)
651 self.assertTrue(isinstance(EXCEPTION_FUTURE.exception(timeout=0), 651 self.assertIsInstance(EXCEPTION_FUTURE.exception(timeout=0), OSError)
652 OSError))
653 self.assertEqual(SUCCESSFUL_FUTURE.exception(timeout=0), None) 652 self.assertEqual(SUCCESSFUL_FUTURE.exception(timeout=0), None)
654 653
655 def test_exception_with_success(self): 654 def test_exception_with_success(self):
656 def notification(): 655 def notification():
657 # Wait until the main thread is waiting for the exception. 656 # Wait until the main thread is waiting for the exception.
658 time.sleep(1) 657 time.sleep(1)
659 with f1._condition: 658 with f1._condition:
660 f1._state = FINISHED 659 f1._state = FINISHED
661 f1._exception = OSError() 660 f1._exception = OSError()
662 f1._condition.notify_all() 661 f1._condition.notify_all()
663 662
664 f1 = create_future(state=PENDING) 663 f1 = create_future(state=PENDING)
665 t = threading.Thread(target=notification) 664 t = threading.Thread(target=notification)
666 t.start() 665 t.start()
667 666
668 self.assertTrue(isinstance(f1.exception(timeout=5), OSError)) 667 self.assertIsInstance(f1.exception(timeout=5), OSError)
669 668
670 @test.support.reap_threads 669 @test.support.reap_threads
671 def test_main(): 670 def test_main():
672 try: 671 try:
673 test.support.run_unittest(ProcessPoolExecutorTest, 672 test.support.run_unittest(ProcessPoolExecutorTest,
674 ThreadPoolExecutorTest, 673 ThreadPoolExecutorTest,
675 ProcessPoolWaitTests, 674 ProcessPoolWaitTests,
676 ThreadPoolWaitTests, 675 ThreadPoolWaitTests,
677 ProcessPoolAsCompletedTests, 676 ProcessPoolAsCompletedTests,
678 ThreadPoolAsCompletedTests, 677 ThreadPoolAsCompletedTests,
679 FutureTests, 678 FutureTests,
680 ProcessPoolShutdownTest, 679 ProcessPoolShutdownTest,
681 ThreadPoolShutdownTest, 680 ThreadPoolShutdownTest,
682 ) 681 )
683 finally: 682 finally:
684 test.support.reap_children() 683 test.support.reap_children()
685 684
686 if __name__ == "__main__": 685 if __name__ == "__main__":
687 test_main() 686 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+