Rev 5902: Re-apply the bits of TestCase that I wanted, on the new bzr.dev tip. in http://bazaar.launchpad.net/~jameinel/bzr.dev-good
John Arbash Meinel
john at arbash-meinel.com
Tue May 24 19:18:27 UTC 2011
At http://bazaar.launchpad.net/~jameinel/bzr.dev-good
------------------------------------------------------------
revno: 5902 [merge]
revision-id: john at arbash-meinel.com-20110524191808-zy45zt5pj6qu4vff
parent: pqm at pqm.ubuntu.com-20110520110731-8slefcqat6dr3asl
parent: john at arbash-meinel.com-20110519185007-yzrct57glwjip8co
committer: John Arbash Meinel <john at arbash-meinel.com>
branch nick: bzr.dev-good
timestamp: Tue 2011-05-24 21:18:08 +0200
message:
Re-apply the bits of TestCase that I wanted, on the new bzr.dev tip.
modified:
bzrlib/tests/__init__.py selftest.py-20050531073622-8d0e3c8845c97a64
-------------- next part --------------
=== modified file 'bzrlib/tests/__init__.py'
--- a/bzrlib/tests/__init__.py 2011-05-20 11:07:31 +0000
+++ b/bzrlib/tests/__init__.py 2011-05-24 19:18:08 +0000
@@ -377,13 +377,21 @@
if isinstance(test, TestCase):
test.addCleanup(self._check_leaked_threads, test)
+ def stopTest(self, test):
+ super(ExtendedTestResult, self).stopTest(test)
+ # Manually break cycles, means touching various private things but hey
+ getDetails = getattr(test, "getDetails", None)
+ if getDetails is not None:
+ getDetails().clear()
+ type_equality_funcs = getattr(test, "_type_equality_funcs", None)
+ if type_equality_funcs is not None:
+ type_equality_funcs.clear()
+ self._traceback_from_test = None
+
def startTests(self):
self.report_tests_starting()
self._active_threads = threading.enumerate()
- def stopTest(self, test):
- self._traceback_from_test = None
-
def _check_leaked_threads(self, test):
"""See if any threads have leaked since last call
@@ -963,10 +971,6 @@
super(TestCase, self).setUp()
for feature in getattr(self, '_test_needs_features', []):
self.requireFeature(feature)
- self._log_contents = None
- self.addDetail("log", content.Content(content.ContentType("text",
- "plain", {"charset": "utf8"}),
- lambda:[self._get_log(keep_log_file=True)]))
self._cleanEnvironment()
self._silenceUI()
self._startLogFile()
@@ -1323,13 +1327,13 @@
try:
def capture():
orig_log_exception_quietly()
- captured.append(sys.exc_info())
+ captured.append(sys.exc_info()[1])
trace.log_exception_quietly = capture
func(*args, **kwargs)
finally:
trace.log_exception_quietly = orig_log_exception_quietly
self.assertLength(1, captured)
- err = captured[0][1]
+ err = captured[0]
self.assertIsInstance(err, exception_class)
return err
@@ -1630,7 +1634,14 @@
The file is removed as the test is torn down.
"""
- self._log_file = StringIO()
+ pseudo_log_file = StringIO()
+ def _get_log_contents_for_weird_testtools_api():
+ return [pseudo_log_file.getvalue().decode(
+ "utf-8", "replace").encode("utf-8")]
+ self.addDetail("log", content.Content(content.ContentType("text",
+ "plain", {"charset": "utf8"}),
+ _get_log_contents_for_weird_testtools_api))
+ self._log_file = pseudo_log_file
self._log_memento = trace.push_log_file(self._log_file)
self.addCleanup(self._finishLogFile)
@@ -1643,8 +1654,6 @@
# flush the log file, to get all content
trace._trace_file.flush()
trace.pop_log_file(self._log_memento)
- # Cache the log result and delete the file on disk
- self._get_log(False)
def thisFailsStrictLockCheck(self):
"""It is known that this test would fail with -Dstrict_locks.
@@ -1699,7 +1708,9 @@
def _restoreHooks(self):
for klass, (name, hooks) in self._preserved_hooks.items():
setattr(klass, name, hooks)
- hooks._lazy_hooks = self._preserved_lazy_hooks
+ self._preserved_hooks.clear()
+ bzrlib.hooks._lazy_hooks = self._preserved_lazy_hooks
+ self._preserved_lazy_hooks.clear()
def knownFailure(self, reason):
"""This test has failed for some known reason."""
@@ -1797,41 +1808,6 @@
def log(self, *args):
trace.mutter(*args)
- def _get_log(self, keep_log_file=False):
- """Internal helper to get the log from bzrlib.trace for this test.
-
- Please use self.getDetails, or self.get_log to access this in test case
- code.
-
- :param keep_log_file: When True, if the log is still a file on disk
- leave it as a file on disk. When False, if the log is still a file
- on disk, the log file is deleted and the log preserved as
- self._log_contents.
- :return: A string containing the log.
- """
- if self._log_contents is not None:
- try:
- self._log_contents.decode('utf8')
- except UnicodeDecodeError:
- unicodestr = self._log_contents.decode('utf8', 'replace')
- self._log_contents = unicodestr.encode('utf8')
- return self._log_contents
- if self._log_file is not None:
- log_contents = self._log_file.getvalue()
- try:
- log_contents.decode('utf8')
- except UnicodeDecodeError:
- unicodestr = log_contents.decode('utf8', 'replace')
- log_contents = unicodestr.encode('utf8')
- if not keep_log_file:
- self._log_file = None
- # Permit multiple calls to get_log until we clean it up in
- # finishLogFile
- self._log_contents = log_contents
- return log_contents
- else:
- return "No log file content."
-
def get_log(self):
"""Get a unicode string containing the log from bzrlib.trace.
More information about the bazaar-commits
mailing list