2323
2424NUM_DOCS = 5
2525
26+
2627def client_search_testing (
2728 search_method : Callable ,
2829 excluded_params : list [str ],
2930 alt_name_dict : dict [str , str ],
3031 custom_field_tests : dict [str , Any ],
3132 sub_doc_fields : list [str ],
32- int_bounds : tuple [int ,int ] = (- 100 , 100 ),
33- float_bounds : tuple [float ,float ] = (- 100.12 , 100.12 ),
33+ int_bounds : tuple [int , int ] = (- 100 , 100 ),
34+ float_bounds : tuple [float , float ] = (- 100.12 , 100.12 ),
3435):
35- """
36- Function to test a client using its search method.
36+ """Function to test a client using its search method.
3737 Each parameter is used to query for data, which is then checked.
3838
3939 Args:
@@ -43,7 +43,7 @@ def client_search_testing(
4343 custom_field_tests (dict[str, Any]): Custom queries for specific fields.
4444 sub_doc_fields (list[str]): Prefixes for fields to check in resulting data. Useful when data to be tested is nested.
4545 int_bounds (tuple[int,int]) : integer bounds to use in testing int-type query arguments
46- float_boudns (tuple[float,float]) : float bounds to use in testing float-type query arguments
46+ float_bounds (tuple[float,float]) : float bounds to use in testing float-type query arguments
4747 """
4848 if search_method is None :
4949 return
@@ -56,7 +56,7 @@ def client_search_testing(
5656
5757 if param not in excluded_params + ["return" ]:
5858 param_type = entry [1 ]
59- q = {"chunk_size" : 1 , "num_chunks" : 1 }
59+ q : dict [ str , Any ] = {"chunk_size" : 1 , "num_chunks" : 1 }
6060
6161 if "tuple[int, int]" in param_type :
6262 q [param ] = int_bounds
@@ -84,31 +84,35 @@ def client_search_testing(
8484 assert doc [alt_name_dict .get (param , param )] is not None
8585
8686
87- def client_pagination (search_method : Callable , id_name : str ):
88-
89- page_1 = search_method (_page = 1 , chunk_size = NUM_DOCS , fields = [id_name ])
90- page_2 = search_method (_page = 2 , chunk_size = NUM_DOCS , fields = [id_name ])
91- assert all (
92- len (results ) == NUM_DOCS for results in (page_1 , page_2 )
93- )
87+ def client_pagination (search_method : Callable , id_name : str ):
88+ page_1 = search_method (_page = 1 , chunk_size = NUM_DOCS , fields = [id_name ])
89+ page_2 = search_method (_page = 2 , chunk_size = NUM_DOCS , fields = [id_name ])
90+ assert all (len (results ) == NUM_DOCS for results in (page_1 , page_2 ))
9491 assert {str (getattr (doc , id_name )) for doc in page_1 }.intersection (
95- {str (getattr (doc ,id_name )) for doc in page_2 }
92+ {str (getattr (doc , id_name )) for doc in page_2 }
9693 ) == set ()
9794
9895
99- def client_sort (search_method : Callable , sort_fields : str | Sequence [str ]):
100-
101- for sort_field in ([sort_fields ] if isinstance (sort_fields ,str ) else sort_fields ):
102- asc = search_method (_page = 1 , _sort_fields = sort_field , chunk_size = NUM_DOCS , fields = [sort_field ])
103- desc = search_method (_page = 1 , _sort_fields = f"-{ sort_field } " , chunk_size = NUM_DOCS , fields = [sort_field ])
96+ def client_sort (search_method : Callable , sort_fields : str | Sequence [str ]):
97+ for sort_field in [sort_fields ] if isinstance (sort_fields , str ) else sort_fields :
98+ asc = search_method (
99+ _page = 1 , _sort_fields = sort_field , chunk_size = NUM_DOCS , fields = [sort_field ]
100+ )
101+ desc = search_method (
102+ _page = 1 ,
103+ _sort_fields = f"-{ sort_field } " ,
104+ chunk_size = NUM_DOCS ,
105+ fields = [sort_field ],
106+ )
104107
105108 idxs = list (range (NUM_DOCS ))
106- assert sorted (
107- idxs , key = lambda idx : getattr (asc [idx ],sort_field )
108- ) == idxs
109-
110- assert sorted (
111- idxs ,
112- key = lambda idx : getattr (desc [idx ],sort_field ),
113- reverse = True ,
114- ) == idxs
109+ assert sorted (idxs , key = lambda idx : getattr (asc [idx ], sort_field )) == idxs
110+
111+ assert (
112+ sorted (
113+ idxs ,
114+ key = lambda idx : getattr (desc [idx ], sort_field ),
115+ reverse = True ,
116+ )
117+ == idxs
118+ )
0 commit comments