Skip to content

Commit

Permalink
fix read gzip, add test case
Browse files Browse the repository at this point in the history
  • Loading branch information
schristley committed Oct 18, 2024
1 parent 871cf2e commit 11b79c7
Show file tree
Hide file tree
Showing 3 changed files with 20 additions and 1 deletion.
2 changes: 1 addition & 1 deletion lang/python/airr/interface.py
Original file line number Diff line number Diff line change
Expand Up @@ -41,7 +41,7 @@ def read_rearrangement(filename, validate=False, debug=False):
airr.io.RearrangementReader: iterable reader class.
"""
if filename.endswith(".gz"):
handle = gzip.open(filename, 'r')
handle = gzip.open(filename, 'rt')
else:
handle = open(filename, 'r')

Expand Down
Binary file added lang/python/tests/data/good_rearrangement.tsv.gz
Binary file not shown.
19 changes: 19 additions & 0 deletions lang/python/tests/test_interface.py
Original file line number Diff line number Diff line change
Expand Up @@ -23,6 +23,7 @@ def setUp(self):

# Test data
self.rearrangement_good = os.path.join(data_path, 'good_rearrangement.tsv')
self.rearrangement_good_gz = os.path.join(data_path, 'good_rearrangement.tsv.gz')
self.rearrangement_bad = os.path.join(data_path, 'bad_rearrangement.tsv')
self.rep_good = os.path.join(data_path, 'good_repertoire.yaml')
self.rep_bad = os.path.join(data_path, 'bad_repertoire.yaml')
Expand Down Expand Up @@ -59,6 +60,24 @@ def test_load_rearrangement(self):
result = airr.load_rearrangement(self.rearrangement_bad)
self.assertTupleEqual(result.shape, self.shape_bad, 'load(): bad data failed')

# @unittest.skip('-> read_rearrangement(): skipped\n')
def test_read_rearrangement(self):
# Good data
result = []
reader = airr.read_rearrangement(self.rearrangement_good)
for row in reader:
result.append(row)
reader.close()
self.assertTrue(len(result) == self.shape_good[0], 'read_rearrangement(): good data failed')

# Good data, gzip
result = []
reader = airr.read_rearrangement(self.rearrangement_good_gz)
for row in reader:
result.append(row)
reader.close()
self.assertTrue(len(result) == self.shape_good[0], 'read_rearrangement(): good data (gzip) failed')

# @unittest.skip('-> repertoire_template(): skipped\n')
def test_repertoire_template(self):
try:
Expand Down

0 comments on commit 11b79c7

Please sign in to comment.