From 2b6436e9f4fa85944adc9e80b09bfe25213d6e0b Mon Sep 17 00:00:00 2001 From: rzaitov Date: Thu, 31 Oct 2013 16:16:02 +0400 Subject: [PATCH] =?UTF-8?q?=D0=9D=D0=B0=D0=BF=D0=B8=D1=81=D0=B0=D0=BB=20?= =?UTF-8?q?=D0=BA=D0=BB=D0=B0=D1=81=D1=81=20=D0=BF=D0=B0=D1=80=D1=81=D0=B5?= =?UTF-8?q?=D1=80=D0=B0=20=D1=81=D1=82=D1=80=D0=BE=D0=BA=D0=B8=20=D1=81=20?= =?UTF-8?q?=D1=81=D0=B5=D0=B3=D0=BC=D0=B5=D0=BD=D1=82=D0=B0=D0=BC=D0=B8=20?= =?UTF-8?q?=D0=BD=D0=B0=D0=B7=D0=B2=D0=B0=D0=BD=D0=B8=D1=8F=20=D0=BD=D0=B0?= =?UTF-8?q?=D1=81=D1=82=D1=80=D0=BE=D0=B9=D0=BA=D0=B8?= MIME-Version: 1.0 Content-Type: text/plain; charset=UTF-8 Content-Transfer-Encoding: 8bit --- .../UnitTests/SettingsParser/test_PathParser.py | 16 ++++++++++++++++ scripts/parser/SettingsParser/PathParser.py | 14 ++++++++++++++ 2 files changed, 30 insertions(+) create mode 100644 scripts/UnitTests/SettingsParser/test_PathParser.py create mode 100644 scripts/parser/SettingsParser/PathParser.py diff --git a/scripts/UnitTests/SettingsParser/test_PathParser.py b/scripts/UnitTests/SettingsParser/test_PathParser.py new file mode 100644 index 0000000..46e678c --- /dev/null +++ b/scripts/UnitTests/SettingsParser/test_PathParser.py @@ -0,0 +1,16 @@ +import unittest +from parser.SettingsParser.PathParser import PathParser + + +class TestPathParser(unittest.TestCase): + def setUp(self): + self.parser = PathParser() + + def test_parseValidInput(self): + propertyPath = '123.abc.some_name' + segments = self.parser.parsePath(propertyPath) + + self.assertEqual(3, len(segments)) + self.assertEqual('123', segments[0]) + self.assertEqual('abc', segments[1]) + self.assertEqual('some_name', segments[2]) \ No newline at end of file diff --git a/scripts/parser/SettingsParser/PathParser.py b/scripts/parser/SettingsParser/PathParser.py new file mode 100644 index 0000000..fac8e87 --- /dev/null +++ b/scripts/parser/SettingsParser/PathParser.py @@ -0,0 +1,14 @@ +class PathParser: + def parsePath(self, line): + assert line is not None + + pathSegments = line.split('.') + self._guardPathSegments(pathSegments, line) + + return pathSegments + + def _guardPathSegments(self, pathSegments, sourceLine): + if '' in pathSegments: + raise Exception('invalid path given: {0}'.format(sourceLine)) + +