|
24 | 24 | import pytest |
25 | 25 | import sys |
26 | 26 | import logging |
| 27 | +import time |
27 | 28 | import MDAnalysis as mda |
28 | 29 |
|
29 | 30 | from os.path import basename |
30 | 31 | from MDAnalysis.lib.log import ProgressBar |
31 | 32 |
|
32 | 33 |
|
| 34 | +@pytest.fixture |
| 35 | +def fixed_log_time(monkeypatch): |
| 36 | + """Pytest fixture which temporarily set the logging's t0 to the UNIX epoc""" |
| 37 | + epoch = 0 |
| 38 | + |
| 39 | + monkeypatch.setattr(logging.time, "time", lambda: epoch) |
| 40 | + monkeypatch.setattr(logging.Formatter, "converter", time.gmtime) |
| 41 | + |
| 42 | + |
33 | 43 | class TestConvenienceFunctions: |
34 | 44 | def test_start_logging(self, tmp_path): |
35 | 45 | mda.start_logging(tmp_path / "MDAnalysis.log") |
@@ -57,11 +67,26 @@ def test_stop_logging(self, tmp_path): |
57 | 67 |
|
58 | 68 | assert len(logger.handlers) == 0 |
59 | 69 |
|
60 | | -def test_message_console(tmp_path): |
61 | | - pass |
| 70 | + def test_message_file(self, tmp_path, fixed_log_time): |
| 71 | + |
| 72 | + mda.start_logging(tmp_path / "MDAnalysis.log") |
| 73 | + |
| 74 | + with open(tmp_path / "MDAnalysis.log") as f: |
| 75 | + |
| 76 | + assert ( |
| 77 | + "1970-01-01 00:00:00,000 MDAnalysis INFO " |
| 78 | + + f"MDAnalysis {mda.version.__version__} STARTED logging to {str(tmp_path)}" |
| 79 | + ) |
| 80 | + |
| 81 | + def test_message_console(self, tmp_path, capsys): |
| 82 | + mda.start_logging(tmp_path / "MDAnalysis.log") |
| 83 | + |
| 84 | + assert ( |
| 85 | + "MDAnalysis : INFO " |
| 86 | + + f"MDAnalysis {mda.version.__version__} STARTED logging to {str(tmp_path)}" |
| 87 | + in capsys.readouterr().out |
| 88 | + ) |
62 | 89 |
|
63 | | -def test_message_file(tmp_path): |
64 | | - pass |
65 | 90 |
|
66 | 91 | # TODO need to make a fixture that can clear all handlers per test |
67 | 92 | class TestCreateBehaviors: |
@@ -93,15 +118,19 @@ def test_exception(tmp_path): |
93 | 118 | ): |
94 | 119 | mda.lib.log.create(stream=2) |
95 | 120 |
|
| 121 | + |
96 | 122 | def test_level_parameter(): |
97 | 123 | pass |
98 | 124 |
|
| 125 | + |
99 | 126 | def test_fmt_parameter(): |
100 | 127 | pass |
101 | 128 |
|
| 129 | + |
102 | 130 | def test_mode_parameter(): |
103 | 131 | pass |
104 | 132 |
|
| 133 | + |
105 | 134 | class TestProgressBar(object): |
106 | 135 |
|
107 | 136 | def test_output(self, capsys): |
|
0 commit comments