33 lines
1.0 KiB
Python
33 lines
1.0 KiB
Python
|
import pytest
|
||
|
|
||
|
import datetime
|
||
|
from decimal import Decimal
|
||
|
import fin_defs
|
||
|
|
||
|
NOW = datetime.datetime.now()
|
||
|
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
|