reports: Add Balance.__pos__() method.
I did this while I was working on normalize_amount_func. It turns out it's not immediately needed, but it's still nice to have.
This commit is contained in:
parent
e26dffa214
commit
0581525c98
2 changed files with 17 additions and 0 deletions
|
@ -140,6 +140,9 @@ class Balance(Mapping[str, data.Amount]):
|
|||
def __neg__(self: BalanceType) -> BalanceType:
|
||||
return type(self)(-amt for amt in self.values())
|
||||
|
||||
def __pos__(self: BalanceType) -> BalanceType:
|
||||
return self
|
||||
|
||||
def __getitem__(self, key: str) -> data.Amount:
|
||||
return self._currency_map[key]
|
||||
|
||||
|
|
|
@ -168,6 +168,20 @@ def test_neg(mapping):
|
|||
for key, number in mapping.items():
|
||||
assert actual[key] == testutil.Amount(-number, key)
|
||||
|
||||
@pytest.mark.parametrize('mapping', [
|
||||
{},
|
||||
{'USD': 0},
|
||||
{'EUR': 10},
|
||||
{'JPY': 20, 'BRL': 30},
|
||||
{'EUR': -15},
|
||||
{'JPY': -25, 'BRL': -35},
|
||||
{'JPY': 40, 'USD': 0, 'EUR': -50},
|
||||
])
|
||||
def test_pos(mapping):
|
||||
amounts = frozenset(amounts_from_map(mapping))
|
||||
actual = +core.Balance(amounts)
|
||||
assert set(actual.values()) == amounts
|
||||
|
||||
@pytest.mark.parametrize('map1,map2,expected', [
|
||||
({}, {}, True),
|
||||
({}, {'USD': 0}, True),
|
||||
|
|
Loading…
Reference in a new issue