From 694897eabbd9b52040cf8f59f646a6967b3f40f1 Mon Sep 17 00:00:00 2001 From: Sahas Subramanian Date: Tue, 10 Dec 2024 13:12:37 +0100 Subject: [PATCH 1/2] Rename old `energy` test functions to `power` Signed-off-by: Sahas Subramanian --- tests/test_types.py | 8 ++++---- 1 file changed, 4 insertions(+), 4 deletions(-) diff --git a/tests/test_types.py b/tests/test_types.py index 5230cc4e..efda6e30 100644 --- a/tests/test_types.py +++ b/tests/test_types.py @@ -315,8 +315,8 @@ def test_price_from_pb() -> None: ) -def test_energy_to_pb() -> None: - """Test the client energy type conversions to protobuf.""" +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")), @@ -324,8 +324,8 @@ def test_energy_to_pb() -> None: ) -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")), From e17ed8ea5e49bc72f1762cf178da37b7919019b6 Mon Sep 17 00:00:00 2001 From: Sahas Subramanian Date: Tue, 10 Dec 2024 13:26:22 +0100 Subject: [PATCH 2/2] Add tests for `str` formatting of `Price` and `Power` types Signed-off-by: Sahas Subramanian --- tests/test_types.py | 24 ++++++++++++++++++++++++ 1 file changed, 24 insertions(+) diff --git a/tests/test_types.py b/tests/test_types.py index efda6e30..e30d6c6f 100644 --- a/tests/test_types.py +++ b/tests/test_types.py @@ -315,6 +315,18 @@ def test_price_from_pb() -> None: ) +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( @@ -333,6 +345,18 @@ def test_power_from_pb() -> None: ) +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(