From c006ebbc1c358cd5b2460befcd943b96720d0d14 Mon Sep 17 00:00:00 2001 From: "C. Titus Brown" Date: Wed, 23 Aug 2023 11:31:15 -0700 Subject: [PATCH 1/2] update version in cargo.lock --- Cargo.lock | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-) diff --git a/Cargo.lock b/Cargo.lock index 039ec58c..9544b1df 100644 --- a/Cargo.lock +++ b/Cargo.lock @@ -764,7 +764,7 @@ dependencies = [ [[package]] name = "pyo3-branchwater" -version = "0.5.0" +version = "0.5.1" dependencies = [ "anyhow", "assert_cmd", From 6895b8ee1c0c7a11bca06d69105db413d6004f99 Mon Sep 17 00:00:00 2001 From: "C. Titus Brown" Date: Wed, 23 Aug 2023 12:09:22 -0700 Subject: [PATCH 2/2] add test for empty file & display loading error --- src/lib.rs | 47 ++++++++++++++++++--------------- src/python/tests/test_gather.py | 28 ++++++++++++++++++++ 2 files changed, 54 insertions(+), 21 deletions(-) diff --git a/src/lib.rs b/src/lib.rs index 12095142..d4ce2485 100644 --- a/src/lib.rs +++ b/src/lib.rs @@ -450,33 +450,38 @@ fn load_sketches_above_threshold( .filter_map(|m| { let sigs = Signature::from_path(m); - let mut mm = None; - if let Ok(sigs) = sigs { - for sig in &sigs { - if let Some(mh) = prepare_query(sig, template) { - if let Ok(overlap) = mh.count_common(query, false) { - if overlap >= threshold_hashes { - let result = PrefetchResult { - name: sig.name(), - minhash: mh, - overlap, - }; - mm = Some(result); - break; + match sigs { + Ok(sigs) => { + let mut mm = None; + for sig in &sigs { + if let Some(mh) = prepare_query(sig, template) { + if let Ok(overlap) = mh.count_common(query, false) { + if overlap >= threshold_hashes { + let result = PrefetchResult { + name: sig.name(), + minhash: mh, + overlap, + }; + mm = Some(result); + break; + } } + } else { + eprintln!("WARNING: no compatible sketches in path '{}'", + m.display()); + let _i = skipped_paths.fetch_add(1, atomic::Ordering::SeqCst); } - } else { - eprintln!("WARNING: no compatible sketches in path '{}'", - m.display()); - let _i = skipped_paths.fetch_add(1, atomic::Ordering::SeqCst); } + mm } - } else { - let _ = failed_paths.fetch_add(1, atomic::Ordering::SeqCst); - eprintln!("WARNING: could not load sketches from path '{}'", + Err(err) => { + eprintln!("Sketch loading error: {}", err); + let _ = failed_paths.fetch_add(1, atomic::Ordering::SeqCst); + eprintln!("WARNING: could not load sketches from path '{}'", m.display()); + None + } } - mm }) .collect(); diff --git a/src/python/tests/test_gather.py b/src/python/tests/test_gather.py index 1d1e2f19..ae4d7195 100644 --- a/src/python/tests/test_gather.py +++ b/src/python/tests/test_gather.py @@ -199,6 +199,34 @@ def test_bad_against_2(runtmp, capfd): assert "WARNING: 1 signature paths failed to load. See error messages above." in captured.err +def test_bad_against_3(runtmp, capfd): + # test bad 'against' file - in this case, one containing an empty file + query = get_test_data('SRR606249.sig.gz') + against_list = runtmp.output('against.txt') + + sig2 = get_test_data('2.fa.sig.gz') + empty_file = runtmp.output('empty.sig') + with open(empty_file, 'wb') as fp: + pass + make_file_list(against_list, [sig2, empty_file]) + + + g_output = runtmp.output('gather.csv') + p_output = runtmp.output('prefetch.csv') + + runtmp.sourmash('scripts', 'fastgather', query, against_list, + '-o', g_output, '--output-prefetch', p_output, + '-s', '100000') + + captured = capfd.readouterr() + print(captured.err) + + assert "Sketch loading error: File is too short, less than five bytes" in captured.err + assert "WARNING: could not load sketches from path" in captured.err + + assert "WARNING: 1 signature paths failed to load. See error messages above." in captured.err + + def test_against_multisigfile(runtmp): # test against a sigfile that contains multiple sketches query = get_test_data('SRR606249.sig.gz')