Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Adds test for better fgoxide header error and bump fgoxide version. #43

Open
wants to merge 2 commits into
base: main
Choose a base branch
from
Open
Show file tree
Hide file tree
Changes from 1 commit
Commits
File filter

Filter by extension

Filter by extension


Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
6 changes: 3 additions & 3 deletions Cargo.lock

Some generated files are not rendered by default. Learn more about how customized files appear on GitHub.

4 changes: 3 additions & 1 deletion Cargo.toml
Original file line number Diff line number Diff line change
Expand Up @@ -36,7 +36,9 @@ bstr = "1.0.1"
clap = { version = "4.0.25", features = ["derive"] }
enum_dispatch = "0.3.8"
env_logger = "0.9.3"
fgoxide = "0.3.0"
# TODO: change this when 0.3.1 is released with header validation.
Copy link
Member Author

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

NB: fix and squash the commit after PR is merged in fgoxide.

# fgoxide = "0.3.1"
fgoxide = { git = "https://github.com/fulcrumgenomics/fgoxide.git", branch = "jf/validate-header" }
flate2 = { version = "1.0.25", features = ["zlib-ng"] } # Force the faster backend that requires a C compiler
itertools = "0.10.5"
log = "0.4.17"
Expand Down
43 changes: 30 additions & 13 deletions src/lib/samples.rs
Copy link
Member Author

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Adds tests to catch the new fgoxide header error Error.

Original file line number Diff line number Diff line change
Expand Up @@ -151,11 +151,7 @@ mod tests {
use core::panic;

use super::*;
use csv::DeserializeErrorKind as CsvDeserializeErrorEnum;
use csv::ErrorKind as CsvErrorEnum;
use fgoxide::{self, io::Io};
use serde::de::value::Error as SerdeError;
use serde::de::Error;
use tempfile::TempDir;

// ############################################################################################
Expand All @@ -181,6 +177,29 @@ mod tests {
assert!(samples_metadata.samples[1].barcode == "CATGCTA");
}

#[test]
fn test_tsv_file_delim_error() {
let lines = vec![
theJasonFan marked this conversation as resolved.
Show resolved Hide resolved
// Sample::deserialize_header_line(),
"sample_id,barcode".to_owned(),
"sample1,GATTACA".to_owned(),
"sample2,CATGCTA".to_owned(),
];
let tempdir = TempDir::new().unwrap();
let f1 = tempdir.path().join("sample_metadata.tsv");

let io = Io::default();
io.write_lines(&f1, &lines).unwrap();
let err = SampleGroup::from_file(&f1).unwrap_err();

if let fgoxide::FgError::DelimFileHeaderError { expected, found } = err {
assert_eq!(expected, Sample::deserialize_header_line());
assert_eq!(found, "sample_id,barcode");
} else {
panic!()
}
}

#[test]
fn test_reading_from_file_with_empty_lines_at_end() {
let lines = vec![
Expand Down Expand Up @@ -222,16 +241,14 @@ mod tests {

let io = Io::default();
io.write_lines(&f1, &lines).unwrap();
let mut to_panic = true;
if let fgoxide::FgError::ConversionError(csv_e) = SampleGroup::from_file(&f1).unwrap_err() {
if let CsvErrorEnum::Deserialize { pos: _, err: csv_de_err } = csv_e.into_kind() {
if let CsvDeserializeErrorEnum::Message(s) = csv_de_err.kind() {
to_panic = false;
assert_eq!(s, &SerdeError::missing_field("sample_id").to_string());
}
}
if let fgoxide::FgError::DelimFileHeaderError { expected, found } =
SampleGroup::from_file(&f1).unwrap_err()
{
assert_eq!(expected, Sample::deserialize_header_line());
assert_eq!(found, "sample1\tGATTACA");
} else {
panic!("Different error type than expected reading from headerless file.")
}
assert!(!to_panic, "Different error type than expected reading from headerless file.");
}

#[test]
Expand Down
Loading