From ec02e362365ee199f734cb9e76fc812dd92d3113 Mon Sep 17 00:00:00 2001 From: pommicket Date: Tue, 23 Sep 2025 11:16:21 -0400 Subject: Add location tests, fix locations for multi-line items --- pom_parser/__init__.py | 3 ++- tests/__init__.py | 10 +++++++++- tests/location.py | 11 +++++++++++ 3 files changed, 22 insertions(+), 2 deletions(-) create mode 100644 tests/location.py diff --git a/pom_parser/__init__.py b/pom_parser/__init__.py index ea1c38f..3f1cce2 100644 --- a/pom_parser/__init__.py +++ b/pom_parser/__init__.py @@ -478,6 +478,7 @@ class _Parser: line = self._read_line() if line is None: return False + start_line_number = self.line_number line = line.lstrip(' \t') if not line or line.startswith('#'): return True @@ -507,7 +508,7 @@ class _Parser: item.read = False item.value = value item.file = self.filename - item.line = self.line_number + item.line = start_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 diff --git a/tests/__init__.py b/tests/__init__.py index aed3dc6..5616c23 100644 --- a/tests/__init__.py +++ b/tests/__init__.py @@ -1,6 +1,6 @@ import unittest import os -from tests import parsing, errors +from tests import parsing, errors, location class TestParsing(unittest.TestCase): def test_all(self) -> None: @@ -18,6 +18,14 @@ class TestErrors(unittest.TestCase): with self.subTest(file): errors.test_path(self, f'{test_dir}/{file}') +class TestLocation(unittest.TestCase): + def test_all(self) -> None: + test_dir = '../tests/location' + for file in os.listdir(test_dir): + if not file.endswith('.locations.pom'): continue + with self.subTest(file): + location.test_path(self, f'{test_dir}/{file}') + if __name__ == '__main__': unittest.main() diff --git a/tests/location.py b/tests/location.py new file mode 100644 index 0000000..cdac8e7 --- /dev/null +++ b/tests/location.py @@ -0,0 +1,11 @@ +import pom_parser +import unittest + +def test_path(tester: unittest.TestCase, loc_path: str) -> None: + conf_path = loc_path.replace('.locations.pom', '.pom') + locs = pom_parser.load_path(loc_path) + conf = pom_parser.load_path(conf_path) + for item in conf.items(): + expected = locs.get_uint(item.key) + tester.assertTrue(expected is not None) + tester.assertEqual(expected, item.line, f'Incorrect line number for {item.key}') -- cgit v1.2.3