1
0
fin-defs/test/test_exchange_rate_sample.py
Jon Michael Aanes a322770205
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
Code quality
2024-10-27 17:26:03 +01:00

38 lines
942 B
Python

import datetime
from decimal import Decimal
import fin_defs
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),
)
SAMPLE_HIGH_LOW = fin_defs.ExchangeRateSample(
NOW,
(fin_defs.FiatCurrency.DKK, fin_defs.FiatCurrency.USD),
high=Decimal(1),
low=Decimal('0.5'),
)
def test_sample_average():
assert SAMPLE_AVERAGE.average == 1
assert SAMPLE_HIGH_LOW.average == Decimal('0.75')
def test_invert_sample():
inverted = SAMPLE_HIGH_LOW.invert_exchange_rate()
assert inverted.asset_pair == (fin_defs.FiatCurrency.USD, fin_defs.FiatCurrency.DKK)
assert inverted.high == 2
assert inverted.low == 1
assert inverted.average == 1.5
def test_replace_timestamp():
assert SAMPLE_HIGH_LOW.replace_timestamp(THEN).timestamp == THEN