1
0

Ruff
All checks were successful
Python Ruff Code Quality / ruff (push) Successful in 22s
Run Python tests (through Pytest) / Test (push) Successful in 25s
Verify Python project can be installed, loaded and have version checked / Test (push) Successful in 22s

This commit is contained in:
Jon Michael Aanes 2024-12-23 03:19:02 +01:00
parent ef7a0e8078
commit 42ec581aca
Signed by: Jmaa
SSH Key Fingerprint: SHA256:Ab0GfHGCblESJx7JRE4fj4bFy/KRpeLhi41y4pF3sNA
2 changed files with 14 additions and 6 deletions

View File

@ -505,6 +505,7 @@ class AssetInformation:
THREE_DECIMALS_UNDER_THIS_AMOUNT = 0.10
def assert_same_asset(do: str, a_asset: 'AssetAmount', b_asset: 'AssetAmount'):
if a_asset.asset != b_asset.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)
return AssetAmount(self.asset, self.amount - other.amount)
def __truediv__(self, other: 'Decimal | AssetAmount') -> 'Decimal | AssetAmount':
if isinstance(other, AssetAmount):
assert_same_asset('divide', self, other)

View File

@ -1,5 +1,5 @@
from decimal import Decimal
import re
from decimal import Decimal
import pytest
@ -84,7 +84,9 @@ def test_add_wrong_type():
def test_add_wrong_asset():
with pytest.raises(
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
@ -97,7 +99,9 @@ def test_sub_wrong_type():
def test_sub_wrong_asset():
with pytest.raises(
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
@ -110,7 +114,9 @@ def test_cmp_wrong_type():
def test_cmp_wrong_asset():
with pytest.raises(
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
@ -118,6 +124,8 @@ def test_cmp_wrong_asset():
def test_div_wrong_asset():
with pytest.raises(
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