Rev 3178: Make more than 99% of the bzr core tests pickable. in file:///v/home/vila/src/bzr/experimental/selftest/
Vincent Ladeuil
v.ladeuil+lp at free.fr
Thu Jan 10 22:31:16 GMT 2008
At file:///v/home/vila/src/bzr/experimental/selftest/
------------------------------------------------------------
revno: 3178
revision-id:v.ladeuil+lp at free.fr-20080110223112-a4emv5adley9ncz7
parent: v.ladeuil+lp at free.fr-20080110211454-0qvigli37mad5hd4
committer: Vincent Ladeuil <v.ladeuil+lp at free.fr>
branch nick: selftest
timestamp: Thu 2008-01-10 23:31:12 +0100
message:
Make more than 99% of the bzr core tests pickable.
* bzrlib/tests/__init__.py:
(TestCase.id): Add a '_id' parameter for parameterized tests to
avoid using lambdas (which are not pickable).
* bzrlib/tests/__init__.py:
(save_test_list): doctests can't be reliably pickled. Guard
against data shared between tests (side-effect of failed picklings
?).
(TestScenarioApplier.adapt_test_to_scenario): Avoid lambda use.
* bzrlib/tests/per_lock/__init__.py:
(LockTestProviderAdapter._clone_test): Avoid lambda use.
* bzrlib/tests/EncodingAdapter.py:
(EncodingTestAdapter.adapt): Avoid lambda use.
modified:
bzrlib/tests/EncodingAdapter.py EncodingAdapter.py-20060113032051-4d7e1d8c1e38b4a1
bzrlib/tests/__init__.py selftest.py-20050531073622-8d0e3c8845c97a64
bzrlib/tests/per_lock/__init__.py __init__.py-20070314201444-u92yjsqrkh2m3qcb-1
-------------- next part --------------
=== modified file 'bzrlib/tests/EncodingAdapter.py'
--- a/bzrlib/tests/EncodingAdapter.py 2006-10-11 23:08:27 +0000
+++ b/bzrlib/tests/EncodingAdapter.py 2008-01-10 22:31:12 +0000
@@ -126,13 +126,11 @@
new_test = deepcopy(test)
new_test.encoding = encoding
new_test.info = info
- def make_new_test_id():
- if count:
- new_id = "%s(%s,%s)" % (new_test.id(), encoding, count)
- else:
- new_id = "%s(%s)" % (new_test.id(), encoding)
- return lambda: new_id
- new_test.id = make_new_test_id()
+ if count:
+ new_id = "%s(%s,%s)" % (test.id(), encoding, count)
+ else:
+ new_id = "%s(%s)" % (test.id(), encoding)
+ new_test._id = new_id
result.addTest(new_test)
return result
=== modified file 'bzrlib/tests/__init__.py'
--- a/bzrlib/tests/__init__.py 2008-01-10 21:14:54 +0000
+++ b/bzrlib/tests/__init__.py 2008-01-10 22:31:12 +0000
@@ -783,6 +783,7 @@
accidentally overlooked.
"""
+ _id = None
_log_file_name = None
_log_contents = ''
_keep_log_file = False
@@ -793,6 +794,12 @@
super(TestCase, self).__init__(methodName)
self._cleanups = []
+ def id(self):
+ if self._id is not None:
+ return self._id
+ else:
+ return unittest.TestCase.id(self)
+
def setUp(self):
unittest.TestCase.setUp(self)
self._cleanEnvironment()
@@ -2719,8 +2726,18 @@
pickler = cPickle.Pickler(ftest, cPickle.HIGHEST_PROTOCOL)
fpos = ftest.tell()
for t in iter_suite_tests(suite):
+ if isinstance(t, doctest.DocTestCase):
+ # Since doctests use __globals__ as an attribute there are too many
+ # problems pickling them (including lazy import related problems),
+ # punting for now
+ stream.write('Excluding %s: %s\n'
+ % (t, 'DocTestCase cannot be pickled reliably'))
+ continue
+
try:
pickler.dump(t)
+ # Tests should not share any data isn't it ?
+ pickler.clear_memo()
except cPickle.PicklingError, e:
ftest.truncate(fpos) # Get rid of partial pickle
ftest.seek(fpos, 0)
@@ -2918,8 +2935,7 @@
new_test = deepcopy(test)
for name, value in scenario[1].items():
setattr(new_test, name, value)
- new_id = "%s(%s)" % (new_test.id(), scenario[0])
- new_test.id = lambda: new_id
+ new_test._id = "%s(%s)" % (new_test.id(), scenario[0])
return new_test
=== modified file 'bzrlib/tests/per_lock/__init__.py'
--- a/bzrlib/tests/per_lock/__init__.py 2007-03-14 23:40:34 +0000
+++ b/bzrlib/tests/per_lock/__init__.py 2008-01-10 22:31:12 +0000
@@ -49,10 +49,7 @@
new_test = deepcopy(test)
new_test.write_lock = write_lock
new_test.read_lock = read_lock
- def make_new_test_id():
- new_id = "%s(%s)" % (test.id(), variation)
- return lambda: new_id
- new_test.id = make_new_test_id()
+ new_test._id = "%s(%s)" % (test.id(), variation)
return new_test
def adapt(self, test):
More information about the bazaar-commits
mailing list