Skip to content

Commit 5c1946a

Browse files
committed
upd with test
1 parent 2bae18c commit 5c1946a

File tree

3 files changed

+34
-1
lines changed

3 files changed

+34
-1
lines changed

src/utils/mod.rs

Lines changed: 11 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -124,6 +124,16 @@ pub fn load_gbassembly_info(input_csv: String) -> Result<(Vec<GBAssemblyData>, u
124124
let header = rdr.headers()?;
125125
let expected_header = vec!["accession", "name"];
126126

127+
let header_v: Vec<_> = header.iter().collect();
128+
129+
if header_v[0..2].to_vec() != expected_header {
130+
return Err(anyhow!(
131+
"Invalid column names in CSV file. Columns should be: {:?}, in that order",
132+
expected_header
133+
));
134+
}
135+
136+
/* Not needed for the moment, but leaving the code around ;).
127137
for h in expected_header.iter() {
128138
if !header.iter().any(|e| *h == e) {
129139
return Err(anyhow!(
@@ -133,7 +143,7 @@ pub fn load_gbassembly_info(input_csv: String) -> Result<(Vec<GBAssemblyData>, u
133143
));
134144
}
135145
}
136-
146+
*/
137147
for h in header.iter() {
138148
if !expected_header.iter().any(|e| h == *e) {
139149
eprintln!("WARNING: extra column '{}' in CSV file. Ignoring.", h);
Lines changed: 3 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,3 @@
1+
name,accession
2+
GCA_000961135.2,GCA_000961135.2 Candidatus Aramenus sulfurataquae isolate AZ1-454
3+
GCA_000175535.1,GCA_000175535.1 Chlamydia muridarum MopnTet14 (agent of mouse pneumonitis) strain=MopnTet14

tests/test_gbsketch.py

Lines changed: 20 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -400,6 +400,26 @@ def test_gbsketch_extra_column(runtmp, capfd):
400400
assert "WARNING: extra column 'extra' in CSV file. Ignoring." in captured.err
401401

402402

403+
def test_gbsketch_bad_column_order(runtmp, capfd):
404+
acc_csv = get_test_data('acc-bad-header-order.csv')
405+
406+
output = runtmp.output('simple.zip')
407+
failed = runtmp.output('failed.csv')
408+
ch_fail = runtmp.output('checksum_dl_failed.csv')
409+
410+
with pytest.raises(utils.SourmashCommandFailed):
411+
runtmp.sourmash('scripts', 'gbsketch', acc_csv, '-o', output,
412+
'--failed', failed, '-r', '3', '--checksum-fail', ch_fail,
413+
'--param-str', "dna,k=31,scaled=1000", '-p', "protein,k=10,scaled=200")
414+
415+
assert not os.path.exists(output)
416+
assert not runtmp.last_result.out # stdout should be empty
417+
captured = capfd.readouterr()
418+
print(captured.err)
419+
420+
assert "Invalid column names in CSV file." in captured.err
421+
422+
403423
def test_gbsketch_missing_accfile(runtmp, capfd):
404424
acc_csv = runtmp.output('acc1.csv')
405425
output = runtmp.output('simple.zip')

0 commit comments

Comments
 (0)