|
21 | 21 | # J. Comput. Chem. 32 (2011), 2319--2327, doi:10.1002/jcc.21787 |
22 | 22 | # |
23 | 23 |
|
| 24 | +import pytest |
24 | 25 | import sys |
25 | 26 | import logging |
26 | 27 | import MDAnalysis as mda |
@@ -57,6 +58,37 @@ def test_stop_logging(self, tmp_path): |
57 | 58 | assert len(logger.handlers) == 0 |
58 | 59 |
|
59 | 60 |
|
| 61 | +# TODO need to make a fixture that can clear all handlers per test |
| 62 | +class TestCreateBehaviors: |
| 63 | + |
| 64 | + def test_input_path(self, tmp_path): |
| 65 | + mda.lib.log.create(stream=tmp_path / "foo.log") |
| 66 | + |
| 67 | + assert (tmp_path / "foo.log").exists() |
| 68 | + |
| 69 | + def test_input_string(self, tmp_path): |
| 70 | + mda.lib.log.create(stream=str(tmp_path / "foo.log")) |
| 71 | + |
| 72 | + assert (tmp_path / "foo.log").exists() |
| 73 | + |
| 74 | + # NOTE Assert state could be cleaned up after clear_handlers() fixture is implemented |
| 75 | + def test_input_stream(self): |
| 76 | + mda.lib.log.create(stream=sys.stdout) |
| 77 | + |
| 78 | + logger = logging.getLogger("MDAnalysis") |
| 79 | + assert any( |
| 80 | + isinstance(h, logging.StreamHandler) and h.stream is sys.stdout |
| 81 | + for h in logger.handlers |
| 82 | + ) |
| 83 | + |
| 84 | + def test_exception(tmp_path): |
| 85 | + with pytest.raises( |
| 86 | + TypeError, |
| 87 | + match="Input Stream is neither a string, PathLike object or a stream", |
| 88 | + ): |
| 89 | + mda.lib.log.create(stream=2) |
| 90 | + |
| 91 | + |
60 | 92 | class TestProgressBar(object): |
61 | 93 |
|
62 | 94 | def test_output(self, capsys): |
|
0 commit comments