@@ -48,51 +48,44 @@ class TestAllScenarios(IntegrationTest):
48
48
pass
49
49
50
50
51
- def check_result (expected_result , result ):
52
- if isinstance (result , Cursor ) or isinstance (result , CommandCursor ):
53
- return list (result ) == expected_result
54
-
55
- elif isinstance (result , _WriteResult ):
51
+ def check_result (self , expected_result , result ):
52
+ if isinstance (result , _WriteResult ):
56
53
for res in expected_result :
57
54
prop = camel_to_snake (res )
55
+ msg = "%s : %r != %r" % (prop , expected_result , result )
58
56
# SPEC-869: Only BulkWriteResult has upserted_count.
59
- if (prop == "upserted_count" and
60
- not isinstance (result , BulkWriteResult )):
57
+ if (prop == "upserted_count"
58
+ and not isinstance (result , BulkWriteResult )):
61
59
if result .upserted_id is not None :
62
60
upserted_count = 1
63
61
else :
64
62
upserted_count = 0
65
- if upserted_count != expected_result [res ]:
66
- return False
63
+ self .assertEqual (upserted_count , expected_result [res ], msg )
67
64
elif prop == "inserted_ids" :
68
65
# BulkWriteResult does not have inserted_ids.
69
66
if isinstance (result , BulkWriteResult ):
70
- if len (expected_result [res ]) != result . inserted_count :
71
- return False
67
+ self . assertEqual ( len (expected_result [res ]),
68
+ result . inserted_count )
72
69
else :
73
70
# InsertManyResult may be compared to [id1] from the
74
71
# crud spec or {"0": id1} from the retryable write spec.
75
72
ids = expected_result [res ]
76
73
if isinstance (ids , dict ):
77
74
ids = [ids [str (i )] for i in range (len (ids ))]
78
- if ids != result .inserted_ids :
79
- return False
75
+ self .assertEqual (ids , result .inserted_ids , msg )
80
76
elif prop == "upserted_ids" :
81
77
# Convert indexes from strings to integers.
82
78
ids = expected_result [res ]
83
79
expected_ids = {}
84
80
for str_index in ids :
85
81
expected_ids [int (str_index )] = ids [str_index ]
86
- if expected_ids != result .upserted_ids :
87
- return False
88
- elif getattr ( result , prop ) != expected_result [ res ]:
89
- return False
90
- return True
82
+ self . assertEqual ( expected_ids , result .upserted_ids , msg )
83
+ else :
84
+ self . assertEqual (
85
+ getattr ( result , prop ), expected_result [ res ], msg )
86
+
91
87
else :
92
- if expected_result is None :
93
- return result is None
94
- else :
95
- return result == expected_result
88
+ self .assertEqual (result , expected_result )
96
89
97
90
98
91
def run_operation (collection , test ):
@@ -138,7 +131,11 @@ def run_operation(collection, test):
138
131
if operation == "aggregate" :
139
132
if arguments ["pipeline" ] and "$out" in arguments ["pipeline" ][- 1 ]:
140
133
out = collection .database [arguments ["pipeline" ][- 1 ]["$out" ]]
141
- return out .find ()
134
+ result = out .find ()
135
+
136
+ if isinstance (result , Cursor ) or isinstance (result , CommandCursor ):
137
+ return list (result )
138
+
142
139
return result
143
140
144
141
@@ -160,7 +157,7 @@ def run_scenario(self):
160
157
run_operation (self .db .test , test )
161
158
else :
162
159
result = run_operation (self .db .test , test )
163
- self . assertTrue ( check_result (expected_result , result ) )
160
+ check_result (self , expected_result , result )
164
161
165
162
# Assert final state is expected.
166
163
expected_c = test ['outcome' ].get ('collection' )
0 commit comments