Skip to content

Commit

Permalink
fix SBT subdir loading error (#1893)
Browse files Browse the repository at this point in the history
  • Loading branch information
ctb committed Mar 25, 2022
1 parent f54f60f commit 03f2fae
Show file tree
Hide file tree
Showing 2 changed files with 18 additions and 2 deletions.
8 changes: 6 additions & 2 deletions src/sourmash/sbt.py
Original file line number Diff line number Diff line change
Expand Up @@ -831,8 +831,12 @@ def load(cls, location, *, leaf_loader=None, storage=None, print_version_warning
sbt_fn = os.path.join(dirname, sbt_name)
if not sbt_fn.endswith('.sbt.json') and tempfile is None:
sbt_fn += '.sbt.json'
with open(sbt_fn) as fp:
jnodes = json.load(fp)

try:
with open(sbt_fn) as fp:
jnodes = json.load(fp)
except NotADirectoryError as exc:
raise ValueError(str(exc))

if tempfile is not None:
tempfile.close()
Expand Down
12 changes: 12 additions & 0 deletions tests/test_sbt.py
Original file line number Diff line number Diff line change
Expand Up @@ -1205,3 +1205,15 @@ def test_build_sbt_json_with_dups_exists(runtmp):
assert len(sbt_sigs) == 4

assert all_sigs == sbt_sigs


def test_load_fail_on_file_not_dir(runtmp):
# make sure the load function raises a ValueError for {filename}/sbt,
# rather than a NotADirectoryError

filename = runtmp.output('foo')
with open(filename, 'wt') as fp:
fp.write('something')

with pytest.raises(ValueError) as exc:
x = SBT.load(runtmp.output('foo/bar.sbt.json'))

0 comments on commit 03f2fae

Please sign in to comment.