Revision: 3327
Author: janne.t.harkonen
Date: Wed May 19 03:34:08 2010
Log: handle multiline and multicells comments
http://code.google.com/p/robotframework/source/detail?r=3327

Modified:
 /trunk/src/robot/parsing/populator.py
 /trunk/utest/parsing/test_populator.py

=======================================
--- /trunk/src/robot/parsing/populator.py       Wed May 19 03:09:49 2010
+++ /trunk/src/robot/parsing/populator.py       Wed May 19 03:34:08 2010
@@ -244,18 +244,30 @@
                                           'Timeout': 'timeout'})


+class Comments(object):
+
+    def __init__(self):
+        self._crows = []
+
+    def add(self, row):
+        if row.comments:
+            self._crows.append(row.comments)
+
+    def formatted_value(self):
+        return '\n'.join(' | '.join(row) for row in self._crows)
+
+
 class _PropertyPopulator(Populator):
-    comments = property(lambda self: ''.join(self._comments))

     def __init__(self, setter):
         self._setter = setter
         self._value = []
-        self._comments = []
+        self._comments = Comments()

     def add(self, row):
         if not row.is_commented():
             self._add(row)
-        self._comments.extend(row.comments)
+        self._comments.add(row)


 class NameAndValuePropertyPopulator(_PropertyPopulator):
@@ -265,7 +277,7 @@

     def populate(self):
         name, value = self._value[0], self._value[1:]
-        self._setter(name, value, self.comments)
+        self._setter(name, value, self._comments.formatted_value())


 class SettingPopulator(_PropertyPopulator):
@@ -274,7 +286,7 @@
         self._value.extend(row.tail)

     def populate(self):
-        self._setter(self._value, self.comments)
+        self._setter(self._value, self._comments.formatted_value())


 class SettingTableNameValuePopulator(NameAndValuePropertyPopulator):
=======================================
--- /trunk/utest/parsing/test_populator.py      Wed May 19 03:09:49 2010
+++ /trunk/utest/parsing/test_populator.py      Wed May 19 03:34:08 2010
@@ -302,8 +302,8 @@
     def test_end_of_line_setting_comment(self):
self._create_table('settings', [['Force Tags', 'Foo', 'Bar', '#comment'],
                                         ['Library', 'Foo', '#Lib comment'],
-                                        ['#comment between rows'],
-                                        ['Default Tags', 'Quux'],
+ ['#comment', 'between rows', 'in many cells'], + ['Default Tags', 'Quux', '#also end of line'],
                                         ['Variables', 'varz.py'],
                                         ['# between values'],
                                         ['...', 'arg'],
@@ -312,7 +312,7 @@
                                         ])
         self._assert_setting('force_tags', ['Foo', 'Bar'], 'comment')
         self._assert_import(0, 'Foo', [], 'Lib comment')
- self._assert_setting('default_tags', ['Quux'], 'comment between rows') + self._assert_setting('default_tags', ['Quux'], 'comment | between rows | in many cells\nalso end of line')
         self._assert_import(1, 'varz.py', ['arg'], ' between values')
self._assert_meta(0, 'metaname', 'metavalue', 'last line is commented')

Reply via email to