From 57bdf28f456ea3cd2669294596f90cd4e89018fc Mon Sep 17 00:00:00 2001 From: John Huddleston Date: Tue, 19 Sep 2023 09:39:26 -0700 Subject: [PATCH] Optionally ignore numeric type changes Adds a flag to the diff JSONs script to ignore numeric type changes when running DeepDiff [1]. Updates the export v2 minimal export test to use this new flag instead of creating an intermediate file with sed. [1] https://zepworks.com/deepdiff/current/ignore_types_or_values.html --- scripts/diff_jsons.py | 2 ++ tests/functional/export_v2/cram/minimal.t | 6 ++---- 2 files changed, 4 insertions(+), 4 deletions(-) diff --git a/scripts/diff_jsons.py b/scripts/diff_jsons.py index ece69de4d..ce215e855 100644 --- a/scripts/diff_jsons.py +++ b/scripts/diff_jsons.py @@ -15,6 +15,7 @@ parser.add_argument("--significant-digits", type=int, default=5, help="number of significant digits to use when comparing numeric values") parser.add_argument("--exclude-paths", nargs="+", help="list of paths to exclude from consideration when performing a diff", default=["root['generated_by']['version']"]) parser.add_argument("--exclude-regex-paths", nargs="+", help="list of path regular expressions to exclude from consideration when performing a diff") + parser.add_argument("--ignore-numeric-type-changes", action="store_true", help="ignore numeric type changes in the diff (e.g., int of 1 to float of 1.0)") args = parser.parse_args() @@ -31,5 +32,6 @@ significant_digits=args.significant_digits, exclude_paths=args.exclude_paths, exclude_regex_paths=args.exclude_regex_paths, + ignore_numeric_type_changes=args.ignore_numeric_type_changes, ) ) diff --git a/tests/functional/export_v2/cram/minimal.t b/tests/functional/export_v2/cram/minimal.t index a423a393a..9fd1c1eda 100644 --- a/tests/functional/export_v2/cram/minimal.t +++ b/tests/functional/export_v2/cram/minimal.t @@ -16,12 +16,10 @@ Minimal export -- single input (tree) and single output (dataset JSON) The above minimal.json takes divergence from the newick file. This converts newick divergences of (e.g.) '1' to `1.0` -because BioPython uses floats (which is perfectly reasonable). Remove the decimal to diff the JSON. +because BioPython uses floats (which is perfectly reasonable). Ignore this type change in the JSON diff. (Note that Auspice won't behave any differently) - $ sed 's/\.0//' minimal.json > minimal.no-decimal.json - - $ python3 "$TESTDIR/../../../../scripts/diff_jsons.py" "$TESTDIR/../data/minimal.json" minimal.no-decimal.json \ + $ python3 "$TESTDIR/../../../../scripts/diff_jsons.py" --ignore-numeric-type-changes "$TESTDIR/../data/minimal.json" minimal.json \ > --exclude-paths "root['meta']['updated']" {}