Moved exceptions to own file; added some more tests
Some checks failed
continuous-integration/drone the build failed

This commit is contained in:
Jef Roosens 2021-05-15 13:46:36 +02:00
parent ad31d9a979
commit 0dc1b3ded4
Signed by: Jef Roosens
GPG key ID: 955C0660072F691F
3 changed files with 73 additions and 35 deletions

36
app/exceptions.py Normal file
View 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__()

View file

@ -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: