@@ -79,7 +79,9 @@ def add_mock_rasters_in_folder_list_response(folder_id):
7979 }
8080 qs = {"folder" : folder_id , "page_number" : "1" }
8181 _add_api_response (
82- detector_api_url ("rasters/" ), json = data , match = responses .matchers .query_param_matcher (qs )
82+ detector_api_url ("rasters/" ),
83+ json = data ,
84+ match = responses .matchers .query_param_matcher (qs ),
8385 )
8486
8587
@@ -110,7 +112,9 @@ def add_mock_rasters_in_filtered_list_response(
110112 if has_layers is not None :
111113 qs ["has_vector_layers" ] = bool (has_layers )
112114 _add_api_response (
113- detector_api_url ("rasters/" ), match = responses .matchers .query_param_matcher (qs ), json = data
115+ detector_api_url ("rasters/" ),
116+ match = responses .matchers .query_param_matcher (qs ),
117+ json = data ,
114118 )
115119
116120
@@ -186,21 +190,32 @@ def add_mock_detectors_list_response(string=None, tag=None, shared=None):
186190
187191def add_mock_detector_creation_response (** kwargs ):
188192 match = responses .json_params_matcher ({"configuration" : kwargs }) if kwargs else None
189- _add_api_response (detector_api_url ("detectors/" ), responses .POST , json = {"id" : "foobar" }, match = match )
193+ _add_api_response (
194+ detector_api_url ("detectors/" ),
195+ responses .POST ,
196+ json = {"id" : "foobar" },
197+ match = match ,
198+ )
190199
191200
192201def add_mock_detector_edit_response (d_id , ** kwargs ):
193202 match = responses .json_params_matcher ({"configuration" : kwargs }) if kwargs else None
194- _add_api_response (detector_api_url ("detectors/%s/" % d_id ), responses .PUT , status = 204 , match = match )
203+ _add_api_response (
204+ detector_api_url ("detectors/%s/" % d_id ), responses .PUT , status = 204 , match = match
205+ )
195206
196207
197208def add_mock_detector_train_responses (detector_id ):
198- _add_api_response (detector_api_url ("detectors/%s/train/" % detector_id ), responses .POST , OP_RESP )
209+ _add_api_response (
210+ detector_api_url ("detectors/%s/train/" % detector_id ), responses .POST , OP_RESP
211+ )
199212
200213
201214def add_mock_run_dataset_recommendation_responses (detector_id ):
202215 _add_api_response (
203- detector_api_url ("detectors/%s/dataset_recommendation/" % detector_id ), responses .POST , OP_RESP
216+ detector_api_url ("detectors/%s/dataset_recommendation/" % detector_id ),
217+ responses .POST ,
218+ OP_RESP ,
204219 )
205220
206221
@@ -287,7 +302,9 @@ def add_mock_raster_upload_responses(identity_key, multispectral, cloud_coverage
287302 # Storage PUT
288303 responses .add (responses .PUT , "http://storage.example.com" , status = 200 )
289304 # Commit
290- _add_api_response (detector_api_url ("rasters/%s/commit/" % raster_id ), responses .POST , OP_RESP )
305+ _add_api_response (
306+ detector_api_url ("rasters/%s/commit/" % raster_id ), responses .POST , OP_RESP
307+ )
291308 # Status, first check
292309 data = {"id" : raster_id , "name" : "raster1" , "status" : "processing" }
293310 _add_api_response (detector_api_url ("rasters/%s/" % raster_id ), json = data )
@@ -302,26 +319,36 @@ def add_mock_detection_areas_upload_responses(raster_id):
302319 # Upload initiation
303320 data = {"upload_url" : "http://storage.example.com" , "upload_id" : upload_id }
304321 _add_api_response (
305- detector_api_url ("rasters/%s/detection_areas/upload/file/" % raster_id ), responses .POST , data
322+ detector_api_url ("rasters/%s/detection_areas/upload/file/" % raster_id ),
323+ responses .POST ,
324+ data ,
306325 )
307326 # Storage PUT
308327 responses .add (responses .PUT , "http://storage.example.com" , status = 200 )
309328 # Commit
310329 _add_api_response (
311- detector_api_url ("rasters/%s/detection_areas/upload/%s/commit/" % (raster_id , upload_id )),
330+ detector_api_url (
331+ "rasters/%s/detection_areas/upload/%s/commit/" % (raster_id , upload_id )
332+ ),
312333 responses .POST ,
313334 OP_RESP ,
314335 status = 200 ,
315336 )
316337 # Status, first check
317338 data = {"status" : "processing" }
318339 _add_api_response (
319- detector_api_url ("rasters/%s/detection_areas/upload/%s/" % (raster_id , upload_id )), json = data
340+ detector_api_url (
341+ "rasters/%s/detection_areas/upload/%s/" % (raster_id , upload_id )
342+ ),
343+ json = data ,
320344 )
321345 # Status, second check
322346 data = {"status" : "ready" }
323347 _add_api_response (
324- detector_api_url ("rasters/%s/detection_areas/upload/%s/" % (raster_id , upload_id )), json = data
348+ detector_api_url (
349+ "rasters/%s/detection_areas/upload/%s/" % (raster_id , upload_id )
350+ ),
351+ json = data ,
325352 )
326353
327354
@@ -390,7 +417,9 @@ def add_mock_vector_layer_download_responses(layer_id, polygons_num):
390417 }
391418 add_mock_operations_responses ("success" , results = results )
392419 url = results ["download_url" ]
393- polygons_fc = multipolygon_to_polygon_feature_collection (make_geojson_multipolygon (polygons_num ))
420+ polygons_fc = multipolygon_to_polygon_feature_collection (
421+ make_geojson_multipolygon (polygons_num )
422+ )
394423 assert len (polygons_fc ["features" ]) == polygons_num
395424 responses .add (
396425 responses .GET ,
@@ -399,13 +428,19 @@ def add_mock_vector_layer_download_responses(layer_id, polygons_num):
399428 )
400429 return polygons_fc
401430
431+
402432def add_mock_folder_creation_response (id , name ):
403433 match = responses .matchers .json_params_matcher ({"name" : name })
404- _add_api_response (detector_api_url ("folders/" ), responses .POST , json = {"id" : id }, match = match )
434+ _add_api_response (
435+ detector_api_url ("folders/" ), responses .POST , json = {"id" : id }, match = match
436+ )
405437
406438
407439def make_geojson_polygon (base = 1 ):
408- return {"type" : "Polygon" , "coordinates" : [[[0 , 0 ], [base , 0 ], [base , base ], [0 , base ], [0 , 0 ]]]}
440+ return {
441+ "type" : "Polygon" ,
442+ "coordinates" : [[[0 , 0 ], [base , 0 ], [base , base ], [0 , base ], [0 , 0 ]]],
443+ }
409444
410445
411446def make_geojson_multipolygon (npolygons = 1 ):
@@ -424,9 +459,10 @@ def add_mock_download_result_response(op_id, num_classes):
424459 "class" : {"name" : f"class_{ i + 1 } " },
425460 "result" : {
426461 "url" : f"http://storage.example.com/result_for_class_{ i + 1 } .geojson" ,
427- "vector_layer_id" : f"layer_{ i + 1 } "
462+ "vector_layer_id" : f"layer_{ i + 1 } " ,
428463 },
429- } for i in range (num_classes )
464+ }
465+ for i in range (num_classes )
430466 ],
431467 },
432468 }
@@ -479,15 +515,19 @@ def add_mock_delete_raster_response(raster_id):
479515
480516
481517def add_mock_delete_detectionarea_response (raster_id ):
482- _add_api_response (detector_api_url ("rasters/%s/detection_areas/" % raster_id ), responses .DELETE )
518+ _add_api_response (
519+ detector_api_url ("rasters/%s/detection_areas/" % raster_id ), responses .DELETE
520+ )
483521
484522
485523def add_mock_delete_detector_response (detector_id ):
486524 _add_api_response (detector_api_url ("detectors/%s/" % detector_id ), responses .DELETE )
487525
488526
489527def add_mock_delete_vector_layer_response (layer_id ):
490- _add_api_response (detector_api_url ("vector_layers/%s/" % layer_id ), responses .DELETE )
528+ _add_api_response (
529+ detector_api_url ("vector_layers/%s/" % layer_id ), responses .DELETE
530+ )
491531
492532
493533def add_mock_edit_vector_layer_response (layer_id , ** kwargs ):
@@ -536,7 +576,9 @@ def add_mock_marker_creation_response(marker_id, raster_id, detector_id, coords,
536576 "text" : text ,
537577 }
538578 match = responses .matchers .json_params_matcher (body )
539- _add_api_response (detector_api_url (url ), responses .POST , json = {"id" : marker_id }, match = match )
579+ _add_api_response (
580+ detector_api_url (url ), responses .POST , json = {"id" : marker_id }, match = match
581+ )
540582
541583
542584def add_mock_folder_detector_response (folder_id : str ):
@@ -598,27 +640,30 @@ def test_multipolygon_to_polygon_feature_collection():
598640 "type" : "MultiPolygon" ,
599641 "coordinates" : [
600642 [[[0 , 0 ], [0 , 1 ], [1 , 1 ], [1 , 0 ], [0 , 0 ]]],
601- [[[1 , 1 ], [1 , 2 ], [2 , 2 ], [2 , 1 ], [1 , 1 ]]]
602- ]
643+ [[[1 , 1 ], [1 , 2 ], [2 , 2 ], [2 , 1 ], [1 , 1 ]]],
644+ ],
603645 }
604646 fc = multipolygon_to_polygon_feature_collection (mp )
605647 assert fc == {
606648 "type" : "FeatureCollection" ,
607- "features" : [{
608- "type" : "Feature" ,
609- "properties" : {},
610- "geometry" : {
611- "type" : "Polygon" ,
612- "coordinates" : [[[0 , 0 ], [0 , 1 ], [1 , 1 ], [1 , 0 ], [0 , 0 ]]]
613- }
614- }, {
615- "type" : "Feature" ,
616- "properties" : {},
617- "geometry" : {
618- "type" : "Polygon" ,
619- "coordinates" : [[[1 , 1 ], [1 , 2 ], [2 , 2 ], [2 , 1 ], [1 , 1 ]]]
620- }
621- }]
649+ "features" : [
650+ {
651+ "type" : "Feature" ,
652+ "properties" : {},
653+ "geometry" : {
654+ "type" : "Polygon" ,
655+ "coordinates" : [[[0 , 0 ], [0 , 1 ], [1 , 1 ], [1 , 0 ], [0 , 0 ]]],
656+ },
657+ },
658+ {
659+ "type" : "Feature" ,
660+ "properties" : {},
661+ "geometry" : {
662+ "type" : "Polygon" ,
663+ "coordinates" : [[[1 , 1 ], [1 , 2 ], [2 , 2 ], [2 , 1 ], [1 , 1 ]]],
664+ },
665+ },
666+ ],
622667 }
623668
624669
@@ -953,7 +998,9 @@ def test_download_result_to_feature_collection(monkeypatch):
953998 assert len (feat1 ["geometry" ]["coordinates" ]) == 10
954999 assert isinstance (feat1 ["geometry" ]["coordinates" ][0 ][0 ][0 ][0 ], (int , float ))
9551000 feat2 = fc ["features" ][(class_1_index + 1 ) % 2 ]
956- assert feat2 ["type" ] == "Feature" and feat2 ["geometry" ]["type" ] == "MultiPolygon"
1001+ assert (
1002+ feat2 ["type" ] == "Feature" and feat2 ["geometry" ]["type" ] == "MultiPolygon"
1003+ )
9571004 assert feat2 ["properties" ]["class_name" ] == "class_2"
9581005 assert len (feat2 ["geometry" ]["coordinates" ]) == 20
9591006 assert isinstance (feat2 ["geometry" ]["coordinates" ][0 ][0 ][0 ][0 ], (int , float ))
@@ -1060,7 +1107,9 @@ def test_download_vector_layer_to_file(monkeypatch):
10601107 assert fc ["type" ] == "FeatureCollection"
10611108 assert fc == polygons_fc and len (fc ["features" ]) == 2
10621109 assert fc ["features" ][0 ]["geometry" ]["type" ] == "Polygon"
1063- assert isinstance (fc ["features" ][1 ]["geometry" ]["coordinates" ][0 ][0 ][0 ], (int , float ))
1110+ assert isinstance (
1111+ fc ["features" ][1 ]["geometry" ]["coordinates" ][0 ][0 ][0 ], (int , float )
1112+ )
10641113 assert len (responses .calls ) == 3 # POST /download, GET /operations, GET url
10651114
10661115
0 commit comments