Skip to content

Commit d952902

Browse files
committed
Updated Tests
1 parent 0fdd02e commit d952902

1 file changed

Lines changed: 32 additions & 0 deletions

File tree

testsuite/MDAnalysisTests/lib/test_log.py

Lines changed: 32 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -21,6 +21,7 @@
2121
# J. Comput. Chem. 32 (2011), 2319--2327, doi:10.1002/jcc.21787
2222
#
2323

24+
import pytest
2425
import sys
2526
import logging
2627
import MDAnalysis as mda
@@ -57,6 +58,37 @@ def test_stop_logging(self, tmp_path):
5758
assert len(logger.handlers) == 0
5859

5960

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+
6092
class TestProgressBar(object):
6193

6294
def test_output(self, capsys):

0 commit comments

Comments
 (0)