diff --git a/CHANGELOG.md b/CHANGELOG.md index 4245aaa8a..338f58e07 100644 --- a/CHANGELOG.md +++ b/CHANGELOG.md @@ -16,6 +16,9 @@ - add validators to `rotation-1.0.0.yaml` & `gas_component-1.0.0.yaml` [[#303]](https://github.com/BAMWelDX/weldx/pull/303) +### fixes + +- prevent creation of `IsoBaseGroove` with negative parameters [[#306]](https://github.com/BAMWelDX/weldx/pull/306) ## 0.3.1 (21.03.2021) diff --git a/tests/asdf_tests/test_asdf_groove.py b/tests/asdf_tests/test_asdf_groove.py index e883583c8..29902a2f4 100644 --- a/tests/asdf_tests/test_asdf_groove.py +++ b/tests/asdf_tests/test_asdf_groove.py @@ -94,6 +94,16 @@ def test_asdf_groove_exceptions(): code_number="6.1.1", ).to_profile() + # negative parameter value + with pytest.raises(ValueError): + get_groove( + groove_type="VGroove", + workpiece_thickness=Q_(9, "mm"), + groove_angle=Q_(50, "deg"), + root_face=Q_(-4, "mm"), + root_gap=Q_(2, "mm"), + ) + @pytest.mark.parametrize("groove", test_params.values(), ids=test_params.keys()) def test_cross_section(groove): # noqa diff --git a/weldx/welding/groove/iso_9692_1.py b/weldx/welding/groove/iso_9692_1.py index c3264b9d1..d70c5f2c5 100644 --- a/weldx/welding/groove/iso_9692_1.py +++ b/weldx/welding/groove/iso_9692_1.py @@ -81,6 +81,12 @@ class IsoBaseGroove(metaclass=abc.ABCMeta): _AREA_RASTER_WIDTH = 0.1 """steers the area approximation of the groove in ~cross_sect_area.""" + def __post_init__(self): + """Make sure all parameters are valid after class init.""" + for key, value in self.parameters().items(): + if value < 0.0: + raise ValueError(f"Invalid value for parameter {key}={value:~}") + def parameters(self): """Return groove parameters as dictionary of quantities.""" return {k: v for k, v in self.__dict__.items() if isinstance(v, pint.Quantity)} @@ -1719,6 +1725,11 @@ def get_groove( root_face=Q_(3, "mm"), root_gap=Q_(1, "mm")) + Raises + ------ + ValueError + When passing negative parameter values. + Notes ----- Each groove type has a different set of attributes which are required. Only