Написал класс парсера строки с сегментами названия настройки

This commit is contained in:
rzaitov 2013-10-31 16:16:02 +04:00
parent 515b6fba1f
commit 2b6436e9f4
2 changed files with 30 additions and 0 deletions

View File

@ -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])

View File

@ -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))