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

Feature/check warnings #139

Merged
merged 2 commits into from
Sep 15, 2023
Merged
Show file tree
Hide file tree
Changes from all commits
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
1 change: 1 addition & 0 deletions CHANGELOG.md
Original file line number Diff line number Diff line change
Expand Up @@ -9,6 +9,7 @@ and this project adheres to [Semantic Versioning](https://semver.org/spec/v2.0.0

- a separator for joining node values in `link` can be set with attribute `value_sep`
- spreadsheet imports can now be configured with a fallback token column for annotation names not mentioned in a column map, an empty string means map to timeline directly
- graph_op `check` can now be configured to not let the entire processing chain fail, when a test fails, by setting `policy = "warn"` (default is `fail`)

### Fixed

Expand Down
61 changes: 60 additions & 1 deletion src/manipulator/check.rs
Original file line number Diff line number Diff line change
Expand Up @@ -21,6 +21,16 @@
pub struct Check {
tests: Vec<Test>,
report: Option<ReportLevel>,
#[serde(default)]
policy: FailurePolicy,
}

#[derive(Default, Deserialize)]
#[serde(rename_all = "snake_case")]
enum FailurePolicy {
Warn,
#[default]
Fail,
}

#[derive(Deserialize)]
Expand Down Expand Up @@ -53,10 +63,18 @@
.map(|(d, _)| d)
.collect_vec();
if !failed_checks.is_empty() {
let msg = StatusMessage::Failed(AnnattoError::ChecksFailed { failed_checks });
let msg = match self.policy {
FailurePolicy::Warn => StatusMessage::Warning(format!(
"One or more checks failed:\n{}",
failed_checks.join("\n")
)),
FailurePolicy::Fail => {
StatusMessage::Failed(AnnattoError::ChecksFailed { failed_checks })
}
};
if let Some(ref sender) = tx {
sender.send(msg)?;
}

Check warning on line 77 in src/manipulator/check.rs

View workflow job for this annotation

GitHub Actions / Execute tests with code coverage

77 line is not covered with tests
}
Ok(())
}
Expand Down Expand Up @@ -152,8 +170,8 @@
if upper.is_infinite() || upper.is_nan() {
n.ge(lower)
} else {
let u = upper.abs().ceil() as usize;
n.ge(lower) && u.gt(&n)

Check warning on line 174 in src/manipulator/check.rs

View workflow job for this annotation

GitHub Actions / Execute tests with code coverage

173-174 lines are not covered with tests
}
}
};
Expand Down Expand Up @@ -464,8 +482,8 @@
.iter()
.all(|(_, tr)| matches!(tr, TestResult::Passed));
if !all_pass {
let table_string = Check::results_to_table(&results, &ReportLevel::Verbose);
println!("{}", table_string);

Check warning on line 486 in src/manipulator/check.rs

View workflow job for this annotation

GitHub Actions / Execute tests with code coverage

485-486 lines are not covered with tests
}
assert!(all_pass);
Ok(())
Expand All @@ -486,13 +504,54 @@
.filter(|(_, tr)| matches!(tr, TestResult::Passed))
.count();
if passing != failing {
let table_string = Check::results_to_table(&results, &ReportLevel::Verbose);
println!("{}", table_string);

Check warning on line 508 in src/manipulator/check.rs

View workflow job for this annotation

GitHub Actions / Execute tests with code coverage

507-508 lines are not covered with tests
}
assert_eq!(passing, failing);
Ok(())
}

#[test]
fn test_layer_check_fail_policy_warn() {
let gr = input_graph(false);
assert!(gr.is_ok());
let mut g = gr.unwrap();
let toml_path = "./tests/data/graph_op/check/serialized_layer_check_failing_warn.toml";
if let Ok(s) = fs::read_to_string(toml_path) {
let processor_opt: Result<Check, _> = toml::from_str(s.as_str());
assert!(processor_opt.is_ok());
let check = processor_opt.unwrap();
let (sender, receiver) = mpsc::channel();
let dummy_value = temp_dir();
let run = check.manipulate_corpus(&mut g, dummy_value.as_path(), Some(sender));
assert!(run.is_ok());
assert_eq!(
receiver
.into_iter()
.filter(|msg| matches!(msg, StatusMessage::Warning { .. }))
.count(),
1
);
}

Check warning on line 535 in src/manipulator/check.rs

View workflow job for this annotation

GitHub Actions / Execute tests with code coverage

535 line is not covered with tests
let toml_path_fail = "./tests/data/graph_op/check/serialized_layer_check_failing.toml";
if let Ok(s) = fs::read_to_string(toml_path_fail) {
let processor_opt: Result<Check, _> = toml::from_str(s.as_str());
assert!(processor_opt.is_ok());
let check = processor_opt.unwrap();
let (sender, receiver) = mpsc::channel();
let dummy_value = temp_dir();
let run = check.manipulate_corpus(&mut g, dummy_value.as_path(), Some(sender));
assert!(run.is_ok());
assert_eq!(
receiver
.into_iter()
.filter(|msg| matches!(msg, StatusMessage::Failed { .. }))
.count(),
1
);
}

Check warning on line 552 in src/manipulator/check.rs

View workflow job for this annotation

GitHub Actions / Execute tests with code coverage

552 line is not covered with tests
}

#[test]
fn test_layer_test_to_aql_test() {
let mut layers = BTreeMap::new();
Expand Down
15 changes: 15 additions & 0 deletions tests/data/graph_op/check/serialized_layer_check_failing_warn.toml
Original file line number Diff line number Diff line change
@@ -0,0 +1,15 @@
# please note: This is NOT a workflow fragment, this is a serialization of `check`.
# In an annatto workflow the structure will vary due to flattenings and re-arrangments of data.
report = "list"
policy = "warn"

[[tests]]
layers = { pos = [ "PRON" ], cat = [ "NP" ] }

[[tests]]
layers = { deprel = ["subj"] }
edge = "->dep"

[[tests]]
layers = { func = ["D0"] }
edge = ">"
Loading