Rev 5408: (jameinel) Use StringIO rather than real files on disk for log files in in file:///home/pqm/archives/thelove/bzr/%2Btrunk/
Canonical.com Patch Queue Manager
pqm at pqm.ubuntu.com
Fri Sep 3 02:32:47 BST 2010
At file:///home/pqm/archives/thelove/bzr/%2Btrunk/
------------------------------------------------------------
revno: 5408 [merge]
revision-id: pqm at pqm.ubuntu.com-20100903013246-mydkx60um8b2trfq
parent: pqm at pqm.ubuntu.com-20100903001355-l29hnxtjgnlhpq2f
parent: andrew.bennetts at canonical.com-20100902014312-1l886v8xyz8bxwbv
committer: Canonical.com Patch Queue Manager <pqm at pqm.ubuntu.com>
branch nick: +trunk
timestamp: Fri 2010-09-03 02:32:46 +0100
message:
(jameinel) Use StringIO rather than real files on disk for log files in
tests. (Andrew Bennetts)
modified:
NEWS NEWS-20050323055033-4e00b5db738777ff
bzrlib/tests/__init__.py selftest.py-20050531073622-8d0e3c8845c97a64
bzrlib/tests/test_setup.py test_setup.py-20051208073730-4a59a6368c4efa04
=== modified file 'NEWS'
--- a/NEWS 2010-09-01 19:10:42 +0000
+++ b/NEWS 2010-09-03 01:32:46 +0000
@@ -252,6 +252,10 @@
* HTTP test servers will leak less threads (and sockets) and will not hang on
AIX anymore. (Vincent Ladeuil, #405745)
+* The test suite now simply holds log files in memory, rather than writing them
+ out to disk and then reading them back in and deleting them.
+ (Andrew Bennetts)
+
* The way ``bzr selftest --parallel`` generates N partitions of tests to
run in parallel has changed. Instead of splitting the list of tests at
N-1 points, it distributes the tests one-by-one into the partitions in a
=== modified file 'bzrlib/tests/__init__.py'
--- a/bzrlib/tests/__init__.py 2010-09-02 22:51:29 +0000
+++ b/bzrlib/tests/__init__.py 2010-09-03 01:32:46 +0000
@@ -794,7 +794,7 @@
_active_threads = None
_leaking_threads_tests = 0
_first_thread_leaker_id = None
- _log_file_name = None
+ _log_file = None
# record lsprof data when performing benchmark calls.
_gather_lsprof_in_benchmarks = False
@@ -1454,10 +1454,8 @@
The file is removed as the test is torn down.
"""
- fileno, name = tempfile.mkstemp(suffix='.log', prefix='testbzr')
- self._log_file = os.fdopen(fileno, 'w+')
+ self._log_file = StringIO()
self._log_memento = bzrlib.trace.push_log_file(self._log_file)
- self._log_file_name = name
self.addCleanup(self._finishLogFile)
def _finishLogFile(self):
@@ -1665,65 +1663,21 @@
unicodestr = self._log_contents.decode('utf8', 'replace')
self._log_contents = unicodestr.encode('utf8')
return self._log_contents
- import bzrlib.trace
- if bzrlib.trace._trace_file:
- # flush the log file, to get all content
- bzrlib.trace._trace_file.flush()
- if self._log_file_name is not None:
- logfile = open(self._log_file_name)
- try:
- log_contents = logfile.read()
- finally:
- logfile.close()
+ 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:
- close_attempts = 0
- max_close_attempts = 100
- first_close_error = None
- while close_attempts < max_close_attempts:
- close_attempts += 1
- try:
- self._log_file.close()
- except IOError, ioe:
- if ioe.errno is None:
- # No errno implies 'close() called during
- # concurrent operation on the same file object', so
- # retry. Probably a thread is trying to write to
- # the log file.
- if first_close_error is None:
- first_close_error = ioe
- continue
- raise
- else:
- break
- if close_attempts > 1:
- sys.stderr.write(
- 'Unable to close log file on first attempt, '
- 'will retry: %s\n' % (first_close_error,))
- if close_attempts == max_close_attempts:
- sys.stderr.write(
- 'Unable to close log file after %d attempts.\n'
- % (max_close_attempts,))
self._log_file = None
# Permit multiple calls to get_log until we clean it up in
# finishLogFile
self._log_contents = log_contents
- try:
- os.remove(self._log_file_name)
- except OSError, e:
- if sys.platform == 'win32' and e.errno == errno.EACCES:
- sys.stderr.write(('Unable to delete log file '
- ' %r\n' % self._log_file_name))
- else:
- raise
- self._log_file_name = None
return log_contents
else:
- return "No log file content and no log file name."
+ return "No log file content."
def get_log(self):
"""Get a unicode string containing the log from bzrlib.trace.
=== modified file 'bzrlib/tests/test_setup.py'
--- a/bzrlib/tests/test_setup.py 2009-03-23 14:59:43 +0000
+++ b/bzrlib/tests/test_setup.py 2010-09-02 00:49:06 +0000
@@ -74,9 +74,11 @@
self.log('args: %r', args)
p = subprocess.Popen(args,
cwd=self.source_dir,
- stdout=self._log_file,
- stderr=self._log_file,
+ stdout=subprocess.PIPE,
+ stderr=subprocess.PIPE,
)
- s = p.communicate()
+ stdout, stderr = p.communicate()
+ self.log('stdout: %r', stdout)
+ self.log('stderr: %r', stderr)
self.assertEqual(0, p.returncode,
'invocation of %r failed' % args)
More information about the bazaar-commits
mailing list