Skip to content

Commit

Permalink
Check groove parameters (#306)
Browse files Browse the repository at this point in the history
* check for positive parameters in IsoBaseGroove

* add test and update get_groove docstring

* update CHANGELOG.md
  • Loading branch information
CagtayFabry authored Mar 29, 2021
1 parent 616584b commit 7f015c0
Show file tree
Hide file tree
Showing 3 changed files with 24 additions and 0 deletions.
3 changes: 3 additions & 0 deletions CHANGELOG.md
Original file line number Diff line number Diff line change
Expand Up @@ -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)

Expand Down
10 changes: 10 additions & 0 deletions tests/asdf_tests/test_asdf_groove.py
Original file line number Diff line number Diff line change
Expand Up @@ -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
Expand Down
11 changes: 11 additions & 0 deletions weldx/welding/groove/iso_9692_1.py
Original file line number Diff line number Diff line change
Expand Up @@ -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)}
Expand Down Expand Up @@ -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
Expand Down

0 comments on commit 7f015c0

Please sign in to comment.