@@ -914,6 +914,8 @@ def test_rewind(self):
914
914
915
915
self .assertEqual (cursor , cursor .rewind ())
916
916
917
+ # manipulate, oplog_reply, and snapshot are all deprecated.
918
+ @ignore_deprecations
917
919
def test_clone (self ):
918
920
self .db .test .insert_many ([{"x" : i } for i in range (1 , 4 )])
919
921
@@ -952,31 +954,30 @@ def test_clone(self):
952
954
953
955
# Just test attributes
954
956
cursor = self .db .test .find ({"x" : re .compile ("^hello.*" )},
957
+ projection = {'_id' : False },
955
958
skip = 1 ,
956
959
no_cursor_timeout = True ,
957
960
cursor_type = CursorType .TAILABLE_AWAIT ,
961
+ sort = [("x" , 1 )],
958
962
allow_partial_results = True ,
963
+ oplog_replay = True ,
964
+ batch_size = 123 ,
959
965
manipulate = False ,
960
- projection = {'_id' : False }).limit (2 )
966
+ collation = {'locale' : 'en_US' },
967
+ hint = [("_id" , 1 )],
968
+ max_scan = 100 ,
969
+ max_time_ms = 1000 ,
970
+ return_key = True ,
971
+ show_record_id = True ,
972
+ snapshot = True ,
973
+ allow_disk_use = True ).limit (2 )
961
974
cursor .min ([('a' , 1 )]).max ([('b' , 3 )])
962
975
cursor .add_option (128 )
963
976
cursor .comment ('hi!' )
964
977
978
+ # Every attribute should be the same.
965
979
cursor2 = cursor .clone ()
966
- self .assertEqual (cursor ._Cursor__skip , cursor2 ._Cursor__skip )
967
- self .assertEqual (cursor ._Cursor__limit , cursor2 ._Cursor__limit )
968
- self .assertEqual (type (cursor ._Cursor__codec_options ),
969
- type (cursor2 ._Cursor__codec_options ))
970
- self .assertEqual (cursor ._Cursor__manipulate ,
971
- cursor2 ._Cursor__manipulate )
972
- self .assertEqual (cursor ._Cursor__query_flags ,
973
- cursor2 ._Cursor__query_flags )
974
- self .assertEqual (cursor ._Cursor__comment ,
975
- cursor2 ._Cursor__comment )
976
- self .assertEqual (cursor ._Cursor__min ,
977
- cursor2 ._Cursor__min )
978
- self .assertEqual (cursor ._Cursor__max ,
979
- cursor2 ._Cursor__max )
980
+ self .assertEqual (cursor .__dict__ , cursor2 .__dict__ )
980
981
981
982
# Shallow copies can so can mutate
982
983
cursor2 = copy .copy (cursor )
@@ -1011,6 +1012,14 @@ def test_clone(self):
1011
1012
self .assertTrue (isinstance (cursor2 ._Cursor__hint , SON ))
1012
1013
self .assertEqual (cursor ._Cursor__hint , cursor2 ._Cursor__hint )
1013
1014
1015
+ def test_clone_empty (self ):
1016
+ self .db .test .delete_many ({})
1017
+ self .db .test .insert_many ([{"x" : i } for i in range (1 , 4 )])
1018
+ cursor = self .db .test .find ()[2 :2 ]
1019
+ cursor2 = cursor .clone ()
1020
+ self .assertRaises (StopIteration , cursor .next )
1021
+ self .assertRaises (StopIteration , cursor2 .next )
1022
+
1014
1023
@ignore_deprecations
1015
1024
def test_count_with_fields (self ):
1016
1025
self .db .test .drop ()
0 commit comments