@@ -1091,7 +1091,7 @@ def test_get_many():
10911091
10921092def test_all ():
10931093 # Check preconditions
1094- assert len (list (col .all ())) == 0
1094+ assert len (list (col .export ())) == 0
10951095
10961096 # Set up test documents
10971097 col .import_bulk (test_docs )
@@ -1100,71 +1100,132 @@ def test_all():
11001100 result = list (col .all ())
11011101 assert ordered (clean_keys (result )) == test_docs
11021102
1103- # Test all with flush
1104- # result = list(col.all(flush=True, flush_wait=1))
1105- # assert ordered(clean_keys(result)) == test_docs
1106-
1107- # Test all with count
1108- result = col .all (count = True )
1109- assert result .count () == len (test_docs )
1110- assert ordered (clean_keys (result )) == test_docs
1111-
1112- # Test all with batch size
1113- result = col .all (count = True , batch_size = 1 )
1103+ # Test all with a skip of 0
1104+ result = col .all (skip = 0 )
11141105 assert result .count () == len (test_docs )
11151106 assert ordered (clean_keys (result )) == test_docs
11161107
1117- # Test all with time-to-live
1118- result = col .all (count = True , ttl = 1000 )
1119- assert result .count () == len (test_docs )
1120- assert ordered (clean_keys (result )) == test_docs
1108+ # Test all with a skip of 1
1109+ result = col .all (skip = 1 )
1110+ assert result .count () == 4
1111+ assert len (list (result )) == 4
1112+ for doc in list (clean_keys (result )):
1113+ assert doc in test_docs
11211114
1122- # Test all with filters
1123- result = col .all (
1124- count = True ,
1125- filter_fields = ['text' ],
1126- filter_type = 'exclude'
1127- )
1128- assert result .count () == 5
1129- for doc in result :
1130- assert 'text' not in doc
1115+ # Test all with a skip of 3
1116+ result = col .all (skip = 3 )
1117+ assert result .count () == 2
1118+ assert len (list (result )) == 2
1119+ for doc in list (clean_keys (list (result ))):
1120+ assert doc in test_docs
11311121
11321122 # Test all with a limit of 0
1133- result = col .all (count = True , limit = 0 )
1134- assert result .count () == len ( test_docs )
1135- assert ordered (clean_keys (result )) == test_docs
1123+ result = col .all (limit = 0 )
1124+ assert result .count () == 0
1125+ assert ordered (clean_keys (result )) == []
11361126
11371127 # Test all with a limit of 1
1138- result = col .all (count = True , limit = 1 )
1128+ result = col .all (limit = 1 )
11391129 assert result .count () == 1
11401130 assert len (list (result )) == 1
11411131 for doc in list (clean_keys (result )):
11421132 assert doc in test_docs
11431133
11441134 # Test all with a limit of 3
1145- result = col .all (count = True , limit = 3 )
1135+ result = col .all (limit = 3 )
11461136 assert result .count () == 3
11471137 assert len (list (result )) == 3
11481138 for doc in list (clean_keys (list (result ))):
11491139 assert doc in test_docs
11501140
1151- # Test all in missing collection
1141+ # Test all with skip and limit
1142+ result = col .all (skip = 4 , limit = 2 )
1143+ assert result .count () == 1
1144+ assert len (list (result )) == 1
1145+ for doc in list (clean_keys (list (result ))):
1146+ assert doc in test_docs
1147+
1148+ # Test export in missing collection
11521149 with pytest .raises (DocumentGetError ):
11531150 bad_col .all ()
11541151
1155- # Test closing export cursor
1156- result = col .all (count = True , batch_size = 1 )
1157- assert result .close (ignore_missing = False ) is True
1158- assert result .close (ignore_missing = True ) is False
1159-
1160- assert clean_keys (result .next ()) == doc1
1161- with pytest .raises (CursorNextError ):
1162- result .next ()
1163- with pytest .raises (CursorCloseError ):
1164- result .close (ignore_missing = False )
1165-
1166- result = col .all (count = True )
1167- assert result .close (ignore_missing = True ) is False
1152+ # TODO uncomment when export with flush works properly
1153+ # def test_export():
1154+ # # Check preconditions
1155+ # assert len(list(col.export())) == 0
1156+ #
1157+ # # Set up test documents
1158+ # col.import_bulk(test_docs)
1159+ #
1160+ # # Test export with default options
1161+ # result = list(col.export())
1162+ # assert ordered(clean_keys(result)) == test_docs
1163+ #
1164+ # # Test export with flush
1165+ # # result = list(col.export(flush=True, flush_wait=1))
1166+ # # assert ordered(clean_keys(result)) == test_docs
1167+ #
1168+ # # Test export with count
1169+ # result = col.export(count=True)
1170+ # assert result.count() == len(test_docs)
1171+ # assert ordered(clean_keys(result)) == test_docs
1172+ #
1173+ # # Test export with batch size
1174+ # result = col.export(count=True, batch_size=1)
1175+ # assert result.count() == len(test_docs)
1176+ # assert ordered(clean_keys(result)) == test_docs
1177+ #
1178+ # # Test export with time-to-live
1179+ # result = col.export(count=True, ttl=1000)
1180+ # assert result.count() == len(test_docs)
1181+ # assert ordered(clean_keys(result)) == test_docs
1182+ #
1183+ # # Test export with filters
1184+ # result = col.export(
1185+ # count=True,
1186+ # filter_fields=['text'],
1187+ # filter_type='exclude'
1188+ # )
1189+ # assert result.count() == 5
1190+ # for doc in result:
1191+ # assert 'text' not in doc
1192+ #
1193+ # # Test export with a limit of 0
1194+ # result = col.export(count=True, limit=0)
1195+ # assert result.count() == len(test_docs)
1196+ # assert ordered(clean_keys(result)) == test_docs
1197+ #
1198+ # # Test export with a limit of 1
1199+ # result = col.export(count=True, limit=1)
1200+ # assert result.count() == 1
1201+ # assert len(list(result)) == 1
1202+ # for doc in list(clean_keys(result)):
1203+ # assert doc in test_docs
1204+ #
1205+ # # Test export with a limit of 3
1206+ # result = col.export(count=True, limit=3)
1207+ # assert result.count() == 3
1208+ # assert len(list(result)) == 3
1209+ # for doc in list(clean_keys(list(result))):
1210+ # assert doc in test_docs
1211+ #
1212+ # # Test export in missing collection
1213+ # with pytest.raises(DocumentGetError):
1214+ # bad_col.export()
1215+ #
1216+ # # Test closing export cursor
1217+ # result = col.export(count=True, batch_size=1)
1218+ # assert result.close(ignore_missing=False) is True
1219+ # assert result.close(ignore_missing=True) is False
1220+ #
1221+ # assert clean_keys(result.next()) == doc1
1222+ # with pytest.raises(CursorNextError):
1223+ # result.next()
1224+ # with pytest.raises(CursorCloseError):
1225+ # result.close(ignore_missing=False)
1226+ #
1227+ # result = col.export(count=True)
1228+ # assert result.close(ignore_missing=True) is False
11681229
11691230
11701231def test_random ():
0 commit comments