summaryrefslogtreecommitdiffstats
path: root/Lib/test/test_threading.py
diff options
context:
space:
mode:
authorR David Murray <rdmurray@bitdance.com>2013-03-30 21:22:30 (GMT)
committerR David Murray <rdmurray@bitdance.com>2013-03-30 21:22:30 (GMT)
commit5cbf3a0d6e6f35374a32a933dcca7ce3683595c6 (patch)
tree63d8d54a05d9668e1b5373bb9215af48d5787b64 /Lib/test/test_threading.py
parentce852cb8b9d5f879941fe709118f0e966e65196f (diff)
parent19aeb439c6ca0da540ad95eec599d3654babe20b (diff)
downloadcpython-5cbf3a0d6e6f35374a32a933dcca7ce3683595c6.zip
cpython-5cbf3a0d6e6f35374a32a933dcca7ce3683595c6.tar.gz
cpython-5cbf3a0d6e6f35374a32a933dcca7ce3683595c6.tar.bz2
Merge #17435: Don't use mutable default values in Timer.
Patch by Denver Coneybeare with some test modifications by me.
Diffstat (limited to 'Lib/test/test_threading.py')
-rw-r--r--Lib/test/test_threading.py39
1 files changed, 27 insertions, 12 deletions
diff --git a/Lib/test/test_threading.py b/Lib/test/test_threading.py
index fff00f4..9ed6ca7 100644
--- a/Lib/test/test_threading.py
+++ b/Lib/test/test_threading.py
@@ -787,6 +787,32 @@ class ThreadingExceptionTests(BaseTestCase):
self.assertEqual(p.returncode, 0, "Unexpected error: " + stderr.decode())
self.assertEqual(data, expected_output)
+class TimerTests(BaseTestCase):
+
+ def setUp(self):
+ BaseTestCase.setUp(self)
+ self.callback_args = []
+ self.callback_event = threading.Event()
+
+ def test_init_immutable_default_args(self):
+ # Issue 17435: constructor defaults were mutable objects, they could be
+ # mutated via the object attributes and affect other Timer objects.
+ timer1 = threading.Timer(0.01, self._callback_spy)
+ timer1.start()
+ self.callback_event.wait()
+ timer1.args.append("blah")
+ timer1.kwargs["foo"] = "bar"
+ self.callback_event.clear()
+ timer2 = threading.Timer(0.01, self._callback_spy)
+ timer2.start()
+ self.callback_event.wait()
+ self.assertEqual(len(self.callback_args), 2)
+ self.assertEqual(self.callback_args, [((), {}), ((), {})])
+
+ def _callback_spy(self, *args, **kwargs):
+ self.callback_args.append((args[:], kwargs.copy()))
+ self.callback_event.set()
+
class LockTests(lock_tests.LockTests):
locktype = staticmethod(threading.Lock)
@@ -816,16 +842,5 @@ class BoundedSemaphoreTests(lock_tests.BoundedSemaphoreTests):
class BarrierTests(lock_tests.BarrierTests):
barriertype = staticmethod(threading.Barrier)
-
-def test_main():
- test.support.run_unittest(LockTests, PyRLockTests, CRLockTests, EventTests,
- ConditionAsRLockTests, ConditionTests,
- SemaphoreTests, BoundedSemaphoreTests,
- ThreadTests,
- ThreadJoinOnShutdown,
- ThreadingExceptionTests,
- BarrierTests,
- )
-
if __name__ == "__main__":
- test_main()
+ unittest.main()