Skip to content

Commit 09cf1c9

Browse files
ardilaUbuntu
andauthored
Only check for partial equality (#238)
* Only check for partial equality * comment Co-authored-by: Ubuntu <diego.ardila@scale.com>
1 parent a12ae66 commit 09cf1c9

File tree

2 files changed

+27
-2
lines changed

2 files changed

+27
-2
lines changed

tests/helpers.py

Lines changed: 18 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -546,3 +546,21 @@ def create_predictions(
546546
]
547547
dataset.upload_predictions(model, predictions)
548548
return predictions
549+
550+
551+
def assert_partial_equality(expected, result, base_keys=[]):
552+
"""Used to check partial equality of two json-like dictionaries.
553+
554+
This means that all the keys/values in the expected dict must be present in the result dict,
555+
but the result dict may contain additional keys.
556+
"""
557+
for key, value in expected.items():
558+
# If value is a dict, recurse.
559+
keys = base_keys + [key]
560+
if isinstance(value, dict):
561+
assert_partial_equality(value, result[key], keys)
562+
else:
563+
address = ".".join(keys)
564+
assert (
565+
result[key] == value
566+
), f"{address} is not equal: {result[key]} != {value}"

tests/test_annotation.py

Lines changed: 9 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -27,6 +27,7 @@
2727
assert_box_annotation_matches_dict,
2828
assert_category_annotation_matches_dict,
2929
assert_multicategory_annotation_matches_dict,
30+
assert_partial_equality,
3031
assert_polygon_annotation_matches_dict,
3132
assert_segmentation_annotation_matches_dict,
3233
reference_id_from_url,
@@ -743,8 +744,9 @@ def test_default_category_gt_upload_async(dataset):
743744
asynchronous=True,
744745
)
745746
job.sleep_until_complete()
747+
result = job.status()
746748

747-
assert job.status() == {
749+
expected = {
748750
"job_id": job.job_id,
749751
"status": "Completed",
750752
"message": {
@@ -761,6 +763,7 @@ def test_default_category_gt_upload_async(dataset):
761763
"completed_steps": 1,
762764
"total_steps": 1,
763765
}
766+
assert_partial_equality(expected, result)
764767

765768

766769
@pytest.mark.integration
@@ -781,7 +784,9 @@ def test_non_existent_taxonomy_category_gt_upload_async(dataset):
781784
except JobError:
782785
assert error_msg in job.errors()[-1]
783786

784-
assert job.status() == {
787+
result = job.status()
788+
789+
expected = {
785790
"job_id": job.job_id,
786791
"status": "Errored",
787792
"message": {
@@ -791,3 +796,5 @@ def test_non_existent_taxonomy_category_gt_upload_async(dataset):
791796
"completed_steps": 1,
792797
"total_steps": 1,
793798
}
799+
800+
assert_partial_equality(expected, result)

0 commit comments

Comments
 (0)