Open test log in bytes mode

pull/14/head
Dan Puttick 2017-04-12 15:50:02 -04:00
parent a8179d0688
commit d470d6bb21
1 changed files with 10 additions and 7 deletions

View File

@ -5,21 +5,24 @@ from datetime import datetime
def save_logs(groomer, test_description): def save_logs(groomer, test_description):
divider = ('=' * 10 + '{}' + '=' * 10 + '\n') divider = ('=' * 10 + '{}' + '=' * 10 + '\n')
test_log_path = 'tests/test_logs/{}.log'.format(test_description) test_log_path = 'tests/test_logs/{}.log'.format(test_description)
with open(test_log_path, 'w+') as test_log: time_now = str(datetime.now().time()) + '\n'
test_log.write(divider.format('TEST LOG')) with open(test_log_path, 'wb+') as test_log:
test_log.write(str(datetime.now().time()) + '\n') log_header = divider.format('TEST LOG')
test_log.write(test_description + '\n') test_log.write(bytes(log_header, encoding='utf-8'))
test_log.write('-' * 20 + '\n') test_log.write(bytes(time_now, encoding='utf-8'))
test_log.write(bytes(test_description, encoding='utf-8'))
test_log.write(b'\n')
test_log.write(b'-' * 20 + b'\n')
with open(groomer.logger.log_path, 'rb') as logfile: with open(groomer.logger.log_path, 'rb') as logfile:
log = logfile.read() log = logfile.read()
test_log.write(log) test_log.write(log)
if os.path.exists(groomer.logger.log_debug_err): if os.path.exists(groomer.logger.log_debug_err):
test_log.write(divider.format('ERR LOG')) test_log.write(bytes(divider.format('ERR LOG'), encoding='utf-8'))
with open(groomer.logger.log_debug_err, 'rb') as debug_err: with open(groomer.logger.log_debug_err, 'rb') as debug_err:
err = debug_err.read() err = debug_err.read()
test_log.write(err) test_log.write(err)
if os.path.exists(groomer.logger.log_debug_out): if os.path.exists(groomer.logger.log_debug_out):
test_log.write(divider.format('OUT LOG')) test_log.write(bytes(divider.format('OUT LOG'), encoding='utf-8'))
with open(groomer.logger.log_debug_out, 'rb') as debug_out: with open(groomer.logger.log_debug_out, 'rb') as debug_out:
out = debug_out.read() out = debug_out.read()
test_log.write(out) test_log.write(out)