Skip to content

Commit

Permalink
MRG: avoid compressing sig files in directory output twice (#2752)
Browse files Browse the repository at this point in the history
Fixes #2751
  • Loading branch information
ctb authored Sep 7, 2023
1 parent 038a37b commit d4a1b45
Show file tree
Hide file tree
Showing 2 changed files with 25 additions and 1 deletion.
2 changes: 1 addition & 1 deletion src/sourmash/save_load.py
Original file line number Diff line number Diff line change
Expand Up @@ -348,7 +348,7 @@ def add(self, ss):
break
i += 1

with gzip.open(outname, "wb") as fp:
with open(outname, "wb") as fp:
sigmod.save_signatures([ss], fp, compression=1)


Expand Down
24 changes: 24 additions & 0 deletions tests/test_sourmash_args.py
Original file line number Diff line number Diff line change
Expand Up @@ -11,6 +11,7 @@
import csv
import argparse
import shutil
import json

import sourmash_tst_utils as utils
import sourmash
Expand Down Expand Up @@ -363,6 +364,29 @@ def test_save_signatures_to_location_1_dirout(runtmp):
assert len(saved) == 2


def test_save_signatures_to_location_1_dirout_bug_2751(runtmp):
# check for 2x compressed sig files
sig2 = utils.get_test_data('2.fa.sig')
ss2 = sourmash.load_one_signature(sig2, ksize=31)
sig47 = utils.get_test_data('47.fa.sig')
ss47 = sourmash.load_one_signature(sig47, ksize=31)

outloc = runtmp.output('sigout/')
with sourmash_args.SaveSignaturesToLocation(outloc) as save_sig:
print(save_sig)
save_sig.add(ss2)
save_sig.add(ss47)

assert os.path.isdir(outloc)
print(os.listdir(outloc))

outloc2 = runtmp.output('sigout/09a08691ce52952152f0e866a59f6261.sig.gz')
with gzip.open(outloc2, "r") as fp:
data = fp.read()
print(data)
_ = json.loads(data)


def test_save_signatures_to_location_1_dirout_duplicate(runtmp):
# save to sigout/ (directory)
sig2 = utils.get_test_data('2.fa.sig')
Expand Down

0 comments on commit d4a1b45

Please sign in to comment.