aboutsummaryrefslogtreecommitdiffstats
diff options
context:
space:
mode:
authorEugene Triguba <eugenetriguba@gmail.com>2020-08-05 21:12:38 -0500
committerEugene Triguba <eugenetriguba@gmail.com>2020-08-05 21:12:38 -0500
commit36b8e0f288883284e2677f7873088c5a2d779d79 (patch)
tree38ab5da85e300d6704bf8ac9e49a1b9a65f4ad07
parentFix test that was using `parser` option (diff)
downloadconfig-file-36b8e0f288883284e2677f7873088c5a2d779d79.zip
Add tests for abstract parser
-rw-r--r--tests/test_abstract_parser.py50
-rw-r--r--tests/test_base_parser.py57
2 files changed, 50 insertions, 57 deletions
diff --git a/tests/test_abstract_parser.py b/tests/test_abstract_parser.py
new file mode 100644
index 0000000..d1cc4ef
--- /dev/null
+++ b/tests/test_abstract_parser.py
@@ -0,0 +1,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)
diff --git a/tests/test_base_parser.py b/tests/test_base_parser.py
index 90d45f4..e69de29 100644
--- a/tests/test_base_parser.py
+++ b/tests/test_base_parser.py
@@ -1,57 +0,0 @@
-# import pytest
-#
-# from config_file.parsers import BaseParser
-#
-
-# class ConcreteParser(AbstractParser):
-# def __init__(self, file_contents):
-# super().__init__(file_contents)
-#
-# def get(self, key, parse_types=True):
-# super().get(key, parse_types=parse_types)
-#
-# 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, call_super=False):
-# if call_super:
-# super().parse(file_contents)
-#
-# return file_contents
-#
-#
-# def test_that_base_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("").parse, "call super"),
-# ],
-# )
-# 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)
-# elif args == "call super":
-# function(args, call_super=True)
-# else:
-# function(args)