test_logger.py 985 B

1234567891011121314151617181920212223242526272829303132
  1. """
  2. Test the logger module.
  3. """
  4. # Author: Gael Varoquaux <gael dot varoquaux at normalesup dot org>
  5. # Copyright (c) 2009 Gael Varoquaux
  6. # License: BSD Style, 3 clauses.
  7. import re
  8. from joblib.logger import PrintTime
  9. def test_print_time(tmpdir, capsys):
  10. # A simple smoke test for PrintTime.
  11. logfile = tmpdir.join('test.log').strpath
  12. print_time = PrintTime(logfile=logfile)
  13. print_time('Foo')
  14. # Create a second time, to smoke test log rotation.
  15. print_time = PrintTime(logfile=logfile)
  16. print_time('Foo')
  17. # And a third time
  18. print_time = PrintTime(logfile=logfile)
  19. print_time('Foo')
  20. out_printed_text, err_printed_text = capsys.readouterr()
  21. # Use regexps to be robust to time variations
  22. match = r"Foo: 0\..s, 0\..min\nFoo: 0\..s, 0..min\nFoo: " + \
  23. r".\..s, 0..min\n"
  24. if not re.match(match, err_printed_text):
  25. raise AssertionError('Excepted %s, got %s' %
  26. (match, err_printed_text))