1
0

Code quality
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-10-27 17:26:03 +01:00
parent 6856343f4c
commit a322770205
Signed by: Jmaa
SSH Key Fingerprint: SHA256:Ab0GfHGCblESJx7JRE4fj4bFy/KRpeLhi41y4pF3sNA
5 changed files with 20 additions and 11 deletions

View File

@ -205,7 +205,7 @@ class Asset:
@enforce_typing.enforce_types @enforce_typing.enforce_types
@dataclasses.dataclass(frozen=True) @dataclasses.dataclass(frozen=True)
class UnknownAsset(Asset): class UnknownAsset(Asset):
pass """An asset that does not exist."""
@abc.abstractmethod @abc.abstractmethod
def raw_short_name(self) -> str: def raw_short_name(self) -> str:
@ -215,12 +215,14 @@ class UnknownAsset(Asset):
@enforce_typing.enforce_types @enforce_typing.enforce_types
@dataclasses.dataclass(frozen=True) @dataclasses.dataclass(frozen=True)
class Currency(Asset): class Currency(Asset):
pass """Either a Fiat or a Crypto Currency."""
@enforce_typing.enforce_types @enforce_typing.enforce_types
@dataclasses.dataclass(frozen=True, eq=True, order=True) @dataclasses.dataclass(frozen=True, eq=True, order=True)
class FiatCurrency(Currency): class FiatCurrency(Currency):
"""Fiat Currency."""
iso_code: str iso_code: str
def __post_init__(self) -> None: def __post_init__(self) -> None:
@ -253,6 +255,8 @@ FiatCurrency.JPY = FiatCurrency('JPY')
@enforce_typing.enforce_types @enforce_typing.enforce_types
@dataclasses.dataclass(frozen=True, eq=True) @dataclasses.dataclass(frozen=True, eq=True)
class CryptoCurrency(Currency): class CryptoCurrency(Currency):
"""Crypto Currency."""
ccxt_symbol: str ccxt_symbol: str
coingecko_id: str | None = None coingecko_id: str | None = None

View File

@ -82,7 +82,8 @@ def test_add_wrong_type():
def test_add_wrong_asset(): def test_add_wrong_asset():
with pytest.raises( with pytest.raises(
ValueError, match='AssetAmount must have same asset, but: fiat:USD != fiat:DKK', ValueError,
match='AssetAmount must have same asset, but: fiat:USD != fiat:DKK',
): ):
assert USD_20 + DKK_21 assert USD_20 + DKK_21
@ -94,7 +95,8 @@ def test_sub_wrong_type():
def test_sub_wrong_asset(): def test_sub_wrong_asset():
with pytest.raises( with pytest.raises(
ValueError, match='AssetAmount must have same asset, but: fiat:USD != fiat:DKK', ValueError,
match='AssetAmount must have same asset, but: fiat:USD != fiat:DKK',
): ):
assert USD_20 - DKK_21 assert USD_20 - DKK_21
@ -106,13 +108,15 @@ def test_cmp_wrong_type():
def test_cmp_wrong_asset(): def test_cmp_wrong_asset():
with pytest.raises( with pytest.raises(
ValueError, match='AssetAmount must have same asset, but: fiat:USD != fiat:DKK', ValueError,
match='AssetAmount must have same asset, but: fiat:USD != fiat:DKK',
): ):
assert USD_20 < DKK_21 assert USD_20 < DKK_21
def test_div_wrong_asset(): def test_div_wrong_asset():
with pytest.raises( with pytest.raises(
ValueError, match='AssetAmount must have same asset, but: fiat:USD != fiat:DKK', ValueError,
match='AssetAmount must have same asset, but: fiat:USD != fiat:DKK',
): ):
assert USD_21 / DKK_21 assert USD_21 / DKK_21

View File

@ -1,4 +1,3 @@
import fin_defs import fin_defs

View File

@ -1,14 +1,15 @@
import datetime import datetime
from decimal import Decimal from decimal import Decimal
import fin_defs import fin_defs
NOW = datetime.datetime.now() NOW = datetime.datetime.now(tz=datetime.UTC)
THEN = NOW - datetime.timedelta(days=1) THEN = NOW - datetime.timedelta(days=1)
SAMPLE_AVERAGE = fin_defs.ExchangeRateSample( SAMPLE_AVERAGE = fin_defs.ExchangeRateSample(
NOW, (fin_defs.FiatCurrency.DKK, fin_defs.FiatCurrency.USD), _average=Decimal(1), NOW,
(fin_defs.FiatCurrency.DKK, fin_defs.FiatCurrency.USD),
_average=Decimal(1),
) )
SAMPLE_HIGH_LOW = fin_defs.ExchangeRateSample( SAMPLE_HIGH_LOW = fin_defs.ExchangeRateSample(

View File

@ -29,7 +29,8 @@ ASSETS_POLYGON_PRESERVES_FULL_ID = frozenset(
a a
for a in ASSETS for a in ASSETS
if not isinstance( if not isinstance(
a, fin_defs.CryptoCurrency | fin_defs.Commodity | fin_defs.UnknownAsset, a,
fin_defs.CryptoCurrency | fin_defs.Commodity | fin_defs.UnknownAsset,
) )
) - frozenset([NVO]) ) - frozenset([NVO])