From 020efc26b1aedb219ae336b1194fbea88819e0b1 Mon Sep 17 00:00:00 2001 From: Daley Adrichem Date: Fri, 9 Feb 2024 12:01:17 +0100 Subject: [PATCH] Fix black --- flood_adapt/object_model/interface/measures.py | 3 ++- flood_adapt/object_model/io/unitfulvalue.py | 3 ++- tests/test_object_model/interface/test_measures.py | 5 ++--- tests/test_object_model/interface/test_unitfulvalue.py | 2 +- 4 files changed, 7 insertions(+), 6 deletions(-) diff --git a/flood_adapt/object_model/interface/measures.py b/flood_adapt/object_model/interface/measures.py index 2c3587e09..b1c948757 100644 --- a/flood_adapt/object_model/interface/measures.py +++ b/flood_adapt/object_model/interface/measures.py @@ -181,7 +181,8 @@ def validate_hazard_type_values(self) -> "GreenInfrastructureModel": return self elif self.type == HazardType.greening: if not isinstance(self.height, UnitfulHeight) or not isinstance( - self.percent_area, float): + self.percent_area, float + ): raise ValueError( "Height and percent_area needs to be set for greening type measures" ) diff --git a/flood_adapt/object_model/io/unitfulvalue.py b/flood_adapt/object_model/io/unitfulvalue.py index 72163700b..ab2c594c6 100644 --- a/flood_adapt/object_model/io/unitfulvalue.py +++ b/flood_adapt/object_model/io/unitfulvalue.py @@ -109,11 +109,12 @@ def convert(self, new_units: UnitTypesLength) -> float: class UnitfulHeight(UnitfulLength): """A special type of length that is always positive and non-zero. Used for heights.""" + value: float = Field(..., gt=0) @root_validator(pre=True) def convert_length_to_height(cls, obj): - if isinstance(obj, UnitfulLength): + if isinstance(obj, UnitfulLength): return UnitfulHeight(value=obj.value, units=obj.units) return obj diff --git a/tests/test_object_model/interface/test_measures.py b/tests/test_object_model/interface/test_measures.py index ff45e47d0..78f9caa9a 100644 --- a/tests/test_object_model/interface/test_measures.py +++ b/tests/test_object_model/interface/test_measures.py @@ -286,9 +286,8 @@ def test_green_infrastructure_model_other_measure_type(self): ) # Assert - assert ( - "GreenInfrastructureModel\n Value error, Type must be one of " - in str(excinfo.value) + assert "GreenInfrastructureModel\n Value error, Type must be one of " in str( + excinfo.value ) @pytest.mark.parametrize( diff --git a/tests/test_object_model/interface/test_unitfulvalue.py b/tests/test_object_model/interface/test_unitfulvalue.py index 2cac32a42..e32b1f563 100644 --- a/tests/test_object_model/interface/test_unitfulvalue.py +++ b/tests/test_object_model/interface/test_unitfulvalue.py @@ -135,7 +135,7 @@ def test_unitfulHeight_setUnit_invalidUnits(self): with pytest.raises(ValueError) as excinfo: UnitfulHeight(value=10, units="invalid_units") assert "UnitfulHeight\nunits\n Input should be " in str(excinfo.value) - + class TestUnitfulArea: def test_unitfulArea_convertM2ToCM2_correct(self):