test: Try to make output format more readable

Replace the Python repr() syntax and the overly-long standard output
markers.

This format should make it easier to read the logs and copy-paste the
commands.
This commit is contained in:
João Valverde 2023-04-21 01:14:16 +01:00
parent defd2d90fb
commit 7c712c2e7d
1 changed files with 18 additions and 7 deletions

View File

@ -60,7 +60,7 @@ class LoggingPopen(subprocess.Popen):
kwargs['stderr'] = subprocess.PIPE
# Make sure communicate() gives us bytes.
kwargs['universal_newlines'] = False
self.cmd_str = 'command ' + repr(proc_args)
self.proc_args = proc_args
super().__init__(proc_args, *args, **kwargs)
self.stdout_str = ''
self.stderr_str = ''
@ -84,12 +84,23 @@ class LoggingPopen(subprocess.Popen):
out_log = self.trim_output(out_log, self.max_lines)
err_log = err_data.decode('UTF-8', 'replace')
self.log_fd.flush()
self.log_fd.write('-- Begin stdout for {} --\n'.format(self.cmd_str))
self.log_fd.write(out_log)
self.log_fd.write('-- End stdout for {} --\n'.format(self.cmd_str))
self.log_fd.write('-- Begin stderr for {} --\n'.format(self.cmd_str))
self.log_fd.write(err_log)
self.log_fd.write('-- End stderr for {} --\n'.format(self.cmd_str))
if isinstance(self.proc_args, list):
cmd_str = ' '.join(self.proc_args)
else:
cmd_str = self.proc_args
self.log_fd.write('-- Command: {}\n'.format(cmd_str))
if out_log:
self.log_fd.write('-- Begin stdout\n')
self.log_fd.write(out_log)
self.log_fd.write('-- End stdout\n')
else:
self.log_fd.write('-- Empty stdout\n')
if err_log:
self.log_fd.write('-- Begin stderr\n')
self.log_fd.write(err_log)
self.log_fd.write('-- End stderr\n')
else:
self.log_fd.write('-- Empty stderr\n')
self.log_fd.flush()
# Make sure our output is the same everywhere.
# Throwing a UnicodeDecodeError exception here is arguably a good thing.