From 278ae4e2decf64e39a0343b4b1b1c91d8b37a075 Mon Sep 17 00:00:00 2001 From: Eugene Triguba Date: Sun, 19 Jan 2020 15:37:26 -0600 Subject: Add tests for BaseParser --- CHANGELOG.md | 4 +--- tests/test_base_parser.py | 51 +++++++++++++++++++++++++++++++++++++++++++++++ 2 files changed, 52 insertions(+), 3 deletions(-) create mode 100644 tests/test_base_parser.py 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) -- cgit v1.2.3