Skip to content

Commit

Permalink
Add tests for str formatting of Price and Power types (#81)
Browse files Browse the repository at this point in the history
  • Loading branch information
shsms authored Dec 10, 2024
2 parents 779b3a5 + e17ed8e commit bd9e52d
Showing 1 changed file with 28 additions and 4 deletions.
32 changes: 28 additions & 4 deletions tests/test_types.py
Original file line number Diff line number Diff line change
Expand Up @@ -315,24 +315,48 @@ def test_price_from_pb() -> None:
)


def test_energy_to_pb() -> None:
"""Test the client energy type conversions to protobuf."""
def test_price_formatting() -> None:
"""Test the client price type formatting."""
price = Price(amount=Decimal("800"), currency=Currency.JPY)
assert str(price) == "800 JPY"
price = Price(amount=Decimal("-100.3"), currency=Currency.CHF)
assert str(price) == "-100.3 CHF"
price = Price(amount=Decimal("-103.00"), currency=Currency.USD)
assert str(price) == "-103.00 USD"
price = Price(amount=Decimal("400.123"), currency=Currency.EUR)
assert str(price) == "400.123 EUR"


def test_power_to_pb() -> None:
"""Test the client power type conversions to protobuf."""
assert_conversion_to_pb(
original=Power(mw=Decimal("5")),
expected_pb=power_pb2.Power(mw=decimal_pb2.Decimal(value="5")),
assert_func=assert_equal,
)


def test_energy_from_pb() -> None:
"""Test the client energy type conversions from protobuf."""
def test_power_from_pb() -> None:
"""Test the client power type conversions from protobuf."""
assert_conversion_from_pb(
original_pb=power_pb2.Power(mw=decimal_pb2.Decimal(value="5")),
expected=Power(mw=Decimal("5")),
assert_func=assert_equal,
)


def test_power_formatting() -> None:
"""Test the client power type formatting."""
power = Power(mw=Decimal("5"))
assert str(power) == "5 MW"
power = Power(mw=Decimal("5.1"))
assert str(power) == "5.1 MW"
power = Power(mw=Decimal("5.100"))
assert str(power) == "5.100 MW"
power = Power(mw=Decimal("-5.123"))
assert str(power) == "-5.123 MW"


def test_delivery_duration_to_pb() -> None:
"""Test the client delivery duration type conversions to protobuf."""
assert_conversion_to_pb(
Expand Down

0 comments on commit bd9e52d

Please sign in to comment.