2424
2525from test import unittest
2626
27- from bson import CodecOptions
27+ from bson import CodecOptions , encode
2828from pymongo .compression_support import ZlibContext
2929from pymongo .errors import DocumentTooLarge , OperationFailure
3030from pymongo .message import (
@@ -179,10 +179,11 @@ def test_max_doc_size_zero_without_docs(self):
179179 _ , _ , _ , max_doc_size = _op_msg (0 , {"ping" : 1 }, "testdb" , None , _OPTS )
180180 self .assertEqual (max_doc_size , 0 )
181181
182- def test_max_doc_size_nonzero_with_docs (self ):
183- cmd : dict = {"insert" : "col" , "documents" : [{"_id" : 1 , "x" : 2 }, {"_id" : 3 , "x" : 4 }]}
182+ def test_max_doc_size_matches_largest_encoded_doc (self ):
183+ docs = [{"_id" : 1 , "x" : 2 }, {"_id" : 3 , "x" : 4 }]
184+ cmd : dict = {"insert" : "col" , "documents" : docs }
184185 _ , _ , _ , max_doc_size = _op_msg (0 , cmd , "testdb" , None , _OPTS )
185- self .assertGreater (max_doc_size , 0 )
186+ self .assertEqual (max_doc_size , max ( len ( encode ( d )) for d in docs ) )
186187
187188 def test_read_preference_added_for_non_primary (self ):
188189 cmd : dict = {"find" : "col" }
@@ -208,10 +209,6 @@ def test_command_with_documents_field_is_restored(self):
208209
209210
210211class TestQuery (unittest .TestCase ):
211- def test_basic (self ):
212- _ , max_bson_size = _query_impl (0 , "db.col" , 0 , 0 , {"x" : 1 }, None , _OPTS )
213- self .assertGreater (max_bson_size , 0 )
214-
215212 def test_uncompressed_op_code (self ):
216213 _rid , msg , _mbs = _query_uncompressed (0 , "db.col" , 0 , 0 , {}, None , _OPTS )
217214 op_code = struct .unpack ("<i" , msg [12 :16 ])[0 ]
@@ -257,7 +254,7 @@ def test_basic(self):
257254
258255 def test_with_projection (self ):
259256 cmd = _gen_find_command ("col" , {}, {"x" : 1 }, 0 , 0 , None , None , ReadConcern ())
260- self .assertIn ( "projection" , cmd )
257+ self .assertEqual ( cmd [ "projection" ], { "x" : 1 } )
261258
262259 def test_with_skip (self ):
263260 cmd = _gen_find_command ("col" , {}, None , 5 , 0 , None , None , ReadConcern ())
@@ -284,7 +281,7 @@ def test_batch_size_not_adjusted_when_different(self):
284281
285282 def test_read_concern_level_included (self ):
286283 cmd = _gen_find_command ("col" , {}, None , 0 , 0 , None , None , ReadConcern ("majority" ))
287- self .assertIn ( "readConcern" , cmd )
284+ self .assertEqual ( cmd [ "readConcern" ], { "level" : "majority" } )
288285
289286 def test_query_with_dollar_query_modifier (self ):
290287 spec = {"$query" : {"x" : 1 }, "$orderby" : {"x" : 1 }}
0 commit comments