Skip to content

Commit b628fcb

Browse files
committed
Fully compare write results in check_result.
1 parent e42897e commit b628fcb

File tree

1 file changed

+12
-8
lines changed

1 file changed

+12
-8
lines changed

test/test_crud.py

Lines changed: 12 additions & 8 deletions
Original file line numberDiff line numberDiff line change
@@ -73,20 +73,24 @@ def check_result(expected_result, result):
7373
elif prop == "inserted_ids":
7474
# BulkWriteResult does not have inserted_ids.
7575
if isinstance(result, BulkWriteResult):
76-
return len(expected_result[res]) == result.inserted_count
77-
# InsertManyResult may be compared to [id1] from the
78-
# crud spec or {"0": id1} from the retryable write spec.
79-
ids = expected_result[res]
80-
if isinstance(ids, dict):
81-
ids = [ids[str(i)] for i in range(len(ids))]
82-
return ids == result.inserted_ids
76+
if len(expected_result[res]) != result.inserted_count:
77+
return False
78+
else:
79+
# InsertManyResult may be compared to [id1] from the
80+
# crud spec or {"0": id1} from the retryable write spec.
81+
ids = expected_result[res]
82+
if isinstance(ids, dict):
83+
ids = [ids[str(i)] for i in range(len(ids))]
84+
if ids != result.inserted_ids:
85+
return False
8386
elif prop == "upserted_ids":
8487
# Convert indexes from strings to integers.
8588
ids = expected_result[res]
8689
expected_ids = {}
8790
for str_index in ids:
8891
expected_ids[int(str_index)] = ids[str_index]
89-
return expected_ids == result.upserted_ids
92+
if expected_ids != result.upserted_ids:
93+
return False
9094
elif getattr(result, prop) != expected_result[res]:
9195
return False
9296
return True

0 commit comments

Comments
 (0)