From a3227702054b1aa2021f22526d10d9ecc231f40e Mon Sep 17 00:00:00 2001 From: Jon Michael Aanes Date: Sun, 27 Oct 2024 17:26:03 +0100 Subject: [PATCH] Code quality --- fin_defs/__init__.py | 8 ++++++-- test/test_asset_amount.py | 12 ++++++++---- test/test_currency.py | 1 - test/test_exchange_rate_sample.py | 7 ++++--- test/test_ids.py | 3 ++- 5 files changed, 20 insertions(+), 11 deletions(-) diff --git a/fin_defs/__init__.py b/fin_defs/__init__.py index 12228dd..1217ef1 100644 --- a/fin_defs/__init__.py +++ b/fin_defs/__init__.py @@ -205,7 +205,7 @@ class Asset: @enforce_typing.enforce_types @dataclasses.dataclass(frozen=True) class UnknownAsset(Asset): - pass + """An asset that does not exist.""" @abc.abstractmethod def raw_short_name(self) -> str: @@ -215,12 +215,14 @@ class UnknownAsset(Asset): @enforce_typing.enforce_types @dataclasses.dataclass(frozen=True) class Currency(Asset): - pass + """Either a Fiat or a Crypto Currency.""" @enforce_typing.enforce_types @dataclasses.dataclass(frozen=True, eq=True, order=True) class FiatCurrency(Currency): + """Fiat Currency.""" + iso_code: str def __post_init__(self) -> None: @@ -253,6 +255,8 @@ FiatCurrency.JPY = FiatCurrency('JPY') @enforce_typing.enforce_types @dataclasses.dataclass(frozen=True, eq=True) class CryptoCurrency(Currency): + """Crypto Currency.""" + ccxt_symbol: str coingecko_id: str | None = None diff --git a/test/test_asset_amount.py b/test/test_asset_amount.py index c10982a..5c24961 100644 --- a/test/test_asset_amount.py +++ b/test/test_asset_amount.py @@ -82,7 +82,8 @@ def test_add_wrong_type(): def test_add_wrong_asset(): 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 @@ -94,7 +95,8 @@ def test_sub_wrong_type(): def test_sub_wrong_asset(): 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 @@ -106,13 +108,15 @@ def test_cmp_wrong_type(): def test_cmp_wrong_asset(): 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 def test_div_wrong_asset(): 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 diff --git a/test/test_currency.py b/test/test_currency.py index e941eae..6ce802e 100644 --- a/test/test_currency.py +++ b/test/test_currency.py @@ -1,4 +1,3 @@ - import fin_defs diff --git a/test/test_exchange_rate_sample.py b/test/test_exchange_rate_sample.py index b3b43b8..81fbed8 100644 --- a/test/test_exchange_rate_sample.py +++ b/test/test_exchange_rate_sample.py @@ -1,14 +1,15 @@ - import datetime from decimal import Decimal import fin_defs -NOW = datetime.datetime.now() +NOW = datetime.datetime.now(tz=datetime.UTC) THEN = NOW - datetime.timedelta(days=1) 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( diff --git a/test/test_ids.py b/test/test_ids.py index 8872de0..ff67351 100644 --- a/test/test_ids.py +++ b/test/test_ids.py @@ -29,7 +29,8 @@ ASSETS_POLYGON_PRESERVES_FULL_ID = frozenset( a for a in ASSETS 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])