Skip to content

Commit

Permalink
Adjust factory to handle str and int (#365)
Browse files Browse the repository at this point in the history
  • Loading branch information
Pasarus authored Feb 18, 2025
1 parent 1d0491f commit 1ff989f
Show file tree
Hide file tree
Showing 2 changed files with 15 additions and 2 deletions.
4 changes: 2 additions & 2 deletions rundetection/rules/factory.py
Original file line number Diff line number Diff line change
Expand Up @@ -45,8 +45,8 @@ def rule_factory(key_: str, value: T) -> Rule[Any]: # noqa: C901, PLR0911, PLR0
if isinstance(value, str):
return MariMaskFileRule(value)
case "mariwbvan":
if isinstance(value, int):
return MariWBVANRule(value)
if isinstance(value, int | str):
return MariWBVANRule(int(value))
case "osiriscalibfilesandreflection":
if isinstance(value, dict):
return OsirisReflectionCalibrationRule(value)
Expand Down
13 changes: 13 additions & 0 deletions test/rules/test_factory.py
Original file line number Diff line number Diff line change
Expand Up @@ -71,6 +71,19 @@ def test_rule_factory_returns_correct_rule(rule_key, rule_value, expected_rule):
assert_correct_rule(rule_key, rule_value, expected_rule)


def test_mariwbvan_rule_factory_returns_correct_rule_int_and_str():
"""
Test to ensure that the rule factory returns the correct Rule for MariWBVAN when using either a str or int to create
the rule from the specification.
"""
rule = rule_factory("mariwbvan", 12345)
assert isinstance(rule, MariWBVANRule)
assert rule._value == 12345 # noqa: PLR2004
rule = rule_factory("mariwbvan", "12345")
assert isinstance(rule, MariWBVANRule)
assert rule._value == 12345 # noqa: PLR2004


def test_raises_exception_for_missing_rule_class() -> None:
"""
Test exception raised when non-existent rule name is given
Expand Down

0 comments on commit 1ff989f

Please sign in to comment.