aboutsummaryrefslogtreecommitdiffstats
path: root/tests/test_abstract_parser.py
blob: d1cc4efc718a2ac9414fee17d91b469b99f3769d (plain) (blame)
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
import pytest

from config_file import AbstractParser


class ConcreteParser(AbstractParser):
    def __init__(self, file_contents):
        super().__init__(file_contents)

    def get(self, key):
        super().get(key)

    def set(self, key, value):
        super().set(key, value)

    def delete(self, section_key):
        super().delete(section_key)

    def has(self, section_key: str):
        super().has(section_key)

    def stringify(self):
        super().stringify()

    def reset_internal_contents(self, file_contents: str) -> None:
        super().reset_internal_contents(file_contents)


def test_that_abstract_parser_can_not_be_instantiated():
    with pytest.raises(TypeError):
        AbstractParser("")


@pytest.mark.parametrize(
    "function, args",
    [
        (ConcreteParser("").get, ("",)),
        (ConcreteParser("").set, ("", "")),
        (ConcreteParser("").delete, ("",)),
        (ConcreteParser("").stringify, None),
        (ConcreteParser("").has, ("",)),
        (ConcreteParser("").reset_internal_contents, ("",)),
    ],
)
def test_that_abstract_parser_raises_not_implemented_errors(function, args):
    with pytest.raises(NotImplementedError):
        if args is None:
            function()
        else:
            function(*args)