1638
1639
pseudo_log_file = StringIO()
1639
1640
def _get_log_contents_for_weird_testtools_api():
1640
1641
return [pseudo_log_file.getvalue().decode(
1641
"utf-8", "replace").encode("utf-8")]
1642
"utf-8", "replace").encode("utf-8")]
1642
1643
self.addDetail("log", content.Content(content.ContentType("text",
1643
1644
"plain", {"charset": "utf8"}),
1644
1645
_get_log_contents_for_weird_testtools_api))
2066
2067
# so we will avoid using it on all platforms, just to
2067
2068
# make sure the code path is used, and we don't break on win32
2068
2069
cleanup_environment()
2070
# Include the subprocess's log file in the test details, in case
2071
# the test fails due to an error in the subprocess.
2072
self._add_subprocess_log(trace._get_bzr_log_filename())
2069
2073
command = [sys.executable]
2070
2074
# frozen executables don't need the path to bzr
2071
2075
if getattr(sys, "frozen", None) is None:
2090
def _add_subprocess_log(self, log_file_path):
2091
if len(self._log_files) == 0:
2092
# Register an addCleanup func. We do this on the first call to
2093
# _add_subprocess_log rather than in TestCase.setUp so that this
2094
# addCleanup is registered after any cleanups for tempdirs that
2095
# subclasses might create, which will probably remove the log file
2097
self.addCleanup(self._subprocess_log_cleanup)
2098
# self._log_files is a set, so if a log file is reused we won't grab it
2100
self._log_files.add(log_file_path)
2102
def _subprocess_log_cleanup(self):
2103
for count, log_file_path in enumerate(self._log_files):
2104
# We use buffer_now=True to avoid holding the file open beyond
2105
# the life of this function, which might interfere with e.g.
2106
# cleaning tempdirs on Windows.
2107
# XXX: Testtools 0.9.5 doesn't have the content_from_file helper
2108
#detail_content = content.content_from_file(
2109
# log_file_path, buffer_now=True)
2110
with open(log_file_path, 'rb') as log_file:
2111
log_file_bytes = log_file.read()
2112
detail_content = content.Content(content.ContentType("text",
2113
"plain", {"charset": "utf8"}), lambda: [log_file_bytes])
2114
self.addDetail("start_bzr_subprocess-log-%d" % (count,),
2086
2117
def _popen(self, *args, **kwargs):
2087
2118
"""Place a call to Popen.