Skip to content

Commit

Permalink
refactor: incorporate Sourcery AI suggestions
Browse files Browse the repository at this point in the history
  • Loading branch information
weibullguy committed Oct 12, 2024
1 parent 6d325b7 commit 8dc324b
Show file tree
Hide file tree
Showing 3 changed files with 14 additions and 5 deletions.
2 changes: 2 additions & 0 deletions pyproject.toml
Original file line number Diff line number Diff line change
Expand Up @@ -102,6 +102,8 @@ dependencies = [

[tool.hatch.envs.test.scripts]
install = "make PREFIX=$VIRTUAL_ENV install"
devinstall = "pip install -U pip && pip install -e ."
dotest = "pytest {args}"
clean-test = "rm -f .coverage* cobertura.xml && rm -fr .pytest_cache"
run-unit = "pytest -m unit --no-cov --cache-clear tests"
run-integration = "pytest -m integration --no-cov --cache-clear tests"
Expand Down
6 changes: 5 additions & 1 deletion src/ramstk/analyses/fha.py
Original file line number Diff line number Diff line change
Expand Up @@ -69,7 +69,11 @@ def calculate_hri(probability: str, severity: str) -> int:
return PROBABILITY[probability] * SEVERITY[severity]
except KeyError as _error:
raise OutOfRangeError(
(f"Unknown hazard probability ({probability}) or severity ({severity}).")
(
f"Invalid hazard input: probability ({probability}) or severity "
f"({severity}) not recognized. Expected ranges: probability 1-5, "
f"severity I-IV."
)
) from _error


Expand Down
11 changes: 7 additions & 4 deletions tests/analyses/test_fha.py
Original file line number Diff line number Diff line change
Expand Up @@ -59,7 +59,8 @@ def test_calculate_hri_unknown_probability():
with pytest.raises(OutOfRangeError) as e:
fha.calculate_hri("shibboly-biboly-boo", "Medium")
assert e.value.args[0] == (
"Unknown hazard probability (shibboly-biboly-boo) or severity (Medium)."
"Invalid hazard input: probability (shibboly-biboly-boo) or severity (Medium) "
"not recognized. Expected ranges: probability 1-5, severity I-IV."
)


Expand All @@ -71,7 +72,9 @@ def test_calculate_hri_unknown_severity():
with pytest.raises(OutOfRangeError) as e:
fha.calculate_hri("Level A - Frequent", "shibboly-biboly-boo")
assert e.value.args[0] == (
"Unknown hazard probability (Level A - Frequent) or severity (shibboly-biboly-boo)."
"Invalid hazard input: probability (Level A - Frequent) or severity "
"(shibboly-biboly-boo) not recognized. Expected ranges: probability 1-5, "
"severity I-IV."
)


Expand Down Expand Up @@ -242,9 +245,9 @@ def test_calculate_hri_non_string_input():
@pytest.mark.unit
@pytest.mark.calculation
def test_set_user_defined_function_invalid_equation():
"""calculate_user_defined() should raise a SympifyError for invalid equations."""
"""calculate_user_defined() should raise a ValueError for invalid equations."""
with pytest.raises(ValueError):
_fha = fha.set_user_defined_functions(TEST_FHA, ["uf1+uf2", "invalid_equation"])
fha.set_user_defined_functions(TEST_FHA, ["uf1+uf2", "invalid_equation"])


@pytest.mark.unit
Expand Down

0 comments on commit 8dc324b

Please sign in to comment.