76 lines
2.4 KiB
Python
76 lines
2.4 KiB
Python
import datetime
|
|
|
|
import pytest
|
|
from money.currency import Currency
|
|
|
|
from xexe.currency_pair import CurrencyPair
|
|
from xexe.utils import (
|
|
DateRange,
|
|
generate_currency_and_dates_combinations,
|
|
generate_pairs_and_dates_combinations,
|
|
)
|
|
|
|
|
|
def test_date_range_breaks_with_reversed_dates():
|
|
|
|
with pytest.raises(ValueError):
|
|
DateRange(
|
|
start_date=datetime.date(year=2024, month=1, day=3),
|
|
end_date=datetime.date(year=2024, month=1, day=1),
|
|
)
|
|
|
|
|
|
def test_date_range_generates_proper_dates_when_itered():
|
|
|
|
a_range = DateRange(
|
|
start_date=datetime.date(year=2024, month=1, day=1),
|
|
end_date=datetime.date(year=2024, month=1, day=3),
|
|
)
|
|
|
|
dates = [a_date for a_date in a_range]
|
|
|
|
assert dates[0] == datetime.date(year=2024, month=1, day=1)
|
|
assert dates[1] == datetime.date(year=2024, month=1, day=2)
|
|
assert dates[-1] == datetime.date(year=2024, month=1, day=3)
|
|
assert len(dates) == 3
|
|
|
|
|
|
def test_generate_currency_and_dates_combinations_outputs_correctly():
|
|
|
|
date_range = DateRange(
|
|
start_date=datetime.date(year=2024, month=1, day=1),
|
|
end_date=datetime.date(year=2024, month=1, day=3),
|
|
)
|
|
|
|
currencies = {Currency.USD, Currency.EUR, Currency.GBP}
|
|
|
|
combinations = generate_currency_and_dates_combinations(
|
|
currencies=currencies, date_range=date_range
|
|
)
|
|
|
|
assert len(combinations) == 9
|
|
assert len({combination["date"] for combination in combinations}) == 3
|
|
assert len({combination["from_currency"] for combination in combinations}) == 2
|
|
assert len({combination["to_currency"] for combination in combinations}) == 2
|
|
|
|
|
|
def test_generate_pair_and_dates_combinations_outputs_correctly():
|
|
date_range = DateRange(
|
|
start_date=datetime.date(year=2024, month=1, day=1),
|
|
end_date=datetime.date(year=2024, month=1, day=3),
|
|
)
|
|
|
|
pairs = {
|
|
CurrencyPair(from_currency="USD", to_currency="EUR"),
|
|
CurrencyPair(from_currency="USD", to_currency="GBP"),
|
|
CurrencyPair(from_currency="EUR", to_currency="GBP"),
|
|
}
|
|
|
|
combinations = generate_pairs_and_dates_combinations(
|
|
pairs=pairs, date_range=date_range
|
|
)
|
|
|
|
assert len(combinations) == 9
|
|
assert len({combination["date"] for combination in combinations}) == 3
|
|
assert len({combination["from_currency"] for combination in combinations}) == 2
|
|
assert len({combination["to_currency"] for combination in combinations}) == 2
|