aboutsummaryrefslogtreecommitdiffstats
diff options
context:
space:
mode:
authorEugene Triguba <eugenetriguba@gmail.com>2020-08-06 09:47:35 -0500
committerEugene Triguba <eugenetriguba@gmail.com>2020-08-06 09:47:35 -0500
commit836cefe45633331d0e5692295174bf3181a5e365 (patch)
tree8602b312e67cc591f33022f56221ca7434cfe33f
parentUpdate README example to remove MissingKeyError (diff)
downloadconfig-file-836cefe45633331d0e5692295174bf3181a5e365.zip
Change MissingKeyErrors to KeyError
-rw-r--r--config_file/abstract_parser.py4
-rw-r--r--config_file/base_parser.py4
-rw-r--r--tests/test_abstract_parser.py4
-rw-r--r--tests/test_config_file.py5
-rw-r--r--tests/test_ini_parser.py6
5 files changed, 11 insertions, 12 deletions
diff --git a/config_file/abstract_parser.py b/config_file/abstract_parser.py
index ab5d205..689fece 100644
--- a/config_file/abstract_parser.py
+++ b/config_file/abstract_parser.py
@@ -57,7 +57,7 @@ class AbstractParser(ABC):
Whatever value the given key happens to contain.
Raises:
- MissingKeyError: If the key to retrieve does not exist.
+ KeyError: If the key to retrieve does not exist.
"""
raise NotImplementedError
@@ -81,7 +81,7 @@ class AbstractParser(ABC):
key: The key we would like to remove.
Raises:
- MissingKeyError: If the key to remove does not exist.
+ KeyError: If the key to remove does not exist.
"""
raise NotImplementedError
diff --git a/config_file/base_parser.py b/config_file/base_parser.py
index a987a55..a440dcb 100644
--- a/config_file/base_parser.py
+++ b/config_file/base_parser.py
@@ -2,7 +2,7 @@ from types import ModuleType
from typing import Any, Type
from config_file.abstract_parser import AbstractParser
-from config_file.exceptions import MissingKeyError, ParsingError
+from config_file.exceptions import ParsingError
from config_file.nested_lookup import get_occurrence_of_key
from config_file.utils import split_on_dot
@@ -123,7 +123,7 @@ class BaseParser(AbstractParser):
content_reference = content_reference[key]
except (KeyError, TypeError):
- raise MissingKeyError(f"The specified key '{key}' to delete was not found.")
+ raise KeyError(f"The specified key '{key}' to delete was not found.")
def stringify(self) -> str:
return self.__module.dumps(self.parsed_content)
diff --git a/tests/test_abstract_parser.py b/tests/test_abstract_parser.py
index a2d9dbe..1816f6b 100644
--- a/tests/test_abstract_parser.py
+++ b/tests/test_abstract_parser.py
@@ -34,7 +34,7 @@ class ConcreteParser(AbstractParser):
def test_that_abstract_parser_can_not_be_instantiated():
"""
- config_file.abstract_parser.abstract_parser
+ config_file.abstract_parser.AbstractParser
Ensure the AbstractParser raises a TypeError when it is
instantiated.
@@ -56,7 +56,7 @@ def test_that_abstract_parser_can_not_be_instantiated():
)
def test_that_abstract_parser_raises_not_implemented_errors(function, args):
"""
- config_file.abstract_parser.abstract_parser
+ config_file.abstract_parser.AbstractParser
Ensure the AbstractParser raises a NotImplementedError
for every method in it.
diff --git a/tests/test_config_file.py b/tests/test_config_file.py
index 7e21e0b..023b6ae 100644
--- a/tests/test_config_file.py
+++ b/tests/test_config_file.py
@@ -4,7 +4,6 @@ import pytest
from config_file.abstract_parser import AbstractParser
from config_file.config_file import ConfigFile
-from config_file.exceptions import MissingKeyError
from config_file.ini_parser import IniParser
SUPPORTED_FILE_TYPES = ["ini", "json", "yaml", "toml"]
@@ -126,10 +125,10 @@ def test_that_config_file_can_delete(templated_config_file, key):
@pytest.mark.parametrize("key", ["", 0, False, {}, "header_one.does_not_exist"])
-def test_that_config_file_raises_missing_key_error_on_invalid_input_or_missing_key(
+def test_that_config_file_raises_key_error_on_invalid_input_or_missing_key(
templated_config_file, key
):
config = templated_config_file()
- with pytest.raises(MissingKeyError):
+ with pytest.raises(KeyError):
config.delete(key)
diff --git a/tests/test_ini_parser.py b/tests/test_ini_parser.py
index 24507b7..2accc8f 100644
--- a/tests/test_ini_parser.py
+++ b/tests/test_ini_parser.py
@@ -1,6 +1,6 @@
import pytest
-from config_file.exceptions import MissingKeyError, ParsingError
+from config_file.exceptions import ParsingError
from config_file.ini_parser import IniParser
@@ -81,10 +81,10 @@ def test_that_ini_parser_can_delete(section_key, expected_result):
@pytest.mark.parametrize(
"section_key", ["section_is_not_present", "test_section.but_key_is_not_present"],
)
-def test_that_ini_parser_delete_raises_missing_key_errors(section_key):
+def test_that_ini_parser_delete_raises_key_error(section_key):
ini_file = """[test_section]\nkey1 = value\n\n"""
parser = IniParser(ini_file)
- with pytest.raises(MissingKeyError):
+ with pytest.raises(KeyError):
parser.delete(section_key)