Skip to content

Commit

Permalink
Fix DeepDiff in tests when OVERWRITE_TEST_EXPECTED_DATA is set
Browse files Browse the repository at this point in the history
Make sure we overwrite expected test results only when there's a
meaningful diff.
  • Loading branch information
mihaitodor committed Apr 4, 2024
1 parent cd6e631 commit 054ab29
Showing 1 changed file with 10 additions and 8 deletions.
18 changes: 10 additions & 8 deletions tests/utilities.py
Original file line number Diff line number Diff line change
@@ -1,6 +1,7 @@
import json
import os
import deepdiff

from deepdiff import DeepDiff

FIND_SUBJECT_VARIANTS_URL = "/subject-operations/genotype-operations/$find-subject-variants"
FIND_SUBJECT_VARIANTS_OUTPUT_DIR = "tests/expected_outputs/find_subject_variants/"
Expand Down Expand Up @@ -123,12 +124,13 @@ def find_the_gene_query(query):


def compare_actual_and_expected_output(filename, actual_json):
if 'OVERWRITE_TEST_EXPECTED_DATA' in os.environ:
with open(filename, 'w') as expected_output_file:
json.dump(actual_json, expected_output_file, indent=4)
return

with open(filename) as expected_output_file:
expected_json = json.load(expected_output_file)
diff = deepdiff.DeepDiff(actual_json, expected_json, ignore_order=True)
assert diff == {}
diff = DeepDiff(actual_json, expected_json, ignore_order=True)

if diff != {}:
if 'OVERWRITE_TEST_EXPECTED_DATA' in os.environ:
with open(filename, 'w') as expected_output_file:
json.dump(actual_json, expected_output_file, indent=4)
else:
assert diff == {}

0 comments on commit 054ab29

Please sign in to comment.