Skip to content

Commit

Permalink
Optionally ignore numeric type changes
Browse files Browse the repository at this point in the history
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
  • Loading branch information
huddlej committed Sep 19, 2023
1 parent 416e2a2 commit 57bdf28
Show file tree
Hide file tree
Showing 2 changed files with 4 additions and 4 deletions.
2 changes: 2 additions & 0 deletions scripts/diff_jsons.py
Original file line number Diff line number Diff line change
Expand Up @@ -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()

Expand All @@ -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,
)
)
6 changes: 2 additions & 4 deletions tests/functional/export_v2/cram/minimal.t
Original file line number Diff line number Diff line change
Expand Up @@ -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']"
{}

Expand Down

0 comments on commit 57bdf28

Please sign in to comment.