Skip to content

Commit

Permalink
Merge pull request #139 from korpling/feature/check-warnings
Browse files Browse the repository at this point in the history
Feature/check warnings
  • Loading branch information
MartinKl authored Sep 15, 2023
2 parents 052d059 + a5ff81a commit 574a4fb
Show file tree
Hide file tree
Showing 3 changed files with 76 additions and 1 deletion.
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 const MODULE_NAME: &str = "check";
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,7 +63,15 @@ impl Manipulator for Check {
.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)?;
}
Expand Down Expand Up @@ -493,6 +511,47 @@ mod tests {
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
);
}
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
);
}
}

#[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 = ">"

0 comments on commit 574a4fb

Please sign in to comment.