Skip to content

Commit 87d65cb

Browse files
committed
fix: adapt tests to new multiprocessing
1 parent d4dd6a0 commit 87d65cb

File tree

1 file changed

+16
-46
lines changed

1 file changed

+16
-46
lines changed

mapswipe_workers/tests/unittests/test_process_mapillary.py

Lines changed: 16 additions & 46 deletions
Original file line numberDiff line numberDiff line change
@@ -53,6 +53,7 @@ def setUp(self):
5353
)
5454
self.empty_polygon = Polygon()
5555
self.empty_geometry = GeometryCollection()
56+
self.row = pd.Series({"x": 1, "y": 1, "z": self.level})
5657

5758
def test_create_tiles_with_valid_polygon(self):
5859
tiles = create_tiles(self.test_polygon, self.level)
@@ -171,26 +172,26 @@ def test_download_and_process_tile_success(self, mock_get, mock_vt2geojson):
171172

172173
row = {"x": 1, "y": 1, "z": 14}
173174

174-
result = download_and_process_tile(row)
175+
polygon = wkt.loads("POLYGON ((-1 -1, -1 1, 1 1, 1 -1, -1 -1))")
175176

177+
result = download_and_process_tile(row, polygon, {})
176178
self.assertIsInstance(result, pd.DataFrame)
177179
self.assertEqual(len(result), 1)
178180
self.assertEqual(result["geometry"][0].wkt, "POINT (0 0)")
179181

180182
@patch("mapswipe_workers.utils.process_mapillary.requests.get")
181183
def test_download_and_process_tile_failure(self, mock_get):
182-
# Mock a failed response
184+
183185
mock_response = MagicMock()
184186
mock_response.status_code = 500
185187
mock_get.return_value = mock_response
186188

187-
row = pd.Series({"x": 1, "y": 1, "z": self.level})
188-
result = download_and_process_tile(row)
189+
result = download_and_process_tile(self.row, self.test_polygon, {})
189190

190191
self.assertIsNone(result)
191192

192-
@patch("mapswipe_workers.utils.process_mapillary.download_and_process_tile")
193-
def test_coordinate_download(self, mock_download_and_process_tile):
193+
@patch("mapswipe_workers.utils.process_mapillary.get_mapillary_data")
194+
def test_download_and_process_tile_spatial_filtering(self, mock_get_mapillary_data):
194195
inside_points = [
195196
(0.2, 0.2),
196197
(0.5, 0.5),
@@ -208,20 +209,20 @@ def test_coordinate_download(self, mock_download_and_process_tile):
208209
for x, y in points
209210
]
210211

211-
mock_download_and_process_tile.return_value = pd.DataFrame(data)
212+
mock_get_mapillary_data.return_value = pd.DataFrame(data)
212213

213-
metadata = coordinate_download(self.test_polygon, self.level)
214+
metadata = download_and_process_tile(self.row, self.test_polygon, {})
214215

215216
metadata = metadata.drop_duplicates()
216217
self.assertEqual(len(metadata), len(inside_points))
217218

218219
self.assertIsInstance(metadata, pd.DataFrame)
219220

220-
@patch("mapswipe_workers.utils.process_mapillary.download_and_process_tile")
221-
def test_coordinate_download_with_failures(self, mock_download_and_process_tile):
222-
mock_download_and_process_tile.return_value = pd.DataFrame()
221+
@patch("mapswipe_workers.utils.process_mapillary.parallelized_processing")
222+
def test_coordinate_download_with_failures(self, mock_parallelized_processing):
223+
mock_parallelized_processing.return_value = pd.DataFrame()
223224

224-
metadata = coordinate_download(self.test_polygon, self.level)
225+
metadata = coordinate_download(self.test_polygon, self.level, {})
225226

226227
self.assertTrue(metadata.empty)
227228

@@ -284,7 +285,7 @@ def test_filter_missing_columns(self):
284285
"is_pano",
285286
"organization_id",
286287
"captured_at",
287-
] # Add your column names here
288+
]
288289
for column in columns_to_check:
289290
df_copy = self.fixture_df.copy()
290291
df_copy[column] = None
@@ -302,33 +303,6 @@ def test_get_image_metadata(self, mock_coordinate_download):
302303
self.assertIn("ids", result)
303304
self.assertIn("geometries", result)
304305

305-
@patch("mapswipe_workers.utils.process_mapillary.coordinate_download")
306-
def test_get_image_metadata_filtering(self, mock_coordinate_download):
307-
mock_coordinate_download.return_value = self.fixture_df
308-
309-
params = {
310-
"is_pano": True,
311-
"start_time": "2016-01-20 00:00:00",
312-
"end_time": "2022-01-21 23:59:59",
313-
}
314-
315-
result = get_image_metadata(self.fixture_data, **params)
316-
self.assertIsInstance(result, dict)
317-
self.assertIn("ids", result)
318-
self.assertIn("geometries", result)
319-
320-
@patch("mapswipe_workers.utils.process_mapillary.coordinate_download")
321-
def test_get_image_metadata_no_rows(self, mock_coordinate_download):
322-
mock_coordinate_download.return_value = self.fixture_df
323-
324-
params = {
325-
"is_pano": True,
326-
"start_time": "1916-01-20 00:00:00",
327-
"end_time": "1922-01-21 23:59:59",
328-
}
329-
with self.assertRaises(ValueError):
330-
get_image_metadata(self.fixture_data, **params)
331-
332306
@patch("mapswipe_workers.utils.process_mapillary.coordinate_download")
333307
def test_get_image_metadata_empty_response(self, mock_coordinate_download):
334308
df = self.fixture_df.copy()
@@ -338,13 +312,9 @@ def test_get_image_metadata_empty_response(self, mock_coordinate_download):
338312
with self.assertRaises(ValueError):
339313
get_image_metadata(self.fixture_data)
340314

341-
@patch("mapswipe_workers.utils.process_mapillary.filter_results")
342315
@patch("mapswipe_workers.utils.process_mapillary.coordinate_download")
343-
def test_get_image_metadata_size_restriction(
344-
self, mock_coordinate_download, mock_filter_results
345-
):
346-
mock_filter_results.return_value = pd.DataFrame({"ID": range(1, 100002)})
347-
mock_coordinate_download.return_value = self.fixture_df
316+
def test_get_image_metadata_size_restriction(self, mock_coordinate_download):
317+
mock_coordinate_download.return_value = pd.DataFrame({"ID": range(1, 100002)})
348318

349319
with self.assertRaises(ValueError):
350320
get_image_metadata(self.fixture_data)

0 commit comments

Comments
 (0)