From 8734cdf180799fa14f2d8ca646919b56d90bfcad Mon Sep 17 00:00:00 2001 From: Chewing_Bever Date: Sat, 15 May 2021 14:04:34 +0200 Subject: [PATCH] Added new exception [CI SKIP] --- app/exceptions.py | 19 +++++++++++++++++++ tests/test_skeleton.py | 2 +- 2 files changed, 20 insertions(+), 1 deletion(-) diff --git a/app/exceptions.py b/app/exceptions.py index 1ebfe95..b82bad8 100644 --- a/app/exceptions.py +++ b/app/exceptions.py @@ -34,3 +34,22 @@ class MissingKeyError(Exception): self.message = "Missing key(s): {}".format(", ".join(keys)) super().__init__() + + +class InvalidValueError(Exception): + """Thrown when a key contains an invalid value.""" + + def __init__(self, key: str, expected: str, actual: str): + """Create a new InvalidValueError given the arguments. + + Args: + key: the key containing the invalid value + expected: name of the expected type + actual: name of the actual type + """ + self.message = ( + f"Invalid value for key {key}: expected {expected}, " + f"got {actual}" + ) + + super().__init__() diff --git a/tests/test_skeleton.py b/tests/test_skeleton.py index 6cebba6..9ade87e 100644 --- a/tests/test_skeleton.py +++ b/tests/test_skeleton.py @@ -1,5 +1,5 @@ """Tests wether the skeleton merge works.""" -from app.skeleton import merge_with_skeleton, MissingKeyError, InvalidKeyError +from app.skeleton import merge_with_skeleton from app.exceptions import InvalidKeyError, MissingKeyError import pytest