tests: fix timezone issues for test_quteprocess

Depending on the timezone, you may either get 00:00 as time or 01:00,
which is bad for testing on different machines.
This commit is contained in:
Daniel Schadt 2016-05-26 15:39:14 +02:00
parent 5f2d5feb58
commit fa2636c2f6

View File

@ -93,8 +93,7 @@ def test_quteprocess_quitting(qtbot, quteproc_process):
'"earlyinit", "funcName": "init_log", "lineno": 280, "levelno": 10, ' '"earlyinit", "funcName": "init_log", "lineno": 280, "levelno": 10, '
'"message": "Log initialized."}', '"message": "Log initialized."}',
{ {
'timestamp': datetime.datetime(year=1970, month=1, day=1, 'timestamp': datetime.datetime.fromtimestamp(0),
hour=1, minute=0, second=0),
'loglevel': logging.DEBUG, 'loglevel': logging.DEBUG,
'category': 'init', 'category': 'init',
'module': 'earlyinit', 'module': 'earlyinit',
@ -182,7 +181,7 @@ def test_log_line_parse(data, attrs):
{'created': 0, 'levelname': 'DEBUG', 'name': 'foo', 'module': 'bar', {'created': 0, 'levelname': 'DEBUG', 'name': 'foo', 'module': 'bar',
'funcName': 'qux', 'lineno': 10, 'levelno': 10, 'message': 'quux'}, 'funcName': 'qux', 'lineno': 10, 'levelno': 10, 'message': 'quux'},
False, False,
'01:00:00 DEBUG foo bar:qux:10 quux', '{timestamp} DEBUG foo bar:qux:10 quux',
), ),
# Traceback attached # Traceback attached
( (
@ -191,7 +190,7 @@ def test_log_line_parse(data, attrs):
'traceback': 'Traceback (most recent call last):\n here be ' 'traceback': 'Traceback (most recent call last):\n here be '
'dragons'}, 'dragons'},
False, False,
'01:00:00 DEBUG foo bar:qux:10 quux\n' '{timestamp} DEBUG foo bar:qux:10 quux\n'
'Traceback (most recent call last):\n' 'Traceback (most recent call last):\n'
' here be dragons', ' here be dragons',
), ),
@ -200,13 +199,15 @@ def test_log_line_parse(data, attrs):
{'created': 0, 'levelname': 'DEBUG', 'name': 'foo', 'module': 'bar', {'created': 0, 'levelname': 'DEBUG', 'name': 'foo', 'module': 'bar',
'funcName': 'qux', 'lineno': 10, 'levelno': 10, 'message': 'quux'}, 'funcName': 'qux', 'lineno': 10, 'levelno': 10, 'message': 'quux'},
True, True,
'\033[32m01:00:00\033[0m \033[37mDEBUG \033[0m \033[36mfoo ' '\033[32m{timestamp}\033[0m \033[37mDEBUG \033[0m \033[36mfoo '
'bar:qux:10\033[0m \033[37mquux\033[0m', 'bar:qux:10\033[0m \033[37mquux\033[0m',
), ),
], ids=['normal', 'traceback', 'colored']) ], ids=['normal', 'traceback', 'colored'])
def test_log_line_formatted(data, colorized, expected): def test_log_line_formatted(data, colorized, expected):
line = json.dumps(data) line = json.dumps(data)
record = quteprocess.LogLine(line) record = quteprocess.LogLine(line)
ts = datetime.datetime.fromtimestamp(data['created']).strftime('%H:%M:%S')
expected = expected.format(timestamp=ts)
assert record.formatted_str(colorized=colorized) == expected assert record.formatted_str(colorized=colorized) == expected