summaryrefslogtreecommitdiff
diff options
context:
space:
mode:
-rw-r--r--pom_parser/__init__.py2
-rw-r--r--tests/__init__.py10
-rw-r--r--tests/errors.py9
3 files changed, 20 insertions, 1 deletions
diff --git a/pom_parser/__init__.py b/pom_parser/__init__.py
index 35d0f49..ea1c38f 100644
--- a/pom_parser/__init__.py
+++ b/pom_parser/__init__.py
@@ -508,6 +508,8 @@ class _Parser:
item.value = value
item.file = self.filename
item.line = self.line_number
+ if prev_item := self.items.get(key):
+ self._error(f'Re-definition of {key} (first definition was on line {prev_item.line})')
self.items[key] = item
return True
diff --git a/tests/__init__.py b/tests/__init__.py
index e9737ec..aed3dc6 100644
--- a/tests/__init__.py
+++ b/tests/__init__.py
@@ -1,6 +1,6 @@
import unittest
import os
-from tests import parsing
+from tests import parsing, errors
class TestParsing(unittest.TestCase):
def test_all(self) -> None:
@@ -10,6 +10,14 @@ class TestParsing(unittest.TestCase):
with self.subTest(file):
parsing.test_path(self, f'{test_dir}/{file}')
+class TestErrors(unittest.TestCase):
+ def test_all(self) -> None:
+ test_dir = '../tests/errors'
+ for file in os.listdir(test_dir):
+ if not file.endswith('.pom'): continue
+ with self.subTest(file):
+ errors.test_path(self, f'{test_dir}/{file}')
+
if __name__ == '__main__':
unittest.main()
diff --git a/tests/errors.py b/tests/errors.py
new file mode 100644
index 0000000..841c30e
--- /dev/null
+++ b/tests/errors.py
@@ -0,0 +1,9 @@
+import pom_parser
+import unittest
+
+def test_path(tester: unittest.TestCase, path: str) -> None:
+ try:
+ pom_parser.load_path(path)
+ tester.fail(f'Parsing configuration {path} should have failed.')
+ except pom_parser.Error:
+ pass