@@ -52,8 +52,7 @@ def test_explain(self):
5252 def test_hint (self ):
5353 db = self .db
5454 self .assertRaises (TypeError , db .test .find ().hint , 5.5 )
55- db .test .remove ({})
56- db .test .drop_indexes ()
55+ db .test .drop ()
5756
5857 for i in range (100 ):
5958 db .test .insert ({"num" : i , "foo" : i })
@@ -94,7 +93,7 @@ def test_limit(self):
9493 self .assertRaises (TypeError , db .test .find ().limit , "hello" )
9594 self .assertRaises (TypeError , db .test .find ().limit , 5.5 )
9695
97- db .test .remove ({} )
96+ db .test .drop ( )
9897 for i in range (100 ):
9998 db .test .save ({"x" : i })
10099
@@ -134,6 +133,50 @@ def test_limit(self):
134133 break
135134 self .assertRaises (InvalidOperation , a .limit , 5 )
136135
136+
137+ def test_batch_size (self ):
138+ db = self .db
139+ db .test .drop ()
140+ for x in range (200 ):
141+ db .test .save ({"x" : x })
142+
143+ self .assertRaises (TypeError , db .test .find ().batch_size , None )
144+ self .assertRaises (TypeError , db .test .find ().batch_size , "hello" )
145+ self .assertRaises (TypeError , db .test .find ().batch_size , 5.5 )
146+ self .assertRaises (ValueError , db .test .find ().batch_size , - 1 )
147+ a = db .test .find ()
148+ for _ in a :
149+ break
150+ self .assertRaises (InvalidOperation , a .batch_size , 5 )
151+
152+ def cursor_count (cursor , expected_count ):
153+ count = 0
154+ for _ in cursor :
155+ count += 1
156+ self .assertEqual (expected_count , count )
157+
158+ cursor_count (db .test .find ().batch_size (0 ), 200 )
159+ cursor_count (db .test .find ().batch_size (1 ), 200 )
160+ cursor_count (db .test .find ().batch_size (2 ), 200 )
161+ cursor_count (db .test .find ().batch_size (5 ), 200 )
162+ cursor_count (db .test .find ().batch_size (100 ), 200 )
163+ cursor_count (db .test .find ().batch_size (500 ), 200 )
164+
165+ cursor_count (db .test .find ().batch_size (0 ).limit (1 ), 1 )
166+ cursor_count (db .test .find ().batch_size (1 ).limit (1 ), 1 )
167+ cursor_count (db .test .find ().batch_size (2 ).limit (1 ), 1 )
168+ cursor_count (db .test .find ().batch_size (5 ).limit (1 ), 1 )
169+ cursor_count (db .test .find ().batch_size (100 ).limit (1 ), 1 )
170+ cursor_count (db .test .find ().batch_size (500 ).limit (1 ), 1 )
171+
172+ cursor_count (db .test .find ().batch_size (0 ).limit (10 ), 10 )
173+ cursor_count (db .test .find ().batch_size (1 ).limit (10 ), 10 )
174+ cursor_count (db .test .find ().batch_size (2 ).limit (10 ), 10 )
175+ cursor_count (db .test .find ().batch_size (5 ).limit (10 ), 10 )
176+ cursor_count (db .test .find ().batch_size (100 ).limit (10 ), 10 )
177+ cursor_count (db .test .find ().batch_size (500 ).limit (10 ), 10 )
178+
179+
137180 def test_skip (self ):
138181 db = self .db
139182
@@ -189,7 +232,7 @@ def test_sort(self):
189232 [("hello" , DESCENDING )], DESCENDING )
190233 self .assertRaises (TypeError , db .test .find ().sort , "hello" , "world" )
191234
192- db .test .remove ({} )
235+ db .test .drop ( )
193236
194237 unsort = range (10 )
195238 random .shuffle (unsort )
@@ -218,7 +261,7 @@ def test_sort(self):
218261 shuffled = list (expected )
219262 random .shuffle (shuffled )
220263
221- db .test .remove ({} )
264+ db .test .drop ( )
222265 for (a , b ) in shuffled :
223266 db .test .save ({"a" : a , "b" : b })
224267
@@ -235,7 +278,7 @@ def test_sort(self):
235278
236279 def test_count (self ):
237280 db = self .db
238- db .test .remove ({} )
281+ db .test .drop ( )
239282
240283 self .assertEqual (0 , db .test .find ().count ())
241284
@@ -260,7 +303,7 @@ def test_count(self):
260303
261304 def test_where (self ):
262305 db = self .db
263- db .test .remove ({} )
306+ db .test .drop ( )
264307
265308 a = db .test .find ()
266309 self .assertRaises (TypeError , a .where , 5 )
@@ -405,7 +448,7 @@ def test_clone(self):
405448 self .assertNotEqual (cursor , cursor .clone ())
406449
407450 def test_count_with_fields (self ):
408- self .db .test .remove ({} )
451+ self .db .test .drop ( )
409452 self .db .test .save ({"x" : 1 })
410453
411454 if not version .at_least (self .db .connection , (1 , 1 , 3 , - 1 )):
0 commit comments