Skip to content

Commit e17ed8e

Browse files
committed
Add tests for str formatting of Price and Power types
Signed-off-by: Sahas Subramanian <[email protected]>
1 parent 694897e commit e17ed8e

File tree

1 file changed

+24
-0
lines changed

1 file changed

+24
-0
lines changed

tests/test_types.py

Lines changed: 24 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -315,6 +315,18 @@ def test_price_from_pb() -> None:
315315
)
316316

317317

318+
def test_price_formatting() -> None:
319+
"""Test the client price type formatting."""
320+
price = Price(amount=Decimal("800"), currency=Currency.JPY)
321+
assert str(price) == "800 JPY"
322+
price = Price(amount=Decimal("-100.3"), currency=Currency.CHF)
323+
assert str(price) == "-100.3 CHF"
324+
price = Price(amount=Decimal("-103.00"), currency=Currency.USD)
325+
assert str(price) == "-103.00 USD"
326+
price = Price(amount=Decimal("400.123"), currency=Currency.EUR)
327+
assert str(price) == "400.123 EUR"
328+
329+
318330
def test_power_to_pb() -> None:
319331
"""Test the client power type conversions to protobuf."""
320332
assert_conversion_to_pb(
@@ -333,6 +345,18 @@ def test_power_from_pb() -> None:
333345
)
334346

335347

348+
def test_power_formatting() -> None:
349+
"""Test the client power type formatting."""
350+
power = Power(mw=Decimal("5"))
351+
assert str(power) == "5 MW"
352+
power = Power(mw=Decimal("5.1"))
353+
assert str(power) == "5.1 MW"
354+
power = Power(mw=Decimal("5.100"))
355+
assert str(power) == "5.100 MW"
356+
power = Power(mw=Decimal("-5.123"))
357+
assert str(power) == "-5.123 MW"
358+
359+
336360
def test_delivery_duration_to_pb() -> None:
337361
"""Test the client delivery duration type conversions to protobuf."""
338362
assert_conversion_to_pb(

0 commit comments

Comments
 (0)