File tree Expand file tree Collapse file tree 2 files changed +27
-2
lines changed Expand file tree Collapse file tree 2 files changed +27
-2
lines changed Original file line number Diff line number Diff line change @@ -546,3 +546,21 @@ def create_predictions(
546
546
]
547
547
dataset .upload_predictions (model , predictions )
548
548
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 } "
Original file line number Diff line number Diff line change 27
27
assert_box_annotation_matches_dict ,
28
28
assert_category_annotation_matches_dict ,
29
29
assert_multicategory_annotation_matches_dict ,
30
+ assert_partial_equality ,
30
31
assert_polygon_annotation_matches_dict ,
31
32
assert_segmentation_annotation_matches_dict ,
32
33
reference_id_from_url ,
@@ -743,8 +744,9 @@ def test_default_category_gt_upload_async(dataset):
743
744
asynchronous = True ,
744
745
)
745
746
job .sleep_until_complete ()
747
+ result = job .status ()
746
748
747
- assert job . status () = = {
749
+ expected = {
748
750
"job_id" : job .job_id ,
749
751
"status" : "Completed" ,
750
752
"message" : {
@@ -761,6 +763,7 @@ def test_default_category_gt_upload_async(dataset):
761
763
"completed_steps" : 1 ,
762
764
"total_steps" : 1 ,
763
765
}
766
+ assert_partial_equality (expected , result )
764
767
765
768
766
769
@pytest .mark .integration
@@ -781,7 +784,9 @@ def test_non_existent_taxonomy_category_gt_upload_async(dataset):
781
784
except JobError :
782
785
assert error_msg in job .errors ()[- 1 ]
783
786
784
- assert job .status () == {
787
+ result = job .status ()
788
+
789
+ expected = {
785
790
"job_id" : job .job_id ,
786
791
"status" : "Errored" ,
787
792
"message" : {
@@ -791,3 +796,5 @@ def test_non_existent_taxonomy_category_gt_upload_async(dataset):
791
796
"completed_steps" : 1 ,
792
797
"total_steps" : 1 ,
793
798
}
799
+
800
+ assert_partial_equality (expected , result )
You can’t perform that action at this time.
0 commit comments