Skip to content

Commit

Permalink
Add tests for utils.myopen()
Browse files Browse the repository at this point in the history
  • Loading branch information
victorlin committed May 17, 2022
1 parent cffae91 commit 1cf0e9e
Showing 1 changed file with 26 additions and 0 deletions.
26 changes: 26 additions & 0 deletions tests/test_utils.py
Original file line number Diff line number Diff line change
Expand Up @@ -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'

0 comments on commit 1cf0e9e

Please sign in to comment.