Skip to content

Commit

Permalink
chore: add tests for structure data
Browse files Browse the repository at this point in the history
  • Loading branch information
AngRodrigues committed Dec 12, 2024
1 parent 05a4ccb commit 61936f9
Show file tree
Hide file tree
Showing 2 changed files with 108 additions and 1 deletion.
3 changes: 2 additions & 1 deletion map2loop/data_checks.py
Original file line number Diff line number Diff line change
Expand Up @@ -441,4 +441,5 @@ def check_fault_fields_validity(mapdata) -> Tuple[bool, str]:
f"Datatype FAULT: ID column '{id_column}' contains duplicate values. Rectify this or remove the key from the config to auto-generate IDs."
)

return (False, "")
return (False, "")

106 changes: 106 additions & 0 deletions tests/mapdata/test_input_data_faults.py
Original file line number Diff line number Diff line change
@@ -0,0 +1,106 @@
import pytest
import geopandas as gpd
import shapely.geometry
from map2loop.mapdata import MapData
from map2loop.m2l_enums import Datatype
from map2loop.data_checks import check_fault_fields_validity

@pytest.mark.parametrize(
"fault_data, fault_config, expected_validity, expected_message",
[
# Valid data
(
{
"geometry": [
shapely.geometry.LineString([(0, 0), (1, 1)]),
shapely.geometry.MultiLineString([[(0, 0), (1, 1)], [(1, 1), (2, 2)]])
],
"FEATURE": ["Fault A", "Fault B"],
"ID": [1, 2]
},
{"structtype_column": "FEATURE", "fault_text": "Fault", "objectid_column": "ID"},
False,
""
),
# Invalid geometry
(
{
"geometry": [
shapely.geometry.LineString([(0, 0), (1, 1)]),
shapely.geometry.Polygon([(0, 0), (1, 1), (1, 0), (0, 1), (0, 0)]) # Invalid geometry
],
"FEATURE": ["Fault A", "Fault B"],
"ID": [1, 2]
},
{"structtype_column": "FEATURE", "fault_text": "Fault", "objectid_column": "ID"},
True,
"Invalid geometries found in FAULT data."
),
# Non-string FEATURE column
(
{
"geometry": [
shapely.geometry.LineString([(0, 0), (1, 1)]),
shapely.geometry.MultiLineString([[(0, 0), (1, 1)], [(1, 1), (2, 2)]])
],
"FEATURE": [5, 2],
"ID": [1, 2]
},
{"structtype_column": "FEATURE", "fault_text": "Fault", "objectid_column": "ID"},
True,
"Datatype FAULT: Column 'FEATURE' (config key: 'structtype_column') contains non-string values."
),
# Invalid values in DIP estimate column
(
{
"geometry": [
shapely.geometry.LineString([(0, 0), (1, 1)]),
shapely.geometry.MultiLineString([[(0, 0), (1, 1)], [(1, 1), (2, 2)]])
],
"FEATURE": ["Fault", "Fault"],
"NAME": ["Zuleika", "Zuleika"],
"ID": [1, 2],
"DIP": [70, 50],
"STRIKE": [150, None],
"DEC": ["north_east", "southt"],
},
{
"structtype_column": "FEATURE",
"fault_text": "Fault",
"objectid_column": "ID",
"name_column": "NAME",
"dip_column": "DIP",
"dipdir_column": "STRIKE",
"dip_estimate_column": "DEC"
},
True,
"Datatype FAULT: Column 'DEC' contains invalid values. Allowed values: ['north_east', 'south_east', 'south_west', 'north_west', 'north', 'east', 'south', 'west']."
),
],
ids=[
"Valid fault data",
"Invalid geometry",
"Non-string FEATURE column",
"Invalid DIP estimate column"
]
)
def test_check_fault_fields_validity(fault_data, fault_config, expected_validity, expected_message):
# Dynamically create the mock config for this test case
class MockConfig:
def __init__(self, config):
self.fault_config = config

# Create a GeoDataFrame
fault_gdf = gpd.GeoDataFrame(fault_data, crs="EPSG:4326")

# Instantiate the MapData class with the dynamic mock config and data
map_data = MapData()
map_data.config = MockConfig(fault_config)
map_data.raw_data = [None] * len(Datatype.__dict__)
map_data.raw_data[Datatype.FAULT] = fault_gdf

# Test the check_fault_fields_validity function
validity_check, message = check_fault_fields_validity(map_data)
assert validity_check == expected_validity
assert message == expected_message

0 comments on commit 61936f9

Please sign in to comment.