Skip to content

Commit

Permalink
fixup! [titlecase] Add compatibility with error_all
Browse files Browse the repository at this point in the history
  • Loading branch information
j23414 committed Jul 21, 2023
1 parent 85bf84b commit 9b550d7
Show file tree
Hide file tree
Showing 2 changed files with 34 additions and 2 deletions.
3 changes: 2 additions & 1 deletion augur/curate/titlecase.py
Original file line number Diff line number Diff line change
Expand Up @@ -102,7 +102,8 @@ def run(args, records):
if titlecased_string is None:
if failure_reporting is DataErrorMethod.ERROR_FIRST:
raise AugurError(failure_message)

if failure_reporting is DataErrorMethod.ERROR_ALL:
print_err(f"ERROR: {failure_message}")
if failure_reporting is DataErrorMethod.WARN:
print_err(f"WARNING: {failure_message}")

Expand Down
33 changes: 32 additions & 1 deletion tests/functional/curate/cram/titlecase.t
Original file line number Diff line number Diff line change
Expand Up @@ -65,4 +65,35 @@ Test cases when fields do not exist, decide if this should error out and may aff

$ echo '{"region":"europe", "country":"france" }' \
> | ${AUGUR} curate titlecase --titlecase-fields "region" "country" "division" "location" "not exist"
{"region": "Europe", "country": "France"}
{"region": "Europe", "country": "France"}

Test output with non-string value input with `ERROR_ALL` failure reporting.
This reports a collection of all titlecase failures which is especially beneficial for automated pipelines.

$ echo '{"bare_int": 2021, "bare_float": 1.2}' \
> | ${AUGUR} curate titlecase --titlecase-fields "bare_int" "bare_float" \
> --failure-reporting "error_all" 1> /dev/null
ERROR: Failed to titlecase 'bare_int':2021 in record 0 because the value is a 'int' and is not a string.
ERROR: Failed to titlecase 'bare_float':1.2 in record 0 because the value is a 'float' and is not a string.
ERROR: Unable to change to titlecase for the following (record, field, field value):
(0, 'bare_int', 2021)
(0, 'bare_float', 1.2)
[2]

Test warning on failures such as when encountering a non-string value.

$ echo '{"bare_int": 2021}' \
> | ${AUGUR} curate titlecase --titlecase-fields "bare_int" \
> --failure-reporting "warn"
WARNING: Failed to titlecase 'bare_int':2021 in record 0 because the value is a 'int' and is not a string.
WARNING: Unable to change to titlecase for the following (record, field, field value):
(0, 'bare_int', 2021)
{"bare_int": 2021}

Test silencing on failures such as when encountering a non-string value

$ echo '{"bare_int": 2021}' \
> | ${AUGUR} curate titlecase --titlecase-fields "bare_int" \
> --failure-reporting "silent"
{"bare_int": 2021}

0 comments on commit 9b550d7

Please sign in to comment.