You cannot select more than 25 topics Topics must start with a letter or number, can include dashes ('-') and can be up to 35 characters long.

39 lines
1.1 KiB
Python

"""
Test the logger module.
"""
# Author: Gael Varoquaux <gael dot varoquaux at normalesup dot org>
# Copyright (c) 2009 Gael Varoquaux
# License: BSD Style, 3 clauses.
import re
from joblib.logger import PrintTime
try:
# Python 2/Python 3 compat
unicode('str')
except NameError:
unicode = lambda s: s
def test_print_time(tmpdir, capsys):
# A simple smoke test for PrintTime.
logfile = tmpdir.join('test.log').strpath
print_time = PrintTime(logfile=logfile)
print_time(unicode('Foo'))
# Create a second time, to smoke test log rotation.
print_time = PrintTime(logfile=logfile)
print_time(unicode('Foo'))
# And a third time
print_time = PrintTime(logfile=logfile)
print_time(unicode('Foo'))
out_printed_text, err_printed_text = capsys.readouterr()
# Use regexps to be robust to time variations
match = r"Foo: 0\..s, 0\..min\nFoo: 0\..s, 0..min\nFoo: " + \
r".\..s, 0..min\n"
if not re.match(match, err_printed_text):
raise AssertionError('Excepted %s, got %s' %
(match, err_printed_text))