From 89ab51f3556ac5981a699181131155c560363757 Mon Sep 17 00:00:00 2001 From: Tessa Pierce Ward Date: Thu, 7 Mar 2024 12:52:15 -0800 Subject: [PATCH] index should error out if no sigs to index (#267) --- src/index.rs | 7 +++++++ src/python/tests/test_index.py | 25 +++++++++++++++++++++++-- 2 files changed, 30 insertions(+), 2 deletions(-) diff --git a/src/index.rs b/src/index.rs index 3747e6f5..3b2aa4a5 100644 --- a/src/index.rs +++ b/src/index.rs @@ -20,6 +20,13 @@ pub fn index>( allow_failed_sigpaths, )?; + if collection.len() == 0 { + bail!( + "No sketches matching parameters, check input: '{}'", + &siglist + ) + } + RevIndex::create( output.as_ref(), collection.select(selection)?.try_into()?, diff --git a/src/python/tests/test_index.py b/src/python/tests/test_index.py index 7fc7b131..f490d2aa 100644 --- a/src/python/tests/test_index.py +++ b/src/python/tests/test_index.py @@ -161,11 +161,31 @@ def test_index_empty_siglist(runtmp, capfd): assert "Error: Signatures failed to load. Exiting." in captured.err -def test_index_nomatch_sig_in_siglist(runtmp, capfd): +def test_index_nomatch(runtmp, capfd): # test index with a siglist file that has (only) a non-matching ksize sig siglist = runtmp.output('against.txt') db = runtmp.output('db.rdb') + sig1 = get_test_data('1.fa.k21.sig.gz') + make_file_list(siglist, [sig1]) + + with pytest.raises(utils.SourmashCommandFailed): + runtmp.sourmash('scripts', 'index', siglist, + '-o', db) + + captured = capfd.readouterr() + print(runtmp.last_result.out) + print(runtmp.last_result.err) + print(captured.out) + print(captured.err) + assert not os.path.exists(db) + + +def test_index_nomatch_sig_in_siglist(runtmp, capfd): + # test index with a siglist file that has both matching and non-matching sigs + siglist = runtmp.output('against.txt') + db = runtmp.output('db.rdb') + sig2 = get_test_data('2.fa.sig.gz') sig1 = get_test_data('1.fa.k21.sig.gz') make_file_list(siglist, [sig2, sig1]) @@ -174,10 +194,11 @@ def test_index_nomatch_sig_in_siglist(runtmp, capfd): '-o', db) captured = capfd.readouterr() - assert os.path.exists(db) # currently empty file print(runtmp.last_result.out) print(runtmp.last_result.err) + print(captured.out) print(captured.err) + assert os.path.exists(db) def test_index_zipfile(runtmp, capfd):