from typing import Any import pytest from config_file.parsers.abstract_parser import AbstractParser from config_file.parsers.base_parser import BaseParser class ConcreteAbstractParser(AbstractParser): """ ConcreteParser is a concrete implementation of the AbstractParser that just calls the AbstractParser's methods so we can ensure they raise a NotImplementedError. """ def __init__(self, file_contents): super().__init__(file_contents) def get(self, key: str) -> Any: super().get(key) # type: ignore def set(self, key: str, value: Any) -> None: super().set(key, value) # type: ignore def delete(self, key: str) -> None: super().delete(key) # type: ignore def has(self, key: str, wild: bool = False) -> bool: return super().has(key, wild=wild) # type: ignore def __str__(self) -> str: return super().__str__() # type: ignore def reset_internal_contents(self, file_contents: str) -> None: super().reset_internal_contents(file_contents) # type: ignore @property def parsed_content(self) -> dict: return super().parsed_content() # type: ignore def test_that_abstract_parser_can_not_be_instantiated(): """ config_file.abstract_parser.AbstractParser Ensure the AbstractParser raises a TypeError when it is instantiated. """ with pytest.raises(TypeError): AbstractParser("") # type: ignore def test_that_base_parser_can_not_be_instantiated(): """ config_file.base_parser.BaseParser Ensure the BaseParser raises a TypeError when it is instantiated. """ with pytest.raises(TypeError): BaseParser("") # type: ignore @pytest.mark.parametrize( "function, args", [ (ConcreteAbstractParser("").get, ("",)), (ConcreteAbstractParser("").set, ("", "")), (ConcreteAbstractParser("").delete, ("",)), (ConcreteAbstractParser("").__str__, None), (ConcreteAbstractParser("").has, ("",)), (ConcreteAbstractParser("").reset_internal_contents, ("",)), ], ) def test_that_abstract_and_base_parser_raises_not_implemented_errors(function, args): """ config_file.abstract_parser.AbstractParser config_file.base_parser.BaseParser Ensure the AbstractParser and BaseParser raises a NotImplementedError for every method in it. """ with pytest.raises(NotImplementedError): if args is None: function() else: function(*args) def test_parsed_content_raises_not_implemented_error(): with pytest.raises(NotImplementedError): ConcreteAbstractParser("").parsed_content