Changeset - 744479013d7a
[Not reviewed]
0 2 0
Brett Smith - 7 years ago 2017-05-09 14:35:20
brettcsmith@brettcsmith.org
loaders: Introduce common exceptions.
2 files changed with 21 insertions and 3 deletions:
0 comments (0 inline, 0 general)
oxrlib/loaders.py
Show inline comments
 
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)
 
        return path.open()
 

	
 
        try:
 
            return path.open()
 
        except FileNotFoundError as error:
 
            raise LoaderNoDataError(path) from error
tests/test_loaders.py
Show inline comments
...
 
@@ -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()
0 comments (0 inline, 0 general)