Skip to content
Merged
Show file tree
Hide file tree
Changes from 1 commit
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
8 changes: 8 additions & 0 deletions src/frequenz/quantities/_quantity.py
Original file line number Diff line number Diff line change
Expand Up @@ -149,6 +149,14 @@ def __round__(self, ndigits: int | None = None) -> Self:
The rounded quantity.
"""
return self._new(round(self._base_value, ndigits))
Copy link
Contributor

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Blankline after function?


def __pos__(self) -> Self:
"""Return this quantity.

Returns:
This quantity.
"""
return self
Copy link
Contributor

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Blankline after function?

@property
def base_unit(self) -> str | None:
"""Return the base unit of this quantity.
Expand Down
27 changes: 27 additions & 0 deletions tests/test_quantities.py
Original file line number Diff line number Diff line change
Expand Up @@ -491,6 +491,33 @@ def test_neg() -> None:
assert -(-pct) == pct


def test_pos() -> None:
"""Test the positive sign of quantities."""
power = Power.from_watts(1000.0)
assert +power == power
assert +(+power) == power

voltage = Voltage.from_volts(230.0)
assert +voltage == voltage
assert +(+voltage) == voltage

current = Current.from_amperes(2)
assert +current == current
assert +(+current) == current

energy = Energy.from_kilowatt_hours(6.2)
assert +energy == energy
assert +(+energy) == energy

freq = Frequency.from_hertz(50)
assert +freq == freq
assert +(+freq) == freq

pct = Percentage.from_fraction(30)
assert +pct == pct
assert +(+pct) == pct


def test_inf() -> None:
"""Test proper formating when using inf in quantities."""
assert f"{Power.from_watts(float('inf'))}" == "inf W"
Expand Down