From 9b550d77b275a093cd6256c4bbf333ab4ba719fd Mon Sep 17 00:00:00 2001 From: Jennifer Chang Date: Fri, 21 Jul 2023 14:31:36 -0700 Subject: [PATCH] fixup! [titlecase] Add compatibility with `error_all` --- augur/curate/titlecase.py | 3 ++- tests/functional/curate/cram/titlecase.t | 33 +++++++++++++++++++++++- 2 files changed, 34 insertions(+), 2 deletions(-) diff --git a/augur/curate/titlecase.py b/augur/curate/titlecase.py index c52b5b914..94cbbc7d8 100755 --- a/augur/curate/titlecase.py +++ b/augur/curate/titlecase.py @@ -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}") diff --git a/tests/functional/curate/cram/titlecase.t b/tests/functional/curate/cram/titlecase.t index 7c40c632c..f3fe98fcb 100644 --- a/tests/functional/curate/cram/titlecase.t +++ b/tests/functional/curate/cram/titlecase.t @@ -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"} \ No newline at end of file + {"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} +