From 1a020db8176b8685aeb75f8bad0169df6e318567 Mon Sep 17 00:00:00 2001 From: Rustam Zaitov Date: Mon, 7 Oct 2013 01:30:48 +0400 Subject: [PATCH] =?UTF-8?q?=D0=94=D0=BB=D1=8F=20=D1=80=D0=B0=D0=B1=D0=BE?= =?UTF-8?q?=D1=82=D1=8B=20=D1=81=20=D1=82=D0=B0=D0=B1=D0=BB=D0=B8=D1=86?= =?UTF-8?q?=D0=B5=D0=B9=20=D1=81=D0=B8=D0=BC=D0=B2=D0=BE=D0=BB=D0=BE=D0=B2?= =?UTF-8?q?=20=D0=B2=D0=BD=D0=B5=D0=B4=D1=80=D0=B5=D0=BD=D0=B0=20=D0=B7?= =?UTF-8?q?=D0=B0=D0=B2=D0=B8=D1=81=D0=B8=D0=BC=D0=BE=D1=81=D1=82=D1=8C=20?= =?UTF-8?q?valueProvider?= MIME-Version: 1.0 Content-Type: text/plain; charset=UTF-8 Content-Transfer-Encoding: 8bit --- scripts/UnitTests/CsprojParser/ValueProvider.py | 3 +++ .../UnitTests/CsprojParser/test_csprojLineParser.py | 4 +++- scripts/UnitTests/CsprojParser/test_csprojParser.py | 4 +++- scripts/parser/CsprojParser/CsprojLineParser.py | 11 +++++++++-- scripts/parser/CsprojParser/CsprojParser.py | 10 ++++++---- 5 files changed, 24 insertions(+), 8 deletions(-) create mode 100644 scripts/UnitTests/CsprojParser/ValueProvider.py diff --git a/scripts/UnitTests/CsprojParser/ValueProvider.py b/scripts/UnitTests/CsprojParser/ValueProvider.py new file mode 100644 index 0000000..646266d --- /dev/null +++ b/scripts/UnitTests/CsprojParser/ValueProvider.py @@ -0,0 +1,3 @@ +class ValueProvider: + def getValueFor(self, link): + return link diff --git a/scripts/UnitTests/CsprojParser/test_csprojLineParser.py b/scripts/UnitTests/CsprojParser/test_csprojLineParser.py index 4e8ea65..97b65cc 100644 --- a/scripts/UnitTests/CsprojParser/test_csprojLineParser.py +++ b/scripts/UnitTests/CsprojParser/test_csprojLineParser.py @@ -1,12 +1,14 @@ # -*- coding: utf-8 -*- import unittest +from UnitTests.CsprojParser.ValueProvider import ValueProvider from parser.CsprojParser.CsprojLineParser import CsprojLineParser class TestCsprojParser(unittest.TestCase): def setUp(self): - self.parser = CsprojLineParser() + value_provider = ValueProvider() + self.parser = CsprojLineParser(value_provider) def test_parseAppStatement(self): statement = "app:SomeAppName" diff --git a/scripts/UnitTests/CsprojParser/test_csprojParser.py b/scripts/UnitTests/CsprojParser/test_csprojParser.py index a8a6de9..8fa6806 100644 --- a/scripts/UnitTests/CsprojParser/test_csprojParser.py +++ b/scripts/UnitTests/CsprojParser/test_csprojParser.py @@ -1,4 +1,5 @@ import unittest +from UnitTests.CsprojParser.ValueProvider import ValueProvider from parser.CsprojParser.CsprojParser import CsprojParser @@ -15,9 +16,10 @@ class TestCase(unittest.TestCase): "csproj app:second attr1 'attr_val1'", "csproj app:second attr2 'attr_val2'"] self.__parser = None + self.__value_provider = ValueProvider() def __do_parse(self): - self.__parser = CsprojParser(self.__lineCollection) + self.__parser = CsprojParser(self.__lineCollection, self.__value_provider) self.__parser.parse() def test_projectCount(self): diff --git a/scripts/parser/CsprojParser/CsprojLineParser.py b/scripts/parser/CsprojParser/CsprojLineParser.py index 2237070..f50d7c3 100644 --- a/scripts/parser/CsprojParser/CsprojLineParser.py +++ b/scripts/parser/CsprojParser/CsprojLineParser.py @@ -3,6 +3,11 @@ from parser.CsprojParser.CsprojSetting.KeyValueSetting import KeyValueSetting import re class CsprojLineParser: + def __init__(self, value_provider): + assert value_provider is not None + + self._value_provider = value_provider + def parse(self, line): ws = ' ' csproj_regexp = "^(?Pcsproj)" @@ -56,7 +61,8 @@ class CsprojLineParser: self.__guardMatch(match, statement) key = match.group('key') - value = match.group('value') + value_link = match.group('value') + value = self._value_provider.getValueFor(value_link) setting = KeyValueSetting(key, value) return setting @@ -69,7 +75,8 @@ class CsprojLineParser: self.__guardMatch(match, statement) attribute_name = match.group('attribute_name') - attribute_value = match.group('attribute_value') + value_link = match.group('attribute_value') + attribute_value = self._value_provider.getValueFor(value_link) setting = AttributeSetting(attribute_name, attribute_value) return setting diff --git a/scripts/parser/CsprojParser/CsprojParser.py b/scripts/parser/CsprojParser/CsprojParser.py index d6c238a..25e54bd 100644 --- a/scripts/parser/CsprojParser/CsprojParser.py +++ b/scripts/parser/CsprojParser/CsprojParser.py @@ -3,16 +3,18 @@ from parser.CsprojParser.CsprojLineParser import CsprojLineParser class CsprojParser: - def __init__(self, line_collection): + def __init__(self, line_collection, value_provider): assert line_collection is not None + assert value_provider is not None - self.line_collection = line_collection + self._line_collection = line_collection + self._value_provider = value_provider self.projects_dict = {} def parse(self): settings = [] - for line in self.line_collection: + for line in self._line_collection: settings.append(self.__parse_line(line)) for s in settings: @@ -28,7 +30,7 @@ class CsprojParser: return csproj def __parse_line(self, line): - line_parser = CsprojLineParser() + line_parser = CsprojLineParser(self._value_provider) setting = line_parser.parse(line) return setting \ No newline at end of file