Skip to content

Commit

Permalink
add test
Browse files Browse the repository at this point in the history
  • Loading branch information
mrsmrynk committed Nov 28, 2023
1 parent 729b64a commit 66b6f17
Showing 1 changed file with 47 additions and 1 deletion.
48 changes: 47 additions & 1 deletion src/utils/tests/test_grid_generator.py
Original file line number Diff line number Diff line change
@@ -1,4 +1,5 @@
import inspect
import unittest.mock as mock

import geopandas as gpd
import geopandas.testing
Expand Down Expand Up @@ -113,10 +114,55 @@ def test_generate_grid_default(grid_generator):
assert quantize_default is True


def test_generate_grid(grid_generator):
@mock.patch('src.utils.grid_generator.GridGenerator.compute_coordinates')
@mock.patch('src.utils.grid_generator.GridGenerator.generate_polygons')
def test_generate_grid(mocked_generate_polygons,
mocked_compute_coordinates,
grid_generator):
"""
| Tests generate_grid().
:param mock.MagicMock mocked_generate_polygons: mocked generate_polygons method
:param mock.MagicMock mocked_compute_coordinates: mocked compute_coordinates method
:param GridGenerator grid_generator: grid generator fixture
:returns: None
:rtype: None
"""
tile_size = 128
quantize = True

polygons = [box(-128, -128, 0, 0), box(0, -128, 128, 0), box(-128, 0, 0, 128), box(0, 0, 128, 128)]

expected = gpd.GeoDataFrame(geometry=polygons,
crs='EPSG:25832')

mocked_compute_coordinates.return_value = np.array([[-128, -128], [0, -128], [-128, 0], [0, 0]], dtype=np.int32)
mocked_generate_polygons.return_value = polygons

grid = grid_generator.generate_grid(tile_size=tile_size,
quantize=quantize)

mocked_compute_coordinates.assert_called_once_with(tile_size=tile_size,
quantize=quantize)

mocked_generate_polygons.assert_called_once_with(coordinates=mocked_compute_coordinates.return_value,
tile_size=tile_size)

assert isinstance(grid, gpd.GeoDataFrame)
assert not grid.empty
assert grid.shape[1] == 1
assert all(grid['geometry'].geom_type == 'Polygon')
assert all(grid['geometry'].is_valid)
assert grid.crs == f'EPSG:{grid_generator.epsg_code}'
gpd.testing.assert_geodataframe_equal(grid, expected, check_geom_type=True)


@pytest.mark.integration
def test_generate_grid_integration(grid_generator):
"""
| Tests generate_grid().
| Integration test.
:param GridGenerator grid_generator: grid generator fixture
:returns: None
:rtype: None
Expand Down

0 comments on commit 66b6f17

Please sign in to comment.