Skip to content

Commit

Permalink
refactor
Browse files Browse the repository at this point in the history
  • Loading branch information
mrsmrynk committed Nov 12, 2023
1 parent 17b0337 commit 53a7e99
Show file tree
Hide file tree
Showing 2 changed files with 13 additions and 21 deletions.
30 changes: 11 additions & 19 deletions src/utils/tests/conftest.py
Original file line number Diff line number Diff line change
Expand Up @@ -2,6 +2,7 @@

import geopandas as gpd
import pytest
from shapely.geometry import box as Box # PEP8 compliant
from shapely.geometry import Polygon

from src.utils.coordinator import Coordinator
Expand Down Expand Up @@ -107,29 +108,20 @@ def boundary_gdf():


@pytest.fixture(scope='session')
def invalid_boundary_gdf():
def invalid_gdf_boundary():
"""
| Returns an invalid boundary geodataframe (more than 1 polygon).
:returns: invalid boundary geodataframe
:rtype: gpd.GeoDataFrame
"""
polygon_1 = Polygon([[-512, -512],
[0, -512],
[0, 0],
[-512, 0]])
polygon_2 = Polygon([[0, -512],
[512, -512],
[512, 0],
[0, 0]])
polygon_3 = Polygon([[0, 0],
[512, 0],
[512, 512],
[0, 512]])
polygon_4 = Polygon([[-512, 0],
[0, 0],
[0, 512],
[-512, 512]])
polygon_1 = Box(-512, -512, 0, 0)
polygon_2 = Box(0, -512, 512, 0)
polygon_3 = Box(0, 0, 512, 512)
polygon_4 = Box(-512, 0, 0, 512)
polygons = [polygon_1, polygon_2, polygon_3, polygon_4]
invalid_boundary_gdf = gpd.GeoDataFrame(geometry=polygons, crs='EPSG:25832')
return invalid_boundary_gdf

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

return invalid_gdf_boundary
4 changes: 2 additions & 2 deletions src/utils/tests/test_config_parser_exceptions.py
Original file line number Diff line number Diff line change
Expand Up @@ -74,7 +74,7 @@ def test_ShapeFileExtensionError():
raise ShapeFileExtensionError(shape_file_path='/path/to/shape_file.py')


def test_ShapeFileLengthError(invalid_boundary_gdf):
def test_ShapeFileLengthError(invalid_gdf_boundary):
"""
| Tests ShapeFileLengthError exception.
Expand All @@ -83,7 +83,7 @@ def test_ShapeFileLengthError(invalid_boundary_gdf):
"""
with pytest.raises(ShapeFileLengthError, match=r'Invalid shape file in shape_file_path in config file!'
r'\n Expected shape file with 1 polygon, got 4 polygons instead\.'):
raise ShapeFileLengthError(gdf=invalid_boundary_gdf)
raise ShapeFileLengthError(gdf=invalid_gdf_boundary)


def test_BoundingBoxNotDefinedError():
Expand Down

0 comments on commit 53a7e99

Please sign in to comment.