Ruff
This commit is contained in:
parent
ef7a0e8078
commit
42ec581aca
|
@ -505,6 +505,7 @@ class AssetInformation:
|
||||||
|
|
||||||
THREE_DECIMALS_UNDER_THIS_AMOUNT = 0.10
|
THREE_DECIMALS_UNDER_THIS_AMOUNT = 0.10
|
||||||
|
|
||||||
|
|
||||||
def assert_same_asset(do: str, a_asset: 'AssetAmount', b_asset: 'AssetAmount'):
|
def assert_same_asset(do: str, a_asset: 'AssetAmount', b_asset: 'AssetAmount'):
|
||||||
if a_asset.asset != b_asset.asset:
|
if a_asset.asset != b_asset.asset:
|
||||||
msg = f'Attempting to {do} {a_asset} and {b_asset}, but these must have the same asset'
|
msg = f'Attempting to {do} {a_asset} and {b_asset}, but these must have the same asset'
|
||||||
|
@ -568,7 +569,6 @@ class AssetAmount:
|
||||||
assert_same_asset('subtract', self, other)
|
assert_same_asset('subtract', self, other)
|
||||||
return AssetAmount(self.asset, self.amount - other.amount)
|
return AssetAmount(self.asset, self.amount - other.amount)
|
||||||
|
|
||||||
|
|
||||||
def __truediv__(self, other: 'Decimal | AssetAmount') -> 'Decimal | AssetAmount':
|
def __truediv__(self, other: 'Decimal | AssetAmount') -> 'Decimal | AssetAmount':
|
||||||
if isinstance(other, AssetAmount):
|
if isinstance(other, AssetAmount):
|
||||||
assert_same_asset('divide', self, other)
|
assert_same_asset('divide', self, other)
|
||||||
|
|
|
@ -1,5 +1,5 @@
|
||||||
from decimal import Decimal
|
|
||||||
import re
|
import re
|
||||||
|
from decimal import Decimal
|
||||||
|
|
||||||
import pytest
|
import pytest
|
||||||
|
|
||||||
|
@ -84,7 +84,9 @@ def test_add_wrong_type():
|
||||||
def test_add_wrong_asset():
|
def test_add_wrong_asset():
|
||||||
with pytest.raises(
|
with pytest.raises(
|
||||||
ValueError,
|
ValueError,
|
||||||
match=re.escape('Attempting to add $20.00 USD and 21.00 DKK, but these must have the same asset'),
|
match=re.escape(
|
||||||
|
'Attempting to add $20.00 USD and 21.00 DKK, but these must have the same asset',
|
||||||
|
),
|
||||||
):
|
):
|
||||||
assert USD_20 + DKK_21
|
assert USD_20 + DKK_21
|
||||||
|
|
||||||
|
@ -97,7 +99,9 @@ def test_sub_wrong_type():
|
||||||
def test_sub_wrong_asset():
|
def test_sub_wrong_asset():
|
||||||
with pytest.raises(
|
with pytest.raises(
|
||||||
ValueError,
|
ValueError,
|
||||||
match=re.escape('Attempting to subtract $20.00 USD and 21.00 DKK, but these must have the same asset'),
|
match=re.escape(
|
||||||
|
'Attempting to subtract $20.00 USD and 21.00 DKK, but these must have the same asset',
|
||||||
|
),
|
||||||
):
|
):
|
||||||
assert USD_20 - DKK_21
|
assert USD_20 - DKK_21
|
||||||
|
|
||||||
|
@ -110,7 +114,9 @@ def test_cmp_wrong_type():
|
||||||
def test_cmp_wrong_asset():
|
def test_cmp_wrong_asset():
|
||||||
with pytest.raises(
|
with pytest.raises(
|
||||||
ValueError,
|
ValueError,
|
||||||
match=re.escape('Attempting to compare $20.00 USD and 21.00 DKK, but these must have the same asset'),
|
match=re.escape(
|
||||||
|
'Attempting to compare $20.00 USD and 21.00 DKK, but these must have the same asset',
|
||||||
|
),
|
||||||
):
|
):
|
||||||
assert USD_20 < DKK_21
|
assert USD_20 < DKK_21
|
||||||
|
|
||||||
|
@ -118,6 +124,8 @@ def test_cmp_wrong_asset():
|
||||||
def test_div_wrong_asset():
|
def test_div_wrong_asset():
|
||||||
with pytest.raises(
|
with pytest.raises(
|
||||||
ValueError,
|
ValueError,
|
||||||
match=re.escape('Attempting to divide $21.00 USD and 21.00 DKK, but these must have the same asset'),
|
match=re.escape(
|
||||||
|
'Attempting to divide $21.00 USD and 21.00 DKK, but these must have the same asset',
|
||||||
|
),
|
||||||
):
|
):
|
||||||
assert USD_21 / DKK_21
|
assert USD_21 / DKK_21
|
||||||
|
|
Loading…
Reference in New Issue
Block a user