2017-07-07 00:00:55 +02:00
|
|
|
#!/usr/bin/env python
|
|
|
|
# -*- coding: utf-8 -*-
|
2017-07-06 21:41:38 +02:00
|
|
|
|
2017-07-07 00:00:55 +02:00
|
|
|
import os
|
2017-07-20 19:18:48 +02:00
|
|
|
from datetime import datetime
|
2016-12-24 22:46:22 +01:00
|
|
|
|
2017-08-07 23:18:15 +02:00
|
|
|
import pytest
|
|
|
|
|
|
|
|
try:
|
2017-08-11 00:12:30 +02:00
|
|
|
from filecheck.filecheck import KittenGroomerFileCheck
|
2017-08-07 23:18:15 +02:00
|
|
|
NODEPS = False
|
|
|
|
except ImportError:
|
|
|
|
NODEPS = True
|
|
|
|
pytestmark = pytest.mark.skipif(NODEPS, reason="Dependencies aren't installed")
|
2017-07-06 21:41:38 +02:00
|
|
|
|
2016-12-24 22:46:22 +01:00
|
|
|
|
|
|
|
def save_logs(groomer, test_description):
|
|
|
|
divider = ('=' * 10 + '{}' + '=' * 10 + '\n')
|
2017-07-20 19:18:48 +02:00
|
|
|
test_log_path = 'tests/{}.log'.format(test_description)
|
2017-04-12 21:50:02 +02:00
|
|
|
time_now = str(datetime.now().time()) + '\n'
|
|
|
|
with open(test_log_path, 'wb+') as test_log:
|
2017-07-20 19:38:54 +02:00
|
|
|
test_log_header = divider.format('TEST LOG')
|
|
|
|
test_log.write(bytes(test_log_header, encoding='utf-8'))
|
2017-04-12 21:50:02 +02:00
|
|
|
test_log.write(bytes(time_now, encoding='utf-8'))
|
|
|
|
test_log.write(bytes(test_description, encoding='utf-8'))
|
|
|
|
test_log.write(b'\n')
|
2017-07-20 19:38:54 +02:00
|
|
|
log_header = divider.format('STD LOG')
|
|
|
|
test_log.write(bytes(log_header, encoding='utf-8'))
|
2017-04-12 21:32:57 +02:00
|
|
|
with open(groomer.logger.log_path, 'rb') as logfile:
|
2016-12-24 22:46:22 +01:00
|
|
|
log = logfile.read()
|
|
|
|
test_log.write(log)
|
2017-03-18 03:19:56 +01:00
|
|
|
if os.path.exists(groomer.logger.log_debug_err):
|
2017-04-12 21:50:02 +02:00
|
|
|
test_log.write(bytes(divider.format('ERR LOG'), encoding='utf-8'))
|
2017-04-12 21:32:57 +02:00
|
|
|
with open(groomer.logger.log_debug_err, 'rb') as debug_err:
|
2017-03-18 03:19:56 +01:00
|
|
|
err = debug_err.read()
|
|
|
|
test_log.write(err)
|
|
|
|
if os.path.exists(groomer.logger.log_debug_out):
|
2017-04-12 21:50:02 +02:00
|
|
|
test_log.write(bytes(divider.format('OUT LOG'), encoding='utf-8'))
|
2017-04-12 21:32:57 +02:00
|
|
|
with open(groomer.logger.log_debug_out, 'rb') as debug_out:
|
2017-03-18 03:19:56 +01:00
|
|
|
out = debug_out.read()
|
|
|
|
test_log.write(out)
|
2017-07-19 19:19:48 +02:00
|
|
|
|
|
|
|
|
2017-07-20 19:18:48 +02:00
|
|
|
def test_logging(tmpdir):
|
|
|
|
groomer = KittenGroomerFileCheck('tests/logging/', tmpdir.strpath)
|
2017-07-19 19:19:48 +02:00
|
|
|
groomer.run()
|
2017-07-20 19:18:48 +02:00
|
|
|
save_logs(groomer, "visual_logging_test")
|