loaders: Introduce common exceptions.
This commit is contained in:
parent
d1ba2dbc6a
commit
744479013d
2 changed files with 21 additions and 3 deletions
|
@ -1,3 +1,19 @@
|
|||
class LoaderError(Exception):
|
||||
pass
|
||||
|
||||
|
||||
class LoaderNoDataError(LoaderError):
|
||||
pass
|
||||
|
||||
|
||||
class LoaderBadRequestError(LoaderError):
|
||||
pass
|
||||
|
||||
|
||||
class LoaderSourceError(LoaderError):
|
||||
pass
|
||||
|
||||
|
||||
class FileCache:
|
||||
def __init__(self, dir_path, filename_pattern):
|
||||
self.dir_path = dir_path
|
||||
|
@ -5,5 +21,7 @@ class FileCache:
|
|||
|
||||
def historical(self, date, base):
|
||||
path = self.dir_path / self.pattern.format(date=date.isoformat(), base=base)
|
||||
try:
|
||||
return path.open()
|
||||
|
||||
except FileNotFoundError as error:
|
||||
raise LoaderNoDataError(path) from error
|
||||
|
|
|
@ -29,7 +29,7 @@ def test_cache_success(dummycache, date, base):
|
|||
def test_cache_not_found(dummycache, date, base):
|
||||
try:
|
||||
cache_file = dummycache.historical(date, base)
|
||||
except FileNotFoundError:
|
||||
except oxrlib.loaders.LoaderNoDataError:
|
||||
pass
|
||||
else:
|
||||
cache_file.close()
|
||||
|
|
Loading…
Reference in a new issue