diff --git a/tests/test_utils.py b/tests/test_utils.py index f74f8691e..d1ce86c94 100644 --- a/tests/test_utils.py +++ b/tests/test_utils.py @@ -161,3 +161,29 @@ def test_read_metadata(self, tmpdir): with pytest.raises(ValueError) as e_info: utils.read_metadata(meta_fn, as_data_frame=True) assert str(e_info.value) == "Duplicated strain in metadata: SEQ_1" + + def test_myopen_text(self, tmpdir): + """Read a text file.""" + path = str(tmpdir / 'test.txt') + with open(path, 'w') as f_write: + f_write.write('foo\nbar\n') + with utils.myopen(path) as f_read: + assert f_read.read() == 'foo\nbar\n' + + def test_myopen_gzip(self, tmpdir): + """Read a text file compressed with gzip.""" + import gzip + path = str(tmpdir / 'test.txt.gz') + with gzip.open(path, 'wt') as f_write: + f_write.write('foo\nbar\n') + with utils.myopen(path) as f_read: + assert f_read.read() == 'foo\nbar\n' + + def test_myopen_lzma(self, tmpdir): + """Read a text file compressed with LZMA.""" + import lzma + path = str(tmpdir / 'test.txt.xz') + with lzma.open(path, 'wt') as f_write: + f_write.write('foo\nbar\n') + with utils.myopen(path) as f_read: + assert f_read.read() == 'foo\nbar\n'