aboutsummaryrefslogtreecommitdiffstats
diff options
context:
space:
mode:
authorEugene Triguba <eugenetriguba@gmail.com>2020-01-19 15:37:26 -0600
committerEugene Triguba <eugenetriguba@gmail.com>2020-01-19 15:37:26 -0600
commit278ae4e2decf64e39a0343b4b1b1c91d8b37a075 (patch)
tree0fd43fe3eca15b8ecdc305dfeaad7edc0ba00f3b
parentCreate publish_to_pypi.yml (diff)
downloadconfig-file-278ae4e2decf64e39a0343b4b1b1c91d8b37a075.zip
Add tests for BaseParser
-rw-r--r--CHANGELOG.md4
-rw-r--r--tests/test_base_parser.py51
2 files changed, 52 insertions, 3 deletions
diff --git a/CHANGELOG.md b/CHANGELOG.md
index 7ccab9e..b9f3bbd 100644
--- a/CHANGELOG.md
+++ b/CHANGELOG.md
@@ -18,9 +18,7 @@ and this project adheres to [Semantic Versioning](https://semver.org/spec/v2.0.0
method should be called after your changes to the config file. It will write them
back out.
- - Raise test coverage to 93% (`BaseParser` is abstract so it isn't tested and some
- methods in `ConfigFile` simply use the same method in the parser so it doesn't make
- sense to test those methods.)
+ - Raise test coverage to 93%.
## 0.3.3 - 2020-01-18
diff --git a/tests/test_base_parser.py b/tests/test_base_parser.py
new file mode 100644
index 0000000..3cd6e8a
--- /dev/null
+++ b/tests/test_base_parser.py
@@ -0,0 +1,51 @@
+import pytest
+
+from config_file.parsers.base_parser import BaseParser
+
+
+class ConcreteParser(BaseParser):
+ def __init__(self, file_contents):
+ super().__init__(file_contents)
+
+ def get(self, key, parse_type=True):
+ super().get(key, parse_type=parse_type)
+
+ def set(self, key, value):
+ super().set(key, value)
+
+ def delete(self, section_key):
+ super().delete(section_key)
+
+ def has(self, section_key: str) -> bool:
+ super().has(section_key)
+
+ def stringify(self) -> str:
+ super().stringify()
+
+ def parse(self, file_contents: str):
+ return file_contents
+
+
+def test_that_base_parser_can_not_be_instantiated():
+ with pytest.raises(TypeError):
+ BaseParser("")
+
+
+@pytest.mark.parametrize(
+ "function, args",
+ [
+ (ConcreteParser("").get, ""),
+ (ConcreteParser("").set, ("", "")),
+ (ConcreteParser("").delete, ""),
+ (ConcreteParser("").stringify, None),
+ (ConcreteParser("").has, ""),
+ ],
+)
+def test_that_base_parser_raises_not_implemented_errors(function, args):
+ with pytest.raises(NotImplementedError):
+ if args is None:
+ function()
+ elif type(args) is tuple:
+ function(*args)
+ else:
+ function(args)