Moved exceptions to own file; added some more tests
Some checks failed
continuous-integration/drone the build failed
Some checks failed
continuous-integration/drone the build failed
This commit is contained in:
parent
ad31d9a979
commit
0dc1b3ded4
3 changed files with 73 additions and 35 deletions
36
app/exceptions.py
Normal file
36
app/exceptions.py
Normal file
|
|
@ -0,0 +1,36 @@
|
|||
"""Common exceptions raised by the program."""
|
||||
from typing import Union, List
|
||||
|
||||
|
||||
class InvalidKeyError(Exception):
|
||||
"""Thrown when a config file contains an invalid key."""
|
||||
|
||||
def __init__(self, keys: Union[str, List[str]]):
|
||||
"""Create a new InvalidKeyError object with the given key.
|
||||
|
||||
Args:
|
||||
keys: the invalid key(s)
|
||||
"""
|
||||
if type(keys) == str:
|
||||
keys = [keys]
|
||||
|
||||
self.message = "Invalid key(s): {}".format(", ".join(keys))
|
||||
|
||||
super().__init__()
|
||||
|
||||
|
||||
class MissingKeyError(Exception):
|
||||
"""Thrown when a required key is missing from a config."""
|
||||
|
||||
def __init__(self, keys: Union[str, List[str]]):
|
||||
"""Create a new MissingKeyError object with the given key.
|
||||
|
||||
Args:
|
||||
keys: the invalid key(s)
|
||||
"""
|
||||
if type(keys) == str:
|
||||
keys = [keys]
|
||||
|
||||
self.message = "Missing key(s): {}".format(", ".join(keys))
|
||||
|
||||
super().__init__()
|
||||
|
|
@ -1,39 +1,6 @@
|
|||
"""Handles merging with the skeleton config."""
|
||||
from typing import Dict, Union, List
|
||||
|
||||
|
||||
class InvalidKeyError(Exception):
|
||||
"""Thrown when a config file contains an invalid key."""
|
||||
|
||||
def __init__(self, keys: Union[str, List[str]]):
|
||||
"""Create a new InvalidKeyError object with the given key.
|
||||
|
||||
Args:
|
||||
keys: the invalid key(s)
|
||||
"""
|
||||
if type(keys) == str:
|
||||
keys = [keys]
|
||||
|
||||
self.message = "Invalid key(s): {}".format(", ".join(keys))
|
||||
|
||||
super().__init__()
|
||||
|
||||
|
||||
class MissingKeyError(Exception):
|
||||
"""Thrown when a required key is missing from a config."""
|
||||
|
||||
def __init__(self, keys: Union[str, List[str]]):
|
||||
"""Create a new MissingKeyError object with the given key.
|
||||
|
||||
Args:
|
||||
keys: the invalid key(s)
|
||||
"""
|
||||
if type(keys) == str:
|
||||
keys = [keys]
|
||||
|
||||
self.message = "Missing key(s): {}".format(", ".join(keys))
|
||||
|
||||
super().__init__()
|
||||
from typing import Dict
|
||||
from .exceptions import InvalidKeyError, MissingKeyError
|
||||
|
||||
|
||||
def merge(*dicts: [Dict]) -> Dict:
|
||||
|
|
|
|||
Reference in a new issue