2004-07-15 03:11:50 +08:00
|
|
|
import unittest
|
|
|
|
from doctest import DocTestSuite
|
2008-05-21 05:35:26 +08:00
|
|
|
from test import support
|
Merged revisions 60053-60078 via svnmerge from
svn+ssh://pythondev@svn.python.org/python/trunk
........
r60054 | christian.heimes | 2008-01-18 20:12:56 +0100 (Fri, 18 Jan 2008) | 1 line
Silence Coverity false alerts with CIDs #172, #183, #184
........
r60057 | guido.van.rossum | 2008-01-18 21:56:30 +0100 (Fri, 18 Jan 2008) | 3 lines
Fix an edge case whereby the __del__() method of a classic class could
create a new weakref to the object.
........
r60058 | raymond.hettinger | 2008-01-18 22:14:58 +0100 (Fri, 18 Jan 2008) | 1 line
Better variable name in an example.
........
r60063 | guido.van.rossum | 2008-01-19 00:05:40 +0100 (Sat, 19 Jan 2008) | 3 lines
This got fixed for classic classes in r60057,
and backported to 2.5.2 in 60056.
........
r60068 | jeffrey.yasskin | 2008-01-19 10:56:06 +0100 (Sat, 19 Jan 2008) | 4 lines
Several tweaks: add construction from strings and .from_decimal(), change
__init__ to __new__ to enforce immutability, and remove "rational." from repr
and the parens from str.
........
r60069 | georg.brandl | 2008-01-19 11:11:27 +0100 (Sat, 19 Jan 2008) | 2 lines
Fix markup.
........
r60070 | georg.brandl | 2008-01-19 11:16:09 +0100 (Sat, 19 Jan 2008) | 3 lines
Amend curses docs by info how to write non-ascii characters.
Thanks to Jeroen Ruigrok van der Werven.
........
r60071 | georg.brandl | 2008-01-19 11:18:07 +0100 (Sat, 19 Jan 2008) | 2 lines
Indentation normalization.
........
r60073 | facundo.batista | 2008-01-19 13:32:27 +0100 (Sat, 19 Jan 2008) | 5 lines
Fix issue #1822: MIMEMultipart.is_multipart() behaves correctly for a
just-created (and empty) instance. Added tests for this. Thanks
Jonathan Share.
........
r60074 | andrew.kuchling | 2008-01-19 14:33:20 +0100 (Sat, 19 Jan 2008) | 1 line
Polish sentence
........
r60075 | christian.heimes | 2008-01-19 14:46:06 +0100 (Sat, 19 Jan 2008) | 1 line
Added unit test to verify that threading.local doesn't cause ref leaks. It seems that the thread local storage always keeps the storage of the last stopped thread alive. Can anybody comment on it, please?
........
r60076 | christian.heimes | 2008-01-19 16:06:09 +0100 (Sat, 19 Jan 2008) | 1 line
Update for threading.local test.
........
r60077 | andrew.kuchling | 2008-01-19 16:16:37 +0100 (Sat, 19 Jan 2008) | 1 line
Polish sentence
........
r60078 | georg.brandl | 2008-01-19 16:22:16 +0100 (Sat, 19 Jan 2008) | 2 lines
Fix typos.
........
2008-01-20 00:21:02 +08:00
|
|
|
import weakref
|
|
|
|
import gc
|
|
|
|
|
2010-08-04 02:41:05 +08:00
|
|
|
# Modules under test
|
|
|
|
_thread = support.import_module('_thread')
|
|
|
|
threading = support.import_module('threading')
|
|
|
|
import _threading_local
|
|
|
|
|
|
|
|
|
Merged revisions 60053-60078 via svnmerge from
svn+ssh://pythondev@svn.python.org/python/trunk
........
r60054 | christian.heimes | 2008-01-18 20:12:56 +0100 (Fri, 18 Jan 2008) | 1 line
Silence Coverity false alerts with CIDs #172, #183, #184
........
r60057 | guido.van.rossum | 2008-01-18 21:56:30 +0100 (Fri, 18 Jan 2008) | 3 lines
Fix an edge case whereby the __del__() method of a classic class could
create a new weakref to the object.
........
r60058 | raymond.hettinger | 2008-01-18 22:14:58 +0100 (Fri, 18 Jan 2008) | 1 line
Better variable name in an example.
........
r60063 | guido.van.rossum | 2008-01-19 00:05:40 +0100 (Sat, 19 Jan 2008) | 3 lines
This got fixed for classic classes in r60057,
and backported to 2.5.2 in 60056.
........
r60068 | jeffrey.yasskin | 2008-01-19 10:56:06 +0100 (Sat, 19 Jan 2008) | 4 lines
Several tweaks: add construction from strings and .from_decimal(), change
__init__ to __new__ to enforce immutability, and remove "rational." from repr
and the parens from str.
........
r60069 | georg.brandl | 2008-01-19 11:11:27 +0100 (Sat, 19 Jan 2008) | 2 lines
Fix markup.
........
r60070 | georg.brandl | 2008-01-19 11:16:09 +0100 (Sat, 19 Jan 2008) | 3 lines
Amend curses docs by info how to write non-ascii characters.
Thanks to Jeroen Ruigrok van der Werven.
........
r60071 | georg.brandl | 2008-01-19 11:18:07 +0100 (Sat, 19 Jan 2008) | 2 lines
Indentation normalization.
........
r60073 | facundo.batista | 2008-01-19 13:32:27 +0100 (Sat, 19 Jan 2008) | 5 lines
Fix issue #1822: MIMEMultipart.is_multipart() behaves correctly for a
just-created (and empty) instance. Added tests for this. Thanks
Jonathan Share.
........
r60074 | andrew.kuchling | 2008-01-19 14:33:20 +0100 (Sat, 19 Jan 2008) | 1 line
Polish sentence
........
r60075 | christian.heimes | 2008-01-19 14:46:06 +0100 (Sat, 19 Jan 2008) | 1 line
Added unit test to verify that threading.local doesn't cause ref leaks. It seems that the thread local storage always keeps the storage of the last stopped thread alive. Can anybody comment on it, please?
........
r60076 | christian.heimes | 2008-01-19 16:06:09 +0100 (Sat, 19 Jan 2008) | 1 line
Update for threading.local test.
........
r60077 | andrew.kuchling | 2008-01-19 16:16:37 +0100 (Sat, 19 Jan 2008) | 1 line
Polish sentence
........
r60078 | georg.brandl | 2008-01-19 16:22:16 +0100 (Sat, 19 Jan 2008) | 2 lines
Fix typos.
........
2008-01-20 00:21:02 +08:00
|
|
|
class Weak(object):
|
|
|
|
pass
|
|
|
|
|
|
|
|
def target(local, weaklist):
|
|
|
|
weak = Weak()
|
|
|
|
local.weak = weak
|
|
|
|
weaklist.append(weakref.ref(weak))
|
|
|
|
|
2010-08-04 02:41:05 +08:00
|
|
|
|
|
|
|
class BaseLocalTest:
|
Merged revisions 60053-60078 via svnmerge from
svn+ssh://pythondev@svn.python.org/python/trunk
........
r60054 | christian.heimes | 2008-01-18 20:12:56 +0100 (Fri, 18 Jan 2008) | 1 line
Silence Coverity false alerts with CIDs #172, #183, #184
........
r60057 | guido.van.rossum | 2008-01-18 21:56:30 +0100 (Fri, 18 Jan 2008) | 3 lines
Fix an edge case whereby the __del__() method of a classic class could
create a new weakref to the object.
........
r60058 | raymond.hettinger | 2008-01-18 22:14:58 +0100 (Fri, 18 Jan 2008) | 1 line
Better variable name in an example.
........
r60063 | guido.van.rossum | 2008-01-19 00:05:40 +0100 (Sat, 19 Jan 2008) | 3 lines
This got fixed for classic classes in r60057,
and backported to 2.5.2 in 60056.
........
r60068 | jeffrey.yasskin | 2008-01-19 10:56:06 +0100 (Sat, 19 Jan 2008) | 4 lines
Several tweaks: add construction from strings and .from_decimal(), change
__init__ to __new__ to enforce immutability, and remove "rational." from repr
and the parens from str.
........
r60069 | georg.brandl | 2008-01-19 11:11:27 +0100 (Sat, 19 Jan 2008) | 2 lines
Fix markup.
........
r60070 | georg.brandl | 2008-01-19 11:16:09 +0100 (Sat, 19 Jan 2008) | 3 lines
Amend curses docs by info how to write non-ascii characters.
Thanks to Jeroen Ruigrok van der Werven.
........
r60071 | georg.brandl | 2008-01-19 11:18:07 +0100 (Sat, 19 Jan 2008) | 2 lines
Indentation normalization.
........
r60073 | facundo.batista | 2008-01-19 13:32:27 +0100 (Sat, 19 Jan 2008) | 5 lines
Fix issue #1822: MIMEMultipart.is_multipart() behaves correctly for a
just-created (and empty) instance. Added tests for this. Thanks
Jonathan Share.
........
r60074 | andrew.kuchling | 2008-01-19 14:33:20 +0100 (Sat, 19 Jan 2008) | 1 line
Polish sentence
........
r60075 | christian.heimes | 2008-01-19 14:46:06 +0100 (Sat, 19 Jan 2008) | 1 line
Added unit test to verify that threading.local doesn't cause ref leaks. It seems that the thread local storage always keeps the storage of the last stopped thread alive. Can anybody comment on it, please?
........
r60076 | christian.heimes | 2008-01-19 16:06:09 +0100 (Sat, 19 Jan 2008) | 1 line
Update for threading.local test.
........
r60077 | andrew.kuchling | 2008-01-19 16:16:37 +0100 (Sat, 19 Jan 2008) | 1 line
Polish sentence
........
r60078 | georg.brandl | 2008-01-19 16:22:16 +0100 (Sat, 19 Jan 2008) | 2 lines
Fix typos.
........
2008-01-20 00:21:02 +08:00
|
|
|
|
|
|
|
def test_local_refs(self):
|
|
|
|
self._local_refs(20)
|
|
|
|
self._local_refs(50)
|
|
|
|
self._local_refs(100)
|
|
|
|
|
|
|
|
def _local_refs(self, n):
|
2010-08-04 02:41:05 +08:00
|
|
|
local = self._local()
|
Merged revisions 60053-60078 via svnmerge from
svn+ssh://pythondev@svn.python.org/python/trunk
........
r60054 | christian.heimes | 2008-01-18 20:12:56 +0100 (Fri, 18 Jan 2008) | 1 line
Silence Coverity false alerts with CIDs #172, #183, #184
........
r60057 | guido.van.rossum | 2008-01-18 21:56:30 +0100 (Fri, 18 Jan 2008) | 3 lines
Fix an edge case whereby the __del__() method of a classic class could
create a new weakref to the object.
........
r60058 | raymond.hettinger | 2008-01-18 22:14:58 +0100 (Fri, 18 Jan 2008) | 1 line
Better variable name in an example.
........
r60063 | guido.van.rossum | 2008-01-19 00:05:40 +0100 (Sat, 19 Jan 2008) | 3 lines
This got fixed for classic classes in r60057,
and backported to 2.5.2 in 60056.
........
r60068 | jeffrey.yasskin | 2008-01-19 10:56:06 +0100 (Sat, 19 Jan 2008) | 4 lines
Several tweaks: add construction from strings and .from_decimal(), change
__init__ to __new__ to enforce immutability, and remove "rational." from repr
and the parens from str.
........
r60069 | georg.brandl | 2008-01-19 11:11:27 +0100 (Sat, 19 Jan 2008) | 2 lines
Fix markup.
........
r60070 | georg.brandl | 2008-01-19 11:16:09 +0100 (Sat, 19 Jan 2008) | 3 lines
Amend curses docs by info how to write non-ascii characters.
Thanks to Jeroen Ruigrok van der Werven.
........
r60071 | georg.brandl | 2008-01-19 11:18:07 +0100 (Sat, 19 Jan 2008) | 2 lines
Indentation normalization.
........
r60073 | facundo.batista | 2008-01-19 13:32:27 +0100 (Sat, 19 Jan 2008) | 5 lines
Fix issue #1822: MIMEMultipart.is_multipart() behaves correctly for a
just-created (and empty) instance. Added tests for this. Thanks
Jonathan Share.
........
r60074 | andrew.kuchling | 2008-01-19 14:33:20 +0100 (Sat, 19 Jan 2008) | 1 line
Polish sentence
........
r60075 | christian.heimes | 2008-01-19 14:46:06 +0100 (Sat, 19 Jan 2008) | 1 line
Added unit test to verify that threading.local doesn't cause ref leaks. It seems that the thread local storage always keeps the storage of the last stopped thread alive. Can anybody comment on it, please?
........
r60076 | christian.heimes | 2008-01-19 16:06:09 +0100 (Sat, 19 Jan 2008) | 1 line
Update for threading.local test.
........
r60077 | andrew.kuchling | 2008-01-19 16:16:37 +0100 (Sat, 19 Jan 2008) | 1 line
Polish sentence
........
r60078 | georg.brandl | 2008-01-19 16:22:16 +0100 (Sat, 19 Jan 2008) | 2 lines
Fix typos.
........
2008-01-20 00:21:02 +08:00
|
|
|
weaklist = []
|
|
|
|
for i in range(n):
|
|
|
|
t = threading.Thread(target=target, args=(local, weaklist))
|
|
|
|
t.start()
|
|
|
|
t.join()
|
|
|
|
del t
|
|
|
|
|
|
|
|
gc.collect()
|
|
|
|
self.assertEqual(len(weaklist), n)
|
|
|
|
|
2010-08-10 06:41:38 +08:00
|
|
|
# XXX _threading_local keeps the local of the last stopped thread alive.
|
Merged revisions 60053-60078 via svnmerge from
svn+ssh://pythondev@svn.python.org/python/trunk
........
r60054 | christian.heimes | 2008-01-18 20:12:56 +0100 (Fri, 18 Jan 2008) | 1 line
Silence Coverity false alerts with CIDs #172, #183, #184
........
r60057 | guido.van.rossum | 2008-01-18 21:56:30 +0100 (Fri, 18 Jan 2008) | 3 lines
Fix an edge case whereby the __del__() method of a classic class could
create a new weakref to the object.
........
r60058 | raymond.hettinger | 2008-01-18 22:14:58 +0100 (Fri, 18 Jan 2008) | 1 line
Better variable name in an example.
........
r60063 | guido.van.rossum | 2008-01-19 00:05:40 +0100 (Sat, 19 Jan 2008) | 3 lines
This got fixed for classic classes in r60057,
and backported to 2.5.2 in 60056.
........
r60068 | jeffrey.yasskin | 2008-01-19 10:56:06 +0100 (Sat, 19 Jan 2008) | 4 lines
Several tweaks: add construction from strings and .from_decimal(), change
__init__ to __new__ to enforce immutability, and remove "rational." from repr
and the parens from str.
........
r60069 | georg.brandl | 2008-01-19 11:11:27 +0100 (Sat, 19 Jan 2008) | 2 lines
Fix markup.
........
r60070 | georg.brandl | 2008-01-19 11:16:09 +0100 (Sat, 19 Jan 2008) | 3 lines
Amend curses docs by info how to write non-ascii characters.
Thanks to Jeroen Ruigrok van der Werven.
........
r60071 | georg.brandl | 2008-01-19 11:18:07 +0100 (Sat, 19 Jan 2008) | 2 lines
Indentation normalization.
........
r60073 | facundo.batista | 2008-01-19 13:32:27 +0100 (Sat, 19 Jan 2008) | 5 lines
Fix issue #1822: MIMEMultipart.is_multipart() behaves correctly for a
just-created (and empty) instance. Added tests for this. Thanks
Jonathan Share.
........
r60074 | andrew.kuchling | 2008-01-19 14:33:20 +0100 (Sat, 19 Jan 2008) | 1 line
Polish sentence
........
r60075 | christian.heimes | 2008-01-19 14:46:06 +0100 (Sat, 19 Jan 2008) | 1 line
Added unit test to verify that threading.local doesn't cause ref leaks. It seems that the thread local storage always keeps the storage of the last stopped thread alive. Can anybody comment on it, please?
........
r60076 | christian.heimes | 2008-01-19 16:06:09 +0100 (Sat, 19 Jan 2008) | 1 line
Update for threading.local test.
........
r60077 | andrew.kuchling | 2008-01-19 16:16:37 +0100 (Sat, 19 Jan 2008) | 1 line
Polish sentence
........
r60078 | georg.brandl | 2008-01-19 16:22:16 +0100 (Sat, 19 Jan 2008) | 2 lines
Fix typos.
........
2008-01-20 00:21:02 +08:00
|
|
|
deadlist = [weak for weak in weaklist if weak() is None]
|
2010-08-10 06:41:38 +08:00
|
|
|
self.assertIn(len(deadlist), (n-1, n))
|
Merged revisions 60053-60078 via svnmerge from
svn+ssh://pythondev@svn.python.org/python/trunk
........
r60054 | christian.heimes | 2008-01-18 20:12:56 +0100 (Fri, 18 Jan 2008) | 1 line
Silence Coverity false alerts with CIDs #172, #183, #184
........
r60057 | guido.van.rossum | 2008-01-18 21:56:30 +0100 (Fri, 18 Jan 2008) | 3 lines
Fix an edge case whereby the __del__() method of a classic class could
create a new weakref to the object.
........
r60058 | raymond.hettinger | 2008-01-18 22:14:58 +0100 (Fri, 18 Jan 2008) | 1 line
Better variable name in an example.
........
r60063 | guido.van.rossum | 2008-01-19 00:05:40 +0100 (Sat, 19 Jan 2008) | 3 lines
This got fixed for classic classes in r60057,
and backported to 2.5.2 in 60056.
........
r60068 | jeffrey.yasskin | 2008-01-19 10:56:06 +0100 (Sat, 19 Jan 2008) | 4 lines
Several tweaks: add construction from strings and .from_decimal(), change
__init__ to __new__ to enforce immutability, and remove "rational." from repr
and the parens from str.
........
r60069 | georg.brandl | 2008-01-19 11:11:27 +0100 (Sat, 19 Jan 2008) | 2 lines
Fix markup.
........
r60070 | georg.brandl | 2008-01-19 11:16:09 +0100 (Sat, 19 Jan 2008) | 3 lines
Amend curses docs by info how to write non-ascii characters.
Thanks to Jeroen Ruigrok van der Werven.
........
r60071 | georg.brandl | 2008-01-19 11:18:07 +0100 (Sat, 19 Jan 2008) | 2 lines
Indentation normalization.
........
r60073 | facundo.batista | 2008-01-19 13:32:27 +0100 (Sat, 19 Jan 2008) | 5 lines
Fix issue #1822: MIMEMultipart.is_multipart() behaves correctly for a
just-created (and empty) instance. Added tests for this. Thanks
Jonathan Share.
........
r60074 | andrew.kuchling | 2008-01-19 14:33:20 +0100 (Sat, 19 Jan 2008) | 1 line
Polish sentence
........
r60075 | christian.heimes | 2008-01-19 14:46:06 +0100 (Sat, 19 Jan 2008) | 1 line
Added unit test to verify that threading.local doesn't cause ref leaks. It seems that the thread local storage always keeps the storage of the last stopped thread alive. Can anybody comment on it, please?
........
r60076 | christian.heimes | 2008-01-19 16:06:09 +0100 (Sat, 19 Jan 2008) | 1 line
Update for threading.local test.
........
r60077 | andrew.kuchling | 2008-01-19 16:16:37 +0100 (Sat, 19 Jan 2008) | 1 line
Polish sentence
........
r60078 | georg.brandl | 2008-01-19 16:22:16 +0100 (Sat, 19 Jan 2008) | 2 lines
Fix typos.
........
2008-01-20 00:21:02 +08:00
|
|
|
|
|
|
|
# Assignment to the same thread local frees it sometimes (!)
|
|
|
|
local.someothervar = None
|
|
|
|
gc.collect()
|
|
|
|
deadlist = [weak for weak in weaklist if weak() is None]
|
2009-08-13 16:51:18 +08:00
|
|
|
self.assertTrue(len(deadlist) in (n-1, n), (n, len(deadlist)))
|
2004-07-15 03:11:50 +08:00
|
|
|
|
2008-07-01 07:30:24 +08:00
|
|
|
def test_derived(self):
|
|
|
|
# Issue 3088: if there is a threads switch inside the __init__
|
|
|
|
# of a threading.local derived class, the per-thread dictionary
|
|
|
|
# is created but not correctly set on the object.
|
|
|
|
# The first member set may be bogus.
|
|
|
|
import time
|
2010-08-04 02:41:05 +08:00
|
|
|
class Local(self._local):
|
2008-07-01 07:30:24 +08:00
|
|
|
def __init__(self):
|
|
|
|
time.sleep(0.01)
|
|
|
|
local = Local()
|
|
|
|
|
|
|
|
def f(i):
|
|
|
|
local.x = i
|
|
|
|
# Simply check that the variable is correctly set
|
|
|
|
self.assertEqual(local.x, i)
|
|
|
|
|
|
|
|
threads= []
|
|
|
|
for i in range(10):
|
|
|
|
t = threading.Thread(target=f, args=(i,))
|
|
|
|
t.start()
|
|
|
|
threads.append(t)
|
|
|
|
|
|
|
|
for t in threads:
|
|
|
|
t.join()
|
|
|
|
|
2009-09-29 13:03:48 +08:00
|
|
|
def test_derived_cycle_dealloc(self):
|
|
|
|
# http://bugs.python.org/issue6990
|
2010-08-04 02:41:05 +08:00
|
|
|
class Local(self._local):
|
2009-09-29 13:03:48 +08:00
|
|
|
pass
|
|
|
|
locals = None
|
|
|
|
passed = False
|
|
|
|
e1 = threading.Event()
|
|
|
|
e2 = threading.Event()
|
|
|
|
|
|
|
|
def f():
|
|
|
|
nonlocal passed
|
|
|
|
# 1) Involve Local in a cycle
|
|
|
|
cycle = [Local()]
|
|
|
|
cycle.append(cycle)
|
|
|
|
cycle[0].foo = 'bar'
|
|
|
|
|
|
|
|
# 2) GC the cycle (triggers threadmodule.c::local_clear
|
|
|
|
# before local_dealloc)
|
|
|
|
del cycle
|
|
|
|
gc.collect()
|
|
|
|
e1.set()
|
|
|
|
e2.wait()
|
|
|
|
|
|
|
|
# 4) New Locals should be empty
|
|
|
|
passed = all(not hasattr(local, 'foo') for local in locals)
|
|
|
|
|
|
|
|
t = threading.Thread(target=f)
|
|
|
|
t.start()
|
|
|
|
e1.wait()
|
|
|
|
|
|
|
|
# 3) New Locals should recycle the original's address. Creating
|
|
|
|
# them in the thread overwrites the thread state and avoids the
|
|
|
|
# bug
|
|
|
|
locals = [Local() for i in range(10)]
|
|
|
|
e2.set()
|
|
|
|
t.join()
|
|
|
|
|
|
|
|
self.assertTrue(passed)
|
|
|
|
|
2010-08-29 02:27:09 +08:00
|
|
|
def _test_one_class(self, c):
|
|
|
|
self._failed = "No error message set or cleared."
|
|
|
|
obj = c()
|
|
|
|
e1 = threading.Event()
|
|
|
|
e2 = threading.Event()
|
|
|
|
|
|
|
|
def f1():
|
|
|
|
obj.x = 'foo'
|
|
|
|
obj.y = 'bar'
|
|
|
|
del obj.y
|
|
|
|
e1.set()
|
|
|
|
e2.wait()
|
|
|
|
|
|
|
|
def f2():
|
|
|
|
try:
|
|
|
|
foo = obj.x
|
|
|
|
except AttributeError:
|
|
|
|
# This is expected -- we haven't set obj.x in this thread yet!
|
|
|
|
self._failed = "" # passed
|
|
|
|
else:
|
|
|
|
self._failed = ('Incorrectly got value %r from class %r\n' %
|
|
|
|
(foo, c))
|
|
|
|
sys.stderr.write(self._failed)
|
|
|
|
|
|
|
|
t1 = threading.Thread(target=f1)
|
|
|
|
t1.start()
|
|
|
|
e1.wait()
|
|
|
|
t2 = threading.Thread(target=f2)
|
|
|
|
t2.start()
|
|
|
|
t2.join()
|
|
|
|
# The test is done; just let t1 know it can exit, and wait for it.
|
|
|
|
e2.set()
|
|
|
|
t1.join()
|
|
|
|
|
|
|
|
self.assertFalse(self._failed, self._failed)
|
|
|
|
|
|
|
|
def test_threading_local(self):
|
|
|
|
self._test_one_class(self._local)
|
|
|
|
|
|
|
|
def test_threading_local_subclass(self):
|
|
|
|
class LocalSubclass(self._local):
|
|
|
|
"""To test that subclasses behave properly."""
|
|
|
|
self._test_one_class(LocalSubclass)
|
|
|
|
|
|
|
|
def _test_dict_attribute(self, cls):
|
|
|
|
obj = cls()
|
|
|
|
obj.x = 5
|
|
|
|
self.assertEqual(obj.__dict__, {'x': 5})
|
|
|
|
with self.assertRaises(AttributeError):
|
|
|
|
obj.__dict__ = {}
|
|
|
|
with self.assertRaises(AttributeError):
|
|
|
|
del obj.__dict__
|
|
|
|
|
|
|
|
def test_dict_attribute(self):
|
|
|
|
self._test_dict_attribute(self._local)
|
|
|
|
|
|
|
|
def test_dict_attribute_subclass(self):
|
|
|
|
class LocalSubclass(self._local):
|
|
|
|
"""To test that subclasses behave properly."""
|
|
|
|
self._test_dict_attribute(LocalSubclass)
|
|
|
|
|
2008-07-01 07:30:24 +08:00
|
|
|
|
2010-08-04 02:41:05 +08:00
|
|
|
class ThreadLocalTest(unittest.TestCase, BaseLocalTest):
|
|
|
|
_local = _thread._local
|
|
|
|
|
2010-08-10 06:41:38 +08:00
|
|
|
# Fails for the pure Python implementation
|
|
|
|
def test_cycle_collection(self):
|
|
|
|
class X:
|
|
|
|
pass
|
|
|
|
|
|
|
|
x = X()
|
|
|
|
x.local = self._local()
|
|
|
|
x.local.x = x
|
|
|
|
wr = weakref.ref(x)
|
|
|
|
del x
|
|
|
|
gc.collect()
|
|
|
|
self.assertIs(wr(), None)
|
|
|
|
|
2010-08-04 02:41:05 +08:00
|
|
|
class PyThreadingLocalTest(unittest.TestCase, BaseLocalTest):
|
|
|
|
_local = _threading_local.local
|
|
|
|
|
|
|
|
|
2004-07-15 03:11:50 +08:00
|
|
|
def test_main():
|
Merged revisions 60053-60078 via svnmerge from
svn+ssh://pythondev@svn.python.org/python/trunk
........
r60054 | christian.heimes | 2008-01-18 20:12:56 +0100 (Fri, 18 Jan 2008) | 1 line
Silence Coverity false alerts with CIDs #172, #183, #184
........
r60057 | guido.van.rossum | 2008-01-18 21:56:30 +0100 (Fri, 18 Jan 2008) | 3 lines
Fix an edge case whereby the __del__() method of a classic class could
create a new weakref to the object.
........
r60058 | raymond.hettinger | 2008-01-18 22:14:58 +0100 (Fri, 18 Jan 2008) | 1 line
Better variable name in an example.
........
r60063 | guido.van.rossum | 2008-01-19 00:05:40 +0100 (Sat, 19 Jan 2008) | 3 lines
This got fixed for classic classes in r60057,
and backported to 2.5.2 in 60056.
........
r60068 | jeffrey.yasskin | 2008-01-19 10:56:06 +0100 (Sat, 19 Jan 2008) | 4 lines
Several tweaks: add construction from strings and .from_decimal(), change
__init__ to __new__ to enforce immutability, and remove "rational." from repr
and the parens from str.
........
r60069 | georg.brandl | 2008-01-19 11:11:27 +0100 (Sat, 19 Jan 2008) | 2 lines
Fix markup.
........
r60070 | georg.brandl | 2008-01-19 11:16:09 +0100 (Sat, 19 Jan 2008) | 3 lines
Amend curses docs by info how to write non-ascii characters.
Thanks to Jeroen Ruigrok van der Werven.
........
r60071 | georg.brandl | 2008-01-19 11:18:07 +0100 (Sat, 19 Jan 2008) | 2 lines
Indentation normalization.
........
r60073 | facundo.batista | 2008-01-19 13:32:27 +0100 (Sat, 19 Jan 2008) | 5 lines
Fix issue #1822: MIMEMultipart.is_multipart() behaves correctly for a
just-created (and empty) instance. Added tests for this. Thanks
Jonathan Share.
........
r60074 | andrew.kuchling | 2008-01-19 14:33:20 +0100 (Sat, 19 Jan 2008) | 1 line
Polish sentence
........
r60075 | christian.heimes | 2008-01-19 14:46:06 +0100 (Sat, 19 Jan 2008) | 1 line
Added unit test to verify that threading.local doesn't cause ref leaks. It seems that the thread local storage always keeps the storage of the last stopped thread alive. Can anybody comment on it, please?
........
r60076 | christian.heimes | 2008-01-19 16:06:09 +0100 (Sat, 19 Jan 2008) | 1 line
Update for threading.local test.
........
r60077 | andrew.kuchling | 2008-01-19 16:16:37 +0100 (Sat, 19 Jan 2008) | 1 line
Polish sentence
........
r60078 | georg.brandl | 2008-01-19 16:22:16 +0100 (Sat, 19 Jan 2008) | 2 lines
Fix typos.
........
2008-01-20 00:21:02 +08:00
|
|
|
suite = unittest.TestSuite()
|
|
|
|
suite.addTest(DocTestSuite('_threading_local'))
|
2010-08-04 02:41:05 +08:00
|
|
|
suite.addTest(unittest.makeSuite(ThreadLocalTest))
|
|
|
|
suite.addTest(unittest.makeSuite(PyThreadingLocalTest))
|
2004-07-15 03:11:50 +08:00
|
|
|
|
2010-08-04 08:19:35 +08:00
|
|
|
local_orig = _threading_local.local
|
|
|
|
def setUp(test):
|
|
|
|
_threading_local.local = _thread._local
|
|
|
|
def tearDown(test):
|
|
|
|
_threading_local.local = local_orig
|
|
|
|
suite.addTest(DocTestSuite('_threading_local',
|
|
|
|
setUp=setUp, tearDown=tearDown)
|
|
|
|
)
|
2004-07-15 03:11:50 +08:00
|
|
|
|
2008-05-21 05:35:26 +08:00
|
|
|
support.run_unittest(suite)
|
2004-07-15 03:11:50 +08:00
|
|
|
|
|
|
|
if __name__ == '__main__':
|
|
|
|
test_main()
|