Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

fix: remove constraints for value of Impedance and Admittance #117

Merged
merged 2 commits into from
Feb 14, 2024
Merged
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
37 changes: 19 additions & 18 deletions pdm.lock

Some generated files are not rendered by default. Learn more about how customized files appear on GitHub.

17 changes: 15 additions & 2 deletions psdm/quantities/multi_phase.py
Original file line number Diff line number Diff line change
Expand Up @@ -153,8 +153,6 @@ def check_unit(cls, v: Unit) -> Unit:
class Impedance(MultiPhaseQuantity):
"""Natural impedance."""

value: NonEmptyTuple[pydantic.confloat(ge=0)] # type: ignore[valid-type]

precision: int = Precision.IMPEDANCE
unit: Unit = Unit.OHM

Expand All @@ -167,6 +165,21 @@ def check_unit(cls, v: Unit) -> Unit:
return v


class Admittance(MultiPhaseQuantity):
"""Natural admittance."""

precision: int = Precision.ADMITTANCE
unit: Unit = Unit.SIEMENS

@pydantic.field_validator("unit")
def check_unit(cls, v: Unit) -> Unit:
if v is not Unit.SIEMENS.value:
msg = "Input should be Unit.SIEMENS."
raise ValueError(msg)

return v


class Power(MultiPhaseQuantity):
"""Base class for power quantities.

Expand Down
8 changes: 0 additions & 8 deletions psdm/quantities/single_phase.py
Original file line number Diff line number Diff line change
Expand Up @@ -108,7 +108,6 @@ class Impedance(SinglePhaseQuantity):
"""Impedance."""

system_type: SystemType = SystemType.NATURAL
value: pydantic.confloat(ge=0) # type: ignore[valid-type]
precision: int = Precision.IMPEDANCE
unit: Unit = Unit.OHM

Expand Down Expand Up @@ -138,7 +137,6 @@ def check_system_type(cls, v: SystemType) -> SystemType:
class ImpedanceNegSeq(Impedance):
"""Negative sequence impedance."""

value: pydantic.confloat(ge=0) # type: ignore[valid-type]
system_type: SystemType = SystemType.NEGATIVE_SEQUENCE

@pydantic.field_validator("system_type")
Expand All @@ -153,7 +151,6 @@ def check_system_type(cls, v: SystemType) -> SystemType:
class ImpedanceZerSeq(Impedance):
"""Zero sequence impedance."""

value: pydantic.confloat(ge=0) # type: ignore[valid-type]
system_type: SystemType = SystemType.ZERO_SEQUENCE

@pydantic.field_validator("system_type")
Expand All @@ -168,7 +165,6 @@ def check_system_type(cls, v: SystemType) -> SystemType:
class ImpedanceNat(Impedance):
"""Natural impedance."""

value: pydantic.confloat(ge=0) # type: ignore[valid-type]
system_type: SystemType = SystemType.NATURAL

@pydantic.field_validator("system_type")
Expand All @@ -183,7 +179,6 @@ def check_system_type(cls, v: SystemType) -> SystemType:
class Admittance(SinglePhaseQuantity):
"""Admittance."""

value: pydantic.confloat(ge=0) # type: ignore[valid-type]
precision: int = Precision.ADMITTANCE
unit: Unit = Unit.SIEMENS

Expand All @@ -199,7 +194,6 @@ def check_unit(cls, v: Unit) -> Unit:
class AdmittancePosSeq(Admittance):
"""Positive sequence admittance."""

value: pydantic.confloat(ge=0) # type: ignore[valid-type]
system_type: SystemType = SystemType.POSITIVE_SEQUENCE

@pydantic.field_validator("system_type")
Expand All @@ -214,7 +208,6 @@ def check_system_type(cls, v: SystemType) -> SystemType:
class AdmittanceNegSeq(Admittance):
"""Negative sequence admittance."""

value: pydantic.confloat(ge=0) # type: ignore[valid-type]
system_type: SystemType = SystemType.NEGATIVE_SEQUENCE

@pydantic.field_validator("system_type")
Expand All @@ -229,7 +222,6 @@ def check_system_type(cls, v: SystemType) -> SystemType:
class AdmittanceZerSeq(Admittance):
"""Zero sequence admittance."""

value: pydantic.confloat(ge=0) # type: ignore[valid-type]
system_type: SystemType = SystemType.ZERO_SEQUENCE

@pydantic.field_validator("system_type")
Expand Down
4 changes: 2 additions & 2 deletions tests/test_multi_phase_quantities.py
Original file line number Diff line number Diff line change
Expand Up @@ -153,9 +153,9 @@ class TestImpedance:
((0, 0, 0), True, does_not_raise()),
((1, 1, 1), True, does_not_raise()),
((2, 1, 1), False, does_not_raise()),
((-2, 1, 1), False, does_not_raise()),
((1, 1, 1), False, pytest.raises(AssertionError)),
((-2, 1, 1), True, pytest.raises(pydantic.ValidationError)),
((-2, 1, 1), False, pytest.raises(pydantic.ValidationError)),
((-2, 1, 1), True, pytest.raises(AssertionError)),
((2, 1, 1), True, pytest.raises(AssertionError)),
],
)
Expand Down
20 changes: 10 additions & 10 deletions tests/test_single_phase_quantities.py
Original file line number Diff line number Diff line change
Expand Up @@ -56,7 +56,7 @@ class TestImpedance:
[
(0, does_not_raise()),
(1, does_not_raise()),
(-2, pytest.raises(pydantic.ValidationError)),
(-2, does_not_raise()),
],
)
def test_init(
Expand All @@ -68,7 +68,7 @@ def test_init(
Impedance(value=value, system_type=SystemType.NATURAL)


class TestImpedancePS:
class TestImpedancePosSeq:
@pytest.mark.parametrize(
(
"value",
Expand All @@ -77,7 +77,7 @@ class TestImpedancePS:
[
(0, does_not_raise()),
(1, does_not_raise()),
(-2, pytest.raises(pydantic.ValidationError)),
(-2, does_not_raise()),
],
)
def test_init(
Expand All @@ -90,7 +90,7 @@ def test_init(
assert i.system_type == SystemType.POSITIVE_SEQUENCE.value


class TestImpedanceNS:
class TestImpedanceNegSeq:
@pytest.mark.parametrize(
(
"value",
Expand All @@ -99,7 +99,7 @@ class TestImpedanceNS:
[
(0, does_not_raise()),
(1, does_not_raise()),
(-2, pytest.raises(pydantic.ValidationError)),
(-2, does_not_raise()),
],
)
def test_init(
Expand All @@ -112,7 +112,7 @@ def test_init(
assert i.system_type == SystemType.NEGATIVE_SEQUENCE.value


class TestImpedanceZS:
class TestImpedanceZerSeq:
@pytest.mark.parametrize(
(
"value",
Expand All @@ -121,7 +121,7 @@ class TestImpedanceZS:
[
(0, does_not_raise()),
(1, does_not_raise()),
(-2, pytest.raises(pydantic.ValidationError)),
(-2, does_not_raise()),
],
)
def test_init(
Expand All @@ -134,7 +134,7 @@ def test_init(
assert i.system_type == SystemType.ZERO_SEQUENCE.value


class TestImpedanceN:
class TestImpedanceNat:
@pytest.mark.parametrize(
(
"value",
Expand All @@ -143,7 +143,7 @@ class TestImpedanceN:
[
(0, does_not_raise()),
(1, does_not_raise()),
(-2, pytest.raises(pydantic.ValidationError)),
(-2, does_not_raise()),
],
)
def test_init(
Expand All @@ -165,7 +165,7 @@ class TestAdmittance:
[
(0, does_not_raise()),
(1, does_not_raise()),
(-2, pytest.raises(pydantic.ValidationError)),
(-2, does_not_raise()),
],
)
def test_init(
Expand Down