summaryrefslogtreecommitdiffstats
path: root/Lib/test/test_threading_local.py
diff options
context:
space:
mode:
authorAntoine Pitrou <solipsis@pitrou.net>2010-08-03 18:41:05 (GMT)
committerAntoine Pitrou <solipsis@pitrou.net>2010-08-03 18:41:05 (GMT)
commit29643b0978c9270a1e6dcd13de3ab2e9497eee1a (patch)
tree2ddfeafc18a2f22d124f0188b22771d87cbb1256 /Lib/test/test_threading_local.py
parent732cc9be1e95c8bf39bc6535968e521f513a9a1e (diff)
downloadcpython-29643b0978c9270a1e6dcd13de3ab2e9497eee1a.zip
cpython-29643b0978c9270a1e6dcd13de3ab2e9497eee1a.tar.gz
cpython-29643b0978c9270a1e6dcd13de3ab2e9497eee1a.tar.bz2
Recorded merge of revisions 83678 via svnmerge from
svn+ssh://pythondev@svn.python.org/python/branches/py3k ........ r83678 | antoine.pitrou | 2010-08-03 20:32:26 +0200 (mar., 03 août 2010) | 4 lines In test_threading_local, test both the default _thread._local implementation and the pure Python implementation in Lib/_threading_local.py ........
Diffstat (limited to 'Lib/test/test_threading_local.py')
-rw-r--r--Lib/test/test_threading_local.py26
1 files changed, 20 insertions, 6 deletions
diff --git a/Lib/test/test_threading_local.py b/Lib/test/test_threading_local.py
index 726117f..2b896ff 100644
--- a/Lib/test/test_threading_local.py
+++ b/Lib/test/test_threading_local.py
@@ -1,10 +1,15 @@
import unittest
from doctest import DocTestSuite
from test import support
-import threading
import weakref
import gc
+# Modules under test
+_thread = support.import_module('_thread')
+threading = support.import_module('threading')
+import _threading_local
+
+
class Weak(object):
pass
@@ -13,7 +18,8 @@ def target(local, weaklist):
local.weak = weak
weaklist.append(weakref.ref(weak))
-class ThreadingLocalTest(unittest.TestCase):
+
+class BaseLocalTest:
def test_local_refs(self):
self._local_refs(20)
@@ -21,7 +27,7 @@ class ThreadingLocalTest(unittest.TestCase):
self._local_refs(100)
def _local_refs(self, n):
- local = threading.local()
+ local = self._local()
weaklist = []
for i in range(n):
t = threading.Thread(target=target, args=(local, weaklist))
@@ -48,7 +54,7 @@ class ThreadingLocalTest(unittest.TestCase):
# is created but not correctly set on the object.
# The first member set may be bogus.
import time
- class Local(threading.local):
+ class Local(self._local):
def __init__(self):
time.sleep(0.01)
local = Local()
@@ -69,7 +75,7 @@ class ThreadingLocalTest(unittest.TestCase):
def test_derived_cycle_dealloc(self):
# http://bugs.python.org/issue6990
- class Local(threading.local):
+ class Local(self._local):
pass
locals = None
passed = False
@@ -107,10 +113,18 @@ class ThreadingLocalTest(unittest.TestCase):
self.assertTrue(passed)
+class ThreadLocalTest(unittest.TestCase, BaseLocalTest):
+ _local = _thread._local
+
+class PyThreadingLocalTest(unittest.TestCase, BaseLocalTest):
+ _local = _threading_local.local
+
+
def test_main():
suite = unittest.TestSuite()
suite.addTest(DocTestSuite('_threading_local'))
- suite.addTest(unittest.makeSuite(ThreadingLocalTest))
+ suite.addTest(unittest.makeSuite(ThreadLocalTest))
+ suite.addTest(unittest.makeSuite(PyThreadingLocalTest))
try:
from thread import _local