1- import unittest
2- import os
31import json
4- from shapely .geometry import (
5- Polygon ,
6- MultiPolygon ,
7- Point ,
8- LineString ,
9- MultiLineString ,
10- GeometryCollection ,
11- )
12- from shapely import wkt
2+ import os
3+ import unittest
4+ from unittest .mock import MagicMock , patch
5+
136import pandas as pd
14- from unittest .mock import patch , MagicMock
7+ from shapely import wkt
8+ from shapely .geometry import GeometryCollection , MultiPolygon , Polygon
9+
1510from mapswipe_workers .utils .process_mapillary import (
11+ coordinate_download ,
1612 create_tiles ,
1713 download_and_process_tile ,
18- coordinate_download ,
19- geojson_to_polygon ,
2014 filter_by_timerange ,
2115 filter_results ,
16+ geojson_to_polygon ,
2217 get_image_metadata ,
2318)
2419
@@ -47,7 +42,7 @@ def setUpClass(cls):
4742 "r" ,
4843 ) as file :
4944 df = pd .read_csv (file )
50- df [' geometry' ] = df [' geometry' ].apply (wkt .loads )
45+ df [" geometry" ] = df [" geometry" ].apply (wkt .loads )
5146 cls .fixture_df = df
5247
5348 def setUp (self ):
@@ -141,7 +136,10 @@ def test_geojson_to_polygon_non_polygon_geometry_in_feature_collection(self):
141136 }
142137 with self .assertRaises (ValueError ) as context :
143138 geojson_to_polygon (geojson_data )
144- self .assertEqual (str (context .exception ), "Non-polygon geometries cannot be combined into a MultiPolygon." )
139+ self .assertEqual (
140+ str (context .exception ),
141+ "Non-polygon geometries cannot be combined into a MultiPolygon." ,
142+ )
145143
146144 def test_geojson_to_polygon_empty_feature_collection (self ):
147145 geojson_data = {"type" : "FeatureCollection" , "features" : []}
@@ -193,27 +191,17 @@ def test_download_and_process_tile_failure(self, mock_get):
193191
194192 @patch ("mapswipe_workers.utils.process_mapillary.download_and_process_tile" )
195193 def test_coordinate_download (self , mock_download_and_process_tile ):
196- mock_download_and_process_tile .return_value = (
197- pd .DataFrame ([{"geometry" : None }]),
198- None ,
199- )
194+ mock_download_and_process_tile .return_value = pd .DataFrame ([{"geometry" : None }])
200195
201- metadata = coordinate_download (
202- self .test_polygon , self .level
203- )
196+ metadata = coordinate_download (self .test_polygon , self .level )
204197
205198 self .assertIsInstance (metadata , pd .DataFrame )
206199
207200 @patch ("mapswipe_workers.utils.process_mapillary.download_and_process_tile" )
208201 def test_coordinate_download_with_failures (self , mock_download_and_process_tile ):
209- mock_download_and_process_tile .return_value = (
210- None ,
211- pd .Series ({"x" : 1 , "y" : 1 , "z" : self .level }),
212- )
202+ mock_download_and_process_tile .return_value = pd .DataFrame ()
213203
214- metadata = coordinate_download (
215- self .test_polygon , self .level
216- )
204+ metadata = coordinate_download (self .test_polygon , self .level )
217205
218206 self .assertTrue (metadata .empty )
219207
@@ -268,7 +256,11 @@ def test_filter_no_rows_after_filter(self):
268256 self .assertTrue (filtered_df .empty )
269257
270258 def test_filter_missing_columns (self ):
271- columns_to_check = ["is_pano" , "organization_id" , "captured_at" ] # Add your column names here
259+ columns_to_check = [
260+ "is_pano" ,
261+ "organization_id" ,
262+ "captured_at" ,
263+ ] # Add your column names here
272264 for column in columns_to_check :
273265 df_copy = self .fixture_df .copy ()
274266 df_copy [column ] = None
@@ -286,7 +278,6 @@ def test_get_image_metadata(self, mock_coordinate_download):
286278 self .assertIn ("ids" , result )
287279 self .assertIn ("geometries" , result )
288280
289-
290281 @patch ("mapswipe_workers.utils.process_mapillary.coordinate_download" )
291282 def test_get_image_metadata_filtering (self , mock_coordinate_download ):
292283 mock_coordinate_download .return_value = self .fixture_df
@@ -302,7 +293,6 @@ def test_get_image_metadata_filtering(self, mock_coordinate_download):
302293 self .assertIn ("ids" , result )
303294 self .assertIn ("geometries" , result )
304295
305-
306296 @patch ("mapswipe_workers.utils.process_mapillary.coordinate_download" )
307297 def test_get_image_metadata_no_rows (self , mock_coordinate_download ):
308298 mock_coordinate_download .return_value = self .fixture_df
@@ -326,8 +316,10 @@ def test_get_image_metadata_empty_response(self, mock_coordinate_download):
326316
327317 @patch ("mapswipe_workers.utils.process_mapillary.filter_results" )
328318 @patch ("mapswipe_workers.utils.process_mapillary.coordinate_download" )
329- def test_get_image_metadata_size_restriction (self , mock_coordinate_download , mock_filter_results ):
330- mock_filter_results .return_value = pd .DataFrame ({'ID' : range (1 , 100002 )})
319+ def test_get_image_metadata_size_restriction (
320+ self , mock_coordinate_download , mock_filter_results
321+ ):
322+ mock_filter_results .return_value = pd .DataFrame ({"ID" : range (1 , 100002 )})
331323 mock_coordinate_download .return_value = self .fixture_df
332324
333325 with self .assertRaises (ValueError ):
0 commit comments