From ecfe6908217d7f2ec14d3ebaba4ad64cbb11ed2c Mon Sep 17 00:00:00 2001 From: Margriet Palm Date: Fri, 17 Jan 2025 16:06:06 +0100 Subject: [PATCH 1/3] Adapt to match some name changes in threedi-schema --- CHANGES.rst | 2 +- threedi_modelchecker/checks/location.py | 10 +- threedi_modelchecker/checks/other.py | 33 ++- threedi_modelchecker/config.py | 212 +++++++++--------- threedi_modelchecker/tests/factories.py | 30 +-- .../tests/test_checks_factories.py | 16 +- .../tests/test_checks_location.py | 18 +- .../tests/test_checks_other.py | 26 +-- 8 files changed, 171 insertions(+), 176 deletions(-) diff --git a/CHANGES.rst b/CHANGES.rst index a463ef37..33c04946 100644 --- a/CHANGES.rst +++ b/CHANGES.rst @@ -4,7 +4,7 @@ Changelog of threedi-modelchecker 2.16.1 (unreleased) ------------------- -- Nothing changed yet. +- Adapt to match some name changes in threedi-schema 2.16.0 (2025-01-16) diff --git a/threedi_modelchecker/checks/location.py b/threedi_modelchecker/checks/location.py index 7f7a41a9..e69c9d4d 100644 --- a/threedi_modelchecker/checks/location.py +++ b/threedi_modelchecker/checks/location.py @@ -110,14 +110,14 @@ def description(self) -> str: return f"{self.column_name} does not start or end at its connection node (tolerance = {self.max_distance} m)" -class ControlMeasureMapLinestringMapLocationCheck(LinestringLocationCheck): +class MeasureMapLinestringMapLocationCheck(LinestringLocationCheck): def __init__(self, control_table, filters, *args, **kwargs): super().__init__( - ref_column_start=models.ControlMeasureMap.measure_location_id, - ref_column_end=models.ControlMeasureMap.control_id, - ref_table_start=models.ControlMeasureLocation, + ref_column_start=models.MeasureMap.measure_location_id, + ref_column_end=models.MeasureMap.control_id, + ref_table_start=models.MeasureLocation, ref_table_end=control_table, - column=models.ControlMeasureMap.geom, + column=models.MeasureMap.geom, filters=filters, *args, **kwargs, diff --git a/threedi_modelchecker/checks/other.py b/threedi_modelchecker/checks/other.py index 6304696a..08c23fc1 100644 --- a/threedi_modelchecker/checks/other.py +++ b/threedi_modelchecker/checks/other.py @@ -963,15 +963,15 @@ def get_invalid(self, session: Session) -> List[NamedTuple]: return invalids -class ControlTableActionTableCheckDefault(TableStrCheck): +class TableControlActionTableCheckDefault(TableStrCheck): def __init__(self, level=CheckLevel.ERROR, error_code=0): # check for action_table for action_type != set_discharge_coefficients # expected format: multiple rows, separated by \n of "val,val" super().__init__( - column=models.ControlTable.action_table, + column=models.TableControl.action_table, pattern=r"^(-?\d+(\.\d+)?,-?\d+(\.\d+)?\n?)+$", - filters=models.ControlTable.action_type - != constants.ControlTableActionTypes.set_discharge_coefficients, + filters=models.TableControl.action_type + != constants.TableControlActionTypes.set_discharge_coefficients, level=level, error_code=error_code, ) @@ -983,15 +983,15 @@ def description(self) -> str: ) -class ControlTableActionTableCheckDischargeCoefficients(TableStrCheck): +class TableControlActionTableCheckDischargeCoefficients(TableStrCheck): def __init__(self, level=CheckLevel.ERROR, error_code=0): # check for action_table for action_type = set_discharge_coefficients # expected format: multiple rows, separated by \n of "val,val val" super().__init__( - column=models.ControlTable.action_table, + column=models.TableControl.action_table, pattern=r"^(-?\d+(\.\d+)?,-?\d+(\.\d+)? -?\d+(\.\d+)?\n?)+$", - filters=models.ControlTable.action_type - == constants.ControlTableActionTypes.set_discharge_coefficients, + filters=models.TableControl.action_type + == constants.TableControlActionTypes.set_discharge_coefficients, level=level, error_code=error_code, ) @@ -1006,8 +1006,8 @@ def description(self) -> str: class ControlHasSingleMeasureVariable(BaseCheck): def __init__(self, control_model, level=CheckLevel.ERROR, error_code=0): control_type_map = { - models.ControlTable: "table", - models.ControlMemory: "memory", + models.TableControl: "table", + models.MemoryControl: "memory", } self.control_type_name = control_type_map[control_model] super().__init__( @@ -1020,17 +1020,16 @@ def get_invalid(self, session: Session) -> List[NamedTuple]: invalid = [] for record in self.to_check(session): res = ( - session.query(models.ControlMeasureMap) + session.query(models.MeasureMap) .filter( - models.ControlMeasureMap.control_type == self.control_type_name, - models.ControlMeasureMap.control_id == record.id, + models.MeasureMap.control_type == self.control_type_name, + models.MeasureMap.control_id == record.id, ) .join( - models.ControlMeasureLocation, - models.ControlMeasureMap.measure_location_id - == models.ControlMeasureLocation.id, + models.MeasureLocation, + models.MeasureMap.measure_location_id == models.MeasureLocation.id, ) - .with_entities(models.ControlMeasureLocation.measure_variable) + .with_entities(models.MeasureLocation.measure_variable) ).all() if len(res) == 0: continue diff --git a/threedi_modelchecker/config.py b/threedi_modelchecker/config.py index dade85e6..39bdc3c2 100644 --- a/threedi_modelchecker/config.py +++ b/threedi_modelchecker/config.py @@ -51,8 +51,8 @@ ) from .checks.location import ( ConnectionNodeLinestringLocationCheck, - ControlMeasureMapLinestringMapLocationCheck, DWFMapLinestringLocationCheck, + MeasureMapLinestringMapLocationCheck, PointLocationCheck, PumpMapLinestringLocationCheck, SurfaceMapLinestringLocationCheck, @@ -1112,15 +1112,15 @@ def is_none_or_empty(col): ] CHECKS += [ - ControlMeasureMapLinestringMapLocationCheck( + MeasureMapLinestringMapLocationCheck( control_table=table, - filters=models.ControlMeasureMap.control_type == control_type, + filters=models.MeasureMap.control_type == control_type, max_distance=1, error_code=205, ) for table, control_type in [ - (models.ControlTable, "table"), - (models.ControlMemory, "memory"), + (models.TableControl, "table"), + (models.MemoryControl, "memory"), ] ] @@ -1146,8 +1146,8 @@ def is_none_or_empty(col): PointLocationCheck( max_distance=TOLERANCE_M, error_code=206, - column=models.Windshielding.geom, - ref_column=models.Windshielding.channel_id, + column=models.Windshielding1D.geom, + ref_column=models.Windshielding1D.channel_id, ref_table=models.Channel, ), ] @@ -1163,13 +1163,13 @@ def is_none_or_empty(col): ) for table in [ models.BoundaryCondition1D, - models.ControlMeasureLocation, - models.Lateral1d, + models.MeasureLocation, + models.Lateral1D, models.Pump, ] ] -control_tables = [models.ControlMemory, models.ControlTable] +control_tables = [models.MemoryControl, models.TableControl] ref_tables = [ models.Pipe, models.Orifice, @@ -1188,7 +1188,7 @@ def is_none_or_empty(col): ref_table=ref_table, filters=(table.target_type == ref_table.__tablename__), ) - for table in [models.ControlMemory, models.ControlTable] + for table in [models.MemoryControl, models.TableControl] for ref_table in [ models.Channel, models.Pipe, @@ -1650,7 +1650,7 @@ def is_none_or_empty(col): (models.Interflow, models.ModelSettings.use_interflow), (models.GroundWater, models.ModelSettings.use_groundwater_flow), (models.GroundWater, models.ModelSettings.use_groundwater_storage), - (models.VegetationDrag, models.ModelSettings.use_vegetation_drag_2d), + (models.VegetationDrag2D, models.ModelSettings.use_vegetation_drag_2d), (models.Interception, models.ModelSettings.use_interception), ) ] @@ -1679,7 +1679,7 @@ def is_none_or_empty(col): models.SimpleInfiltration, models.Interflow, models.GroundWater, - models.VegetationDrag, + models.VegetationDrag2D, models.Interception, ] ] @@ -1705,7 +1705,7 @@ def is_none_or_empty(col): models.SimulationTemplateSettings.use_0d_inflow, ), ( - [models.ControlTable, models.ControlMemory], + [models.TableControl, models.MemoryControl], models.SimulationTemplateSettings.use_structure_control, ), ) @@ -2080,101 +2080,101 @@ def is_none_or_empty(col): CHECKS += [ RangeCheck( error_code=501, - column=models.VegetationDrag.vegetation_height, + column=models.VegetationDrag2D.vegetation_height, min_value=0, left_inclusive=False, ), QueryCheck( error_code=502, - column=models.VegetationDrag.vegetation_height, - invalid=Query(models.VegetationDrag).filter( - models.VegetationDrag.vegetation_height == None, - is_none_or_empty(models.VegetationDrag.vegetation_height_file), + column=models.VegetationDrag2D.vegetation_height, + invalid=Query(models.VegetationDrag2D).filter( + models.VegetationDrag2D.vegetation_height == None, + is_none_or_empty(models.VegetationDrag2D.vegetation_height_file), ), message="vegetation_drag.height must be defined.", ), QueryCheck( error_code=503, level=CheckLevel.WARNING, - column=models.VegetationDrag.vegetation_height, - invalid=Query(models.VegetationDrag).filter( - models.VegetationDrag.vegetation_height == None, - ~is_none_or_empty(models.VegetationDrag.vegetation_height_file), + column=models.VegetationDrag2D.vegetation_height, + invalid=Query(models.VegetationDrag2D).filter( + models.VegetationDrag2D.vegetation_height == None, + ~is_none_or_empty(models.VegetationDrag2D.vegetation_height_file), ), message="vegetation_drag.height is recommended as fallback value when using a vegetation_height_file.", ), RangeCheck( error_code=504, - column=models.VegetationDrag.vegetation_stem_count, + column=models.VegetationDrag2D.vegetation_stem_count, min_value=0, left_inclusive=False, ), QueryCheck( error_code=505, - column=models.VegetationDrag.vegetation_stem_count, - invalid=Query(models.VegetationDrag).filter( - models.VegetationDrag.vegetation_stem_count == None, - is_none_or_empty(models.VegetationDrag.vegetation_stem_count_file), + column=models.VegetationDrag2D.vegetation_stem_count, + invalid=Query(models.VegetationDrag2D).filter( + models.VegetationDrag2D.vegetation_stem_count == None, + is_none_or_empty(models.VegetationDrag2D.vegetation_stem_count_file), ), message="vegetation_drag.vegetation_stem_count must be defined.", ), QueryCheck( error_code=506, level=CheckLevel.WARNING, - column=models.VegetationDrag.vegetation_stem_count, - invalid=Query(models.VegetationDrag).filter( - models.VegetationDrag.vegetation_stem_count == None, - ~is_none_or_empty(models.VegetationDrag.vegetation_stem_count_file), + column=models.VegetationDrag2D.vegetation_stem_count, + invalid=Query(models.VegetationDrag2D).filter( + models.VegetationDrag2D.vegetation_stem_count == None, + ~is_none_or_empty(models.VegetationDrag2D.vegetation_stem_count_file), ), message="vegetation_drag.vegetation_stem_count is recommended as fallback value when using a vegetation_stem_count_file.", ), RangeCheck( error_code=507, - column=models.VegetationDrag.vegetation_stem_diameter, + column=models.VegetationDrag2D.vegetation_stem_diameter, min_value=0, left_inclusive=False, ), QueryCheck( error_code=508, - column=models.VegetationDrag.vegetation_stem_diameter, - invalid=Query(models.VegetationDrag).filter( - models.VegetationDrag.vegetation_stem_diameter == None, - is_none_or_empty(models.VegetationDrag.vegetation_stem_diameter_file), + column=models.VegetationDrag2D.vegetation_stem_diameter, + invalid=Query(models.VegetationDrag2D).filter( + models.VegetationDrag2D.vegetation_stem_diameter == None, + is_none_or_empty(models.VegetationDrag2D.vegetation_stem_diameter_file), ), message="vegetation_drag.vegetation_stem_diameter must be defined.", ), QueryCheck( error_code=509, level=CheckLevel.WARNING, - column=models.VegetationDrag.vegetation_stem_diameter, - invalid=Query(models.VegetationDrag).filter( - models.VegetationDrag.vegetation_stem_diameter == None, - ~is_none_or_empty(models.VegetationDrag.vegetation_stem_diameter_file), + column=models.VegetationDrag2D.vegetation_stem_diameter, + invalid=Query(models.VegetationDrag2D).filter( + models.VegetationDrag2D.vegetation_stem_diameter == None, + ~is_none_or_empty(models.VegetationDrag2D.vegetation_stem_diameter_file), ), message="vegetation_drag.vegetation_stem_diameter is recommended as fallback value when using a vegetation_stem_diameter_file.", ), RangeCheck( error_code=510, - column=models.VegetationDrag.vegetation_drag_coefficient, + column=models.VegetationDrag2D.vegetation_drag_coefficient, min_value=0, left_inclusive=False, ), QueryCheck( error_code=511, - column=models.VegetationDrag.vegetation_drag_coefficient, - invalid=Query(models.VegetationDrag).filter( - models.VegetationDrag.vegetation_drag_coefficient == None, - is_none_or_empty(models.VegetationDrag.vegetation_drag_coefficient_file), + column=models.VegetationDrag2D.vegetation_drag_coefficient, + invalid=Query(models.VegetationDrag2D).filter( + models.VegetationDrag2D.vegetation_drag_coefficient == None, + is_none_or_empty(models.VegetationDrag2D.vegetation_drag_coefficient_file), ), message="vegetation_drag.vegetation_drag_coefficient must be defined.", ), QueryCheck( error_code=512, level=CheckLevel.WARNING, - column=models.VegetationDrag.vegetation_drag_coefficient, - invalid=Query(models.VegetationDrag).filter( - models.VegetationDrag.vegetation_drag_coefficient == None, - ~is_none_or_empty(models.VegetationDrag.vegetation_drag_coefficient_file), + column=models.VegetationDrag2D.vegetation_drag_coefficient, + invalid=Query(models.VegetationDrag2D).filter( + models.VegetationDrag2D.vegetation_drag_coefficient == None, + ~is_none_or_empty(models.VegetationDrag2D.vegetation_drag_coefficient_file), ), message="vegetation_drag.vegetation_drag_coefficient is recommended as fallback value when using a vegetation_drag_coefficient_file.", ), @@ -2215,16 +2215,16 @@ def is_none_or_empty(col): CHECKS += [ RangeCheck( error_code=code, - column=models.SurfaceParameter.outflow_delay, + column=models.SurfaceParameters.outflow_delay, min_value=0, filters=CONDITIONS["has_inflow"].exists(), ) for code, column in [ - (606, models.SurfaceParameter.outflow_delay), - (607, models.SurfaceParameter.max_infiltration_capacity), - (608, models.SurfaceParameter.min_infiltration_capacity), - (609, models.SurfaceParameter.infiltration_decay_constant), - (610, models.SurfaceParameter.infiltration_recovery_constant), + (606, models.SurfaceParameters.outflow_delay), + (607, models.SurfaceParameters.max_infiltration_capacity), + (608, models.SurfaceParameters.min_infiltration_capacity), + (609, models.SurfaceParameters.infiltration_decay_constant), + (610, models.SurfaceParameters.infiltration_recovery_constant), ] ] CHECKS += [Use0DFlowCheck(error_code=611, level=CheckLevel.WARNING)] @@ -2327,10 +2327,10 @@ def is_none_or_empty(col): models.GroundWater.leakage_file, models.InitialConditions.initial_water_level_file, models.InitialConditions.initial_groundwater_level_file, - models.VegetationDrag.vegetation_height_file, - models.VegetationDrag.vegetation_stem_count_file, - models.VegetationDrag.vegetation_stem_diameter_file, - models.VegetationDrag.vegetation_drag_coefficient_file, + models.VegetationDrag2D.vegetation_height_file, + models.VegetationDrag2D.vegetation_stem_count_file, + models.VegetationDrag2D.vegetation_stem_diameter_file, + models.VegetationDrag2D.vegetation_drag_coefficient_file, ] CHECKS += [ @@ -2466,22 +2466,22 @@ def is_none_or_empty(col): ## 100xx: We continue raster checks from 1400 RasterRangeCheck( error_code=1401, - column=models.VegetationDrag.vegetation_height_file, + column=models.VegetationDrag2D.vegetation_height_file, min_value=0, ), RasterRangeCheck( error_code=1402, - column=models.VegetationDrag.vegetation_stem_count_file, + column=models.VegetationDrag2D.vegetation_stem_count_file, min_value=0, ), RasterRangeCheck( error_code=1403, - column=models.VegetationDrag.vegetation_stem_diameter_file, + column=models.VegetationDrag2D.vegetation_stem_diameter_file, min_value=0, ), RasterRangeCheck( error_code=1404, - column=models.VegetationDrag.vegetation_drag_coefficient_file, + column=models.VegetationDrag2D.vegetation_drag_coefficient_file, min_value=0, ), RasterPixelCountCheck( @@ -2508,10 +2508,10 @@ def is_none_or_empty(col): models.GroundWater.infiltration_decay_period_file, models.GroundWater.groundwater_hydraulic_conductivity_file, models.GroundWater.leakage_file, - models.VegetationDrag.vegetation_height_file, - models.VegetationDrag.vegetation_stem_count_file, - models.VegetationDrag.vegetation_stem_diameter_file, - models.VegetationDrag.vegetation_drag_coefficient_file, + models.VegetationDrag2D.vegetation_height_file, + models.VegetationDrag2D.vegetation_stem_count_file, + models.VegetationDrag2D.vegetation_stem_diameter_file, + models.VegetationDrag2D.vegetation_drag_coefficient_file, models.ModelSettings.dem_file, models.ModelSettings.friction_coefficient_file, models.InitialConditions.initial_water_level_file, @@ -2820,7 +2820,7 @@ def is_none_or_empty(col): for col in [ models.BoundaryCondition1D.timeseries, models.BoundaryConditions2D.timeseries, - models.Lateral1d.timeseries, + models.Lateral1D.timeseries, models.Lateral2D.timeseries, ] ] @@ -2829,7 +2829,7 @@ def is_none_or_empty(col): for col in [ models.BoundaryCondition1D.timeseries, models.BoundaryConditions2D.timeseries, - models.Lateral1d.timeseries, + models.Lateral1D.timeseries, models.Lateral2D.timeseries, ] ] @@ -2838,7 +2838,7 @@ def is_none_or_empty(col): for col in [ models.BoundaryCondition1D.timeseries, models.BoundaryConditions2D.timeseries, - models.Lateral1d.timeseries, + models.Lateral1D.timeseries, models.Lateral2D.timeseries, ] ] @@ -2847,7 +2847,7 @@ def is_none_or_empty(col): for col in [ models.BoundaryCondition1D.timeseries, models.BoundaryConditions2D.timeseries, - models.Lateral1d.timeseries, + models.Lateral1D.timeseries, models.Lateral2D.timeseries, ] ] @@ -2878,19 +2878,15 @@ def is_none_or_empty(col): CHECKS += [ QueryCheck( error_code=1227, - column=models.ControlMeasureMap.id, - invalid=Query(models.ControlMeasureMap).filter( + column=models.MeasureMap.id, + invalid=Query(models.MeasureMap).filter( ( - (models.ControlMeasureMap.control_type == "memory") - & models.ControlMeasureMap.control_id.not_in( - Query(models.ControlMemory.id) - ) + (models.MeasureMap.control_type == "memory") + & models.MeasureMap.control_id.not_in(Query(models.MemoryControl.id)) ) | ( - (models.ControlMeasureMap.control_type == "table") - & models.ControlMeasureMap.control_id.not_in( - Query(models.ControlTable.id) - ) + (models.MeasureMap.control_type == "table") + & models.MeasureMap.control_id.not_in(Query(models.TableControl.id)) ) ), message="control_measure_map.control_id references an id in memory_control or table_control, but the table it references does not contain an entry with that id.", @@ -2899,7 +2895,7 @@ def is_none_or_empty(col): CHECKS += [ ControlHasSingleMeasureVariable(error_code=1229, control_model=table) - for table in [models.ControlTable, models.ControlMemory] + for table in [models.TableControl, models.MemoryControl] ] @@ -3318,18 +3314,18 @@ def is_none_or_empty(col): models.Channel.exchange_type, models.Channel.connection_node_id_start, models.Channel.connection_node_id_end, - models.ControlMeasureMap.weight, - models.ControlMeasureMap.measure_location_id, - models.ControlMeasureLocation.connection_node_id, - models.ControlMeasureLocation.measure_variable, - models.ControlMemory.action_type, - models.ControlMemory.action_value_1, - models.ControlMemory.action_value_2, - models.ControlMemory.target_type, - models.ControlMemory.target_id, - models.ControlTable.action_table, - models.ControlTable.action_type, - models.ControlTable.target_type, + models.MeasureMap.weight, + models.MeasureMap.measure_location_id, + models.MeasureLocation.connection_node_id, + models.MeasureLocation.measure_variable, + models.MemoryControl.action_type, + models.MemoryControl.action_value_1, + models.MemoryControl.action_value_2, + models.MemoryControl.target_type, + models.MemoryControl.target_id, + models.TableControl.action_table, + models.TableControl.action_type, + models.TableControl.target_type, models.CrossSectionLocation.channel_id, models.CrossSectionLocation.friction_type, models.CrossSectionLocation.reference_level, @@ -3357,7 +3353,7 @@ def is_none_or_empty(col): models.Weir.connection_node_id_end, models.Weir.crest_level, models.Weir.crest_type, - models.Windshielding.channel_id, + models.Windshielding1D.channel_id, models.ModelSettings.node_open_water_detection, ] @@ -3365,11 +3361,11 @@ def is_none_or_empty(col): fk_settings = [ ForeignKeyCheckSetting(models.PumpMap.pump_id, models.Pump.id), ForeignKeyCheckSetting( - models.ControlMeasureMap.measure_location_id, models.ControlMeasureLocation.id + models.MeasureMap.measure_location_id, models.MeasureLocation.id ), ForeignKeyCheckSetting(models.SurfaceMap.surface_id, models.Surface.id), ForeignKeyCheckSetting( - models.Surface.surface_parameters_id, models.SurfaceParameter.id + models.Surface.surface_parameters_id, models.SurfaceParameters.id ), ForeignKeyCheckSetting( models.DryWeatherFlowMap.dry_weather_flow_id, models.DryWeatherFlow.id @@ -3382,7 +3378,7 @@ def is_none_or_empty(col): connection_node_fk = [ models.Pump.connection_node_id, models.PumpMap.connection_node_id_end, - models.ControlMeasureLocation.connection_node_id, + models.MeasureLocation.connection_node_id, models.Channel.connection_node_id_start, models.Channel.connection_node_id_end, models.Culvert.connection_node_id_start, @@ -3393,7 +3389,7 @@ def is_none_or_empty(col): models.Pipe.connection_node_id_end, models.Weir.connection_node_id_start, models.Weir.connection_node_id_end, - models.Lateral1d.connection_node_id, + models.Lateral1D.connection_node_id, models.BoundaryCondition1D.connection_node_id, models.DryWeatherFlowMap.connection_node_id, models.SurfaceMap.connection_node_id, @@ -3403,7 +3399,7 @@ def is_none_or_empty(col): ] channel_fk = [ models.CrossSectionLocation.channel_id, - models.Windshielding.channel_id, + models.Windshielding1D.channel_id, models.PotentialBreach.channel_id, models.ExchangeLine.channel_id, ] @@ -3416,7 +3412,7 @@ def is_none_or_empty(col): ] fk_settings += [ForeignKeyCheckSetting(col, models.Material.id) for col in material_fk] -control_tables = [models.ControlMemory, models.ControlTable] +control_tables = [models.MemoryControl, models.TableControl] ref_tables = [ models.Channel, models.Pipe, @@ -3438,14 +3434,14 @@ def is_none_or_empty(col): fk_settings += [ ForeignKeyCheckSetting( - models.ControlMeasureMap.control_id, - models.ControlMemory.id, - models.ControlMeasureMap.control_type == "memory", + models.MeasureMap.control_id, + models.MemoryControl.id, + models.MeasureMap.control_type == "memory", ), ForeignKeyCheckSetting( - models.ControlMeasureMap.control_id, - models.ControlTable.id, - models.ControlMeasureMap.control_type == "table", + models.MeasureMap.control_id, + models.TableControl.id, + models.MeasureMap.control_type == "table", ), ] diff --git a/threedi_modelchecker/tests/factories.py b/threedi_modelchecker/tests/factories.py index b496cae0..b2f089af 100644 --- a/threedi_modelchecker/tests/factories.py +++ b/threedi_modelchecker/tests/factories.py @@ -164,9 +164,9 @@ class Meta: flooding_threshold = 0.01 -class Lateral1dFactory(factory.alchemy.SQLAlchemyModelFactory): +class Lateral1DFactory(factory.alchemy.SQLAlchemyModelFactory): class Meta: - model = models.Lateral1d + model = models.Lateral1D sqlalchemy_session = None timeseries = "0,-0.1" @@ -184,9 +184,9 @@ class Meta: type = constants.Later2dType.SURFACE -class SurfaceParameterFactory(factory.alchemy.SQLAlchemyModelFactory): +class SurfaceParametersFactory(factory.alchemy.SQLAlchemyModelFactory): class Meta: - model = models.SurfaceParameter + model = models.SurfaceParameters sqlalchemy_session = None outflow_delay = 10.0 @@ -251,12 +251,12 @@ class Meta: sqlalchemy_session = None -class ControlTableFactory(factory.alchemy.SQLAlchemyModelFactory): +class TableControlFactory(factory.alchemy.SQLAlchemyModelFactory): class Meta: - model = models.ControlTable + model = models.TableControl sqlalchemy_session = None - action_type = constants.ControlTableActionTypes.set_discharge_coefficients + action_type = constants.TableControlActionTypes.set_discharge_coefficients action_table = "0.0,-1.0 2.0\n1.0,-1.1 2.1" measure_operator = constants.MeasureOperators.greater_than target_type = constants.StructureControlTypes.channel @@ -264,12 +264,12 @@ class Meta: geom = DEFAULT_POINT -class ControlMemoryFactory(factory.alchemy.SQLAlchemyModelFactory): +class MemoryControlFactory(factory.alchemy.SQLAlchemyModelFactory): class Meta: - model = models.ControlMemory + model = models.MemoryControl sqlalchemy_session = None - action_type = constants.ControlTableActionTypes.set_discharge_coefficients + action_type = constants.TableControlActionTypes.set_discharge_coefficients action_value_1 = 0.0 action_value_2 = -1.0 target_type = constants.StructureControlTypes.channel @@ -281,18 +281,18 @@ class Meta: geom = DEFAULT_POINT -class ControlMeasureMapFactory(factory.alchemy.SQLAlchemyModelFactory): +class MeasureMapFactory(factory.alchemy.SQLAlchemyModelFactory): class Meta: - model = models.ControlMeasureMap + model = models.MeasureMap sqlalchemy_session = None control_type = constants.MeasureVariables.waterlevel geom = DEFAULT_LINE -class ControlMeasureLocationFactory(factory.alchemy.SQLAlchemyModelFactory): +class MeasureLocationFactory(factory.alchemy.SQLAlchemyModelFactory): class Meta: - model = models.ControlMeasureLocation + model = models.MeasureLocation sqlalchemy_session = None geom = DEFAULT_POINT @@ -327,7 +327,7 @@ class Meta: class VegetationDragFactory(factory.alchemy.SQLAlchemyModelFactory): class Meta: - model = models.VegetationDrag + model = models.VegetationDrag2D sqlalchemy_session = None vegetation_height = 1.0 diff --git a/threedi_modelchecker/tests/test_checks_factories.py b/threedi_modelchecker/tests/test_checks_factories.py index adbf9755..ddc6e11b 100644 --- a/threedi_modelchecker/tests/test_checks_factories.py +++ b/threedi_modelchecker/tests/test_checks_factories.py @@ -17,12 +17,12 @@ def test_gen_foreign_key_checks_no_filter(): settings = [ ForeignKeyCheckSetting( - models.Surface.surface_parameters_id, models.SurfaceParameter.id + models.Surface.surface_parameters_id, models.SurfaceParameters.id ), ForeignKeyCheckSetting( - models.ControlMemory.target_id, + models.MemoryControl.target_id, models.Channel.id, - models.ControlMemory.target_type == "channel", + models.MemoryControl.target_type == "channel", ), ] foreign_key_checks = generate_foreign_key_checks( @@ -31,22 +31,22 @@ def test_gen_foreign_key_checks_no_filter(): assert len(foreign_key_checks) == 1 fk_check = foreign_key_checks[0] assert models.Surface.surface_parameters_id == fk_check.column - assert models.SurfaceParameter.id == fk_check.reference_column + assert models.SurfaceParameters.id == fk_check.reference_column def test_gen_foreign_key_checks_filter(): settings = [ ForeignKeyCheckSetting( - models.Surface.surface_parameters_id, models.SurfaceParameter.id + models.Surface.surface_parameters_id, models.SurfaceParameters.id ), ForeignKeyCheckSetting( - models.ControlMemory.target_id, + models.MemoryControl.target_id, models.Channel.id, - models.ControlMemory.target_type == "channel", + models.MemoryControl.target_type == "channel", ), ] foreign_key_checks = generate_foreign_key_checks( - models.ControlMemory.__table__, fk_settings=settings + models.MemoryControl.__table__, fk_settings=settings ) assert len(foreign_key_checks) == 1 fk_check = foreign_key_checks[0] diff --git a/threedi_modelchecker/tests/test_checks_location.py b/threedi_modelchecker/tests/test_checks_location.py index 668f0460..235971dd 100644 --- a/threedi_modelchecker/tests/test_checks_location.py +++ b/threedi_modelchecker/tests/test_checks_location.py @@ -3,9 +3,9 @@ from threedi_modelchecker.checks.location import ( ConnectionNodeLinestringLocationCheck, - ControlMeasureMapLinestringMapLocationCheck, DWFMapLinestringLocationCheck, LinestringLocationCheck, + MeasureMapLinestringMapLocationCheck, PointLocationCheck, PumpMapLinestringLocationCheck, SurfaceMapLinestringLocationCheck, @@ -95,29 +95,29 @@ def test_connection_node_linestring_location_check(session, channel_geom, nof_in ) @pytest.mark.parametrize( "control_table, control_type", - [(models.ControlMemory, "memory"), (models.ControlTable, "table")], + [(models.MemoryControl, "memory"), (models.TableControl, "table")], ) def test_control_measure_map_linestring_map_location_check( session, control_table, control_type, channel_geom, nof_invalid ): - factories.ControlMeasureLocationFactory(id=1, geom=f"SRID={SRID};POINT({POINT1})") - factories.ControlMemoryFactory(id=1, geom=f"SRID={SRID};POINT({POINT3})") - factories.ControlTableFactory(id=1, geom=f"SRID={SRID};POINT({POINT3})") - factories.ControlMeasureMapFactory( + factories.MeasureLocationFactory(id=1, geom=f"SRID={SRID};POINT({POINT1})") + factories.MemoryControlFactory(id=1, geom=f"SRID={SRID};POINT({POINT3})") + factories.TableControlFactory(id=1, geom=f"SRID={SRID};POINT({POINT3})") + factories.MeasureMapFactory( measure_location_id=1, control_id=1, control_type="memory", geom=f"SRID={SRID};{channel_geom}", ) - factories.ControlMeasureMapFactory( + factories.MeasureMapFactory( measure_location_id=1, control_id=1, control_type="table", geom=f"SRID={SRID};{channel_geom}", ) - errors = ControlMeasureMapLinestringMapLocationCheck( + errors = MeasureMapLinestringMapLocationCheck( control_table=control_table, - filters=models.ControlMeasureMap.control_type == control_type, + filters=models.MeasureMap.control_type == control_type, max_distance=1.01, ).get_invalid(session) assert len(errors) == nof_invalid diff --git a/threedi_modelchecker/tests/test_checks_other.py b/threedi_modelchecker/tests/test_checks_other.py index 04038e17..0b40e0cc 100644 --- a/threedi_modelchecker/tests/test_checks_other.py +++ b/threedi_modelchecker/tests/test_checks_other.py @@ -13,8 +13,6 @@ ConnectionNodesDistance, ConnectionNodesLength, ControlHasSingleMeasureVariable, - ControlTableActionTableCheckDefault, - ControlTableActionTableCheckDischargeCoefficients, CorrectAggregationSettingsExist, CrossSectionSameConfigurationCheck, DefinedAreaCheck, @@ -34,6 +32,8 @@ PumpStorageTimestepCheck, SpatialIndexCheck, SurfaceNodeInflowAreaCheck, + TableControlActionTableCheckDefault, + TableControlActionTableCheckDischargeCoefficients, TagsValidCheck, Use0DFlowCheck, UsedSettingsPresentCheck, @@ -749,7 +749,7 @@ def test_used_settings_present_check_single_table(session, use_setting, add_sett factories.VegetationDragFactory() check = UsedSettingsPresentCheckSingleTable( column=models.ModelSettings.use_vegetation_drag_2d, - settings_table=models.VegetationDrag, + settings_table=models.VegetationDrag2D, ) assert len(check.get_invalid(session)) == nof_invalid_expected @@ -812,11 +812,11 @@ def test_tags_valid(session): ], ) def test_control_table_action_table_check_default(session, action_table, valid): - factories.ControlTableFactory( + factories.TableControlFactory( action_table=action_table, - action_type=constants.ControlTableActionTypes.set_capacity, + action_type=constants.TableControlActionTypes.set_capacity, ) - check = ControlTableActionTableCheckDefault() + check = TableControlActionTableCheckDefault() assert (len(check.get_invalid(session)) == 0) == valid @@ -839,11 +839,11 @@ def test_control_table_action_table_check_default(session, action_table, valid): def test_control_table_action_table_check_discharge_coefficients( session, action_table, valid ): - factories.ControlTableFactory( + factories.TableControlFactory( action_table=action_table, - action_type=constants.ControlTableActionTypes.set_discharge_coefficients, + action_type=constants.TableControlActionTypes.set_discharge_coefficients, ) - check = ControlTableActionTableCheckDischargeCoefficients() + check = TableControlActionTableCheckDischargeCoefficients() assert (len(check.get_invalid(session)) == 0) == valid @@ -864,13 +864,13 @@ def test_control_table_action_table_check_discharge_coefficients( ], ) def test_control_has_single_measure_variable(session, measure_variables, valid): - factories.ControlTableFactory(id=1) + factories.TableControlFactory(id=1) for i, measure_variable in enumerate(measure_variables, 1): - factories.ControlMeasureMapFactory( + factories.MeasureMapFactory( control_id=1, measure_location_id=i, control_type="table" ) - factories.ControlMeasureLocationFactory(id=i, measure_variable=measure_variable) - check = ControlHasSingleMeasureVariable(control_model=models.ControlTable) + factories.MeasureLocationFactory(id=i, measure_variable=measure_variable) + check = ControlHasSingleMeasureVariable(control_model=models.TableControl) invalids = check.get_invalid(session) assert (len(invalids) == 0) == valid From d5e7ea17913f16cf55bd93baff535eda52c42d01 Mon Sep 17 00:00:00 2001 From: Margriet Palm Date: Mon, 20 Jan 2025 09:20:20 +0100 Subject: [PATCH 2/3] Set correct threedi-schema version --- pyproject.toml | 3 ++- 1 file changed, 2 insertions(+), 1 deletion(-) diff --git a/pyproject.toml b/pyproject.toml index 95c5902c..7206b9f1 100644 --- a/pyproject.toml +++ b/pyproject.toml @@ -20,7 +20,8 @@ dependencies = [ "GeoAlchemy2>=0.9,!=0.11.*", "SQLAlchemy>=1.4", "pyproj", - "threedi-schema==0.230.*" +# "threedi-schema==0.230.*" + "threedi-schema @ git+ssh://git@github.com/nens/threedi-schema@margriet_119_orm_class_names" ] [project.optional-dependencies] From 09f8737261dfc76310f8b172f175d1d6cb99ff37 Mon Sep 17 00:00:00 2001 From: Margriet Palm Date: Mon, 20 Jan 2025 09:28:35 +0100 Subject: [PATCH 3/3] Change threedi-schema dep --- pyproject.toml | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-) diff --git a/pyproject.toml b/pyproject.toml index 7206b9f1..c7ca86c5 100644 --- a/pyproject.toml +++ b/pyproject.toml @@ -20,8 +20,8 @@ dependencies = [ "GeoAlchemy2>=0.9,!=0.11.*", "SQLAlchemy>=1.4", "pyproj", + "threedi-schema @ https://github.com/nens/threedi-schema/archive/margriet_119_orm_class_names.zip" # "threedi-schema==0.230.*" - "threedi-schema @ git+ssh://git@github.com/nens/threedi-schema@margriet_119_orm_class_names" ] [project.optional-dependencies]