36 lines
1 KiB
Python
36 lines
1 KiB
Python
import datetime
|
|
import pathlib
|
|
|
|
import pytest
|
|
|
|
from . import relpath
|
|
import oxrlib.loaders
|
|
|
|
CACHE_PATH = relpath('filecache')
|
|
CACHE_PATTERN = '{date}_{base}_cache.json'
|
|
|
|
@pytest.fixture
|
|
def dummycache():
|
|
return oxrlib.loaders.FileCache(CACHE_PATH, CACHE_PATTERN)
|
|
|
|
@pytest.mark.parametrize('date,base', [
|
|
(datetime.date(1999, 2, 1), 'USD'),
|
|
(datetime.date(1999, 3, 1), 'EUR'),
|
|
])
|
|
def test_cache_success(dummycache, date, base):
|
|
expect_name = CACHE_PATH / CACHE_PATTERN.format(date=date.isoformat(), base=base)
|
|
with dummycache.historical(date, base) as cache_file:
|
|
assert pathlib.Path(cache_file.name) == expect_name
|
|
|
|
@pytest.mark.parametrize('date,base', [
|
|
(datetime.date(1999, 2, 1), 'EUR'),
|
|
(datetime.date(1999, 3, 1), 'USD'),
|
|
])
|
|
def test_cache_not_found(dummycache, date, base):
|
|
try:
|
|
cache_file = dummycache.historical(date, base)
|
|
except oxrlib.loaders.LoaderNoDataError:
|
|
pass
|
|
else:
|
|
cache_file.close()
|
|
assert False, "cache file found when unexpected"
|