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

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

Issue 17435: threading.Timer.__init__() should use immutable argument defaults for args and kwargs
Patch Set: Created 6 years, 9 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 | « Doc/library/threading.rst ('k') | Lib/threading.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 # Very rudimentary test of threading module 1 # Very rudimentary test of threading module
2 2
3 import test.support 3 import test.support
4 from test.support import verbose, strip_python_stderr, import_module 4 from test.support import verbose, strip_python_stderr, import_module
5 from test.script_helper import assert_python_ok 5 from test.script_helper import assert_python_ok
6 6
7 import random 7 import random
8 import re 8 import re
9 import sys 9 import sys
10 _thread = import_module('_thread') 10 _thread = import_module('_thread')
(...skipping 768 matching lines...) Expand 10 before | Expand all | Expand 10 after
779 w.join() 779 w.join()
780 print('end of main thread') 780 print('end of main thread')
781 """ 781 """
782 expected_output = "end of main thread\n" 782 expected_output = "end of main thread\n"
783 p = subprocess.Popen([sys.executable, "-c", script], 783 p = subprocess.Popen([sys.executable, "-c", script],
784 stdout=subprocess.PIPE, stderr=subprocess.PIPE) 784 stdout=subprocess.PIPE, stderr=subprocess.PIPE)
785 stdout, stderr = p.communicate() 785 stdout, stderr = p.communicate()
786 data = stdout.decode().replace('\r', '') 786 data = stdout.decode().replace('\r', '')
787 self.assertEqual(p.returncode, 0, "Unexpected error: " + stderr.decode() ) 787 self.assertEqual(p.returncode, 0, "Unexpected error: " + stderr.decode() )
788 self.assertEqual(data, expected_output) 788 self.assertEqual(data, expected_output)
789
790 class TimerTests(BaseTestCase):
791
792 def setUp(self):
793 BaseTestCase.setUp(self)
794 self.callback_invocations = []
795 self.callback_event = threading.Event()
796
797 def test_init_immutable_default_args(self):
798 timer1 = threading.Timer(1, self._callback_spy)
799 timer1.args.append("blah")
800 timer1.kwargs["foo"] = "bar"
801 timer2 = threading.Timer(1, self._callback_spy)
802 timer2.start()
803 self.callback_event.wait()
804 self.assertEquals(len(self.callback_invocations), 1)
805 (invocation_args, invocation_kwargs) = self.callback_invocations[0]
806 self.assertEquals(invocation_args, ())
807 self.assertEquals(invocation_kwargs, {})
808
809 def _callback_spy(self, *args, **kwargs):
810 self.callback_invocations.append((args, kwargs))
811 self.callback_event.set()
789 812
790 class LockTests(lock_tests.LockTests): 813 class LockTests(lock_tests.LockTests):
791 locktype = staticmethod(threading.Lock) 814 locktype = staticmethod(threading.Lock)
792 815
793 class PyRLockTests(lock_tests.RLockTests): 816 class PyRLockTests(lock_tests.RLockTests):
794 locktype = staticmethod(threading._PyRLock) 817 locktype = staticmethod(threading._PyRLock)
795 818
796 @unittest.skipIf(threading._CRLock is None, 'RLock not implemented in C') 819 @unittest.skipIf(threading._CRLock is None, 'RLock not implemented in C')
797 class CRLockTests(lock_tests.RLockTests): 820 class CRLockTests(lock_tests.RLockTests):
798 locktype = staticmethod(threading._CRLock) 821 locktype = staticmethod(threading._CRLock)
(...skipping 23 matching lines...) Expand all
822 ConditionAsRLockTests, ConditionTests, 845 ConditionAsRLockTests, ConditionTests,
823 SemaphoreTests, BoundedSemaphoreTests, 846 SemaphoreTests, BoundedSemaphoreTests,
824 ThreadTests, 847 ThreadTests,
825 ThreadJoinOnShutdown, 848 ThreadJoinOnShutdown,
826 ThreadingExceptionTests, 849 ThreadingExceptionTests,
827 BarrierTests, 850 BarrierTests,
828 ) 851 )
829 852
830 if __name__ == "__main__": 853 if __name__ == "__main__":
831 test_main() 854 test_main()
OLDNEW
« no previous file with comments | « Doc/library/threading.rst ('k') | Lib/threading.py » ('j') | no next file with comments »

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