Revision: 3328
Author: janne.t.harkonen
Date: Wed May 19 04:06:46 2010
Log: Added support for comments in variable table
http://code.google.com/p/robotframework/source/detail?r=3328

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

=======================================
--- /trunk/src/robot/parsing/newmodel.py        Wed May 19 03:09:49 2010
+++ /trunk/src/robot/parsing/newmodel.py        Wed May 19 04:06:46 2010
@@ -114,8 +114,8 @@
     def __init__(self):
         self.variables = []

-    def add(self, name, value, comment=None):
-        self.variables.append(Variable(name, value))
+    def add(self, name, value, comment):
+        self.variables.append(Variable(name, value, comment))

     def __iter__(self):
         return iter(self.variables)
@@ -158,13 +158,14 @@

 class Variable(object):

-    def __init__(self, name, value):
+    def __init__(self, name, value, comment):
         self.name = name.rstrip('= ')
         if name.startswith('$') and value == []:
             value = ''
         if isinstance(value, basestring):
             value = [value]  # Need to support scalar lists until RF 2.6
         self.value = value
+        self.comment = comment


 class WithSteps(object):
=======================================
--- /trunk/src/robot/parsing/populator.py       Wed May 19 03:34:08 2010
+++ /trunk/src/robot/parsing/populator.py       Wed May 19 04:06:46 2010
@@ -120,7 +120,7 @@
         return datafile.variable_table

     def _get_populator(self, row):
-        return NameAndValuePropertyPopulator(self._table.add)
+        return VariablePopulator(self._table.add)


 class TestTablePopulator(_TablePopulator):
@@ -280,6 +280,14 @@
         self._setter(name, value, self._comments.formatted_value())


+class VariablePopulator(NameAndValuePropertyPopulator):
+
+    def _add(self, row):
+        if row.is_continuing():
+            row = row.dedent()
+        self._value.extend(row.all)
+
+
 class SettingPopulator(_PropertyPopulator):

     def _add(self, row):
=======================================
--- /trunk/utest/parsing/test_populator.py      Wed May 19 03:34:08 2010
+++ /trunk/utest/parsing/test_populator.py      Wed May 19 04:06:46 2010
@@ -58,6 +58,12 @@
         assert_equals(meta.value, exp_value)
         self._assert_comment(meta, exp_comment)

+ def _assert_variable(self, index, exp_name, exp_value, exp_comment=None):
+        var = self._datafile.variable_table.variables[index]
+        assert_equals(var.name, exp_name)
+        assert_equals(var.value, exp_value)
+        self._assert_comment(var, exp_comment)
+
     def _assert_comment(self, item, exp_comment):
         if exp_comment:
             assert_equals(item.comment, exp_comment)
@@ -92,7 +98,8 @@
         doc = 'This is doc'
         setup_name, setup_args = 'Keyword Name', ['a1', 'a2']
         self._create_table('Settings', [['Documentation', doc],
- ['S uite SeTUp'] + [setup_name] + setup_args])
+                                        ['S  uite SeTUp'] + [setup_name],
+                                        ['...'] + setup_args])
         self._assert_setting('doc', doc)
         self._assert_fixture('suite_setup', setup_name, setup_args)

@@ -122,7 +129,8 @@
                                          ['@{list}', 'v1', 'v2'],
                                          ['...', 'v3', 'v4']])
         assert_equals(len(self._datafile.variable_table.variables), 2)
- assert_equals(self._datafile.variable_table.variables[0].name, '${scalar}')
+        self._assert_variable(0, '${scalar}', ['value'])
+        self._assert_variable(1, '@{list}', ['v1', 'v2', 'v3', 'v4'])

     def test_setting_in_multiple_rows(self):
         self._create_table('Settings', [['Documentation', 'Part 1'],
@@ -299,7 +307,7 @@
         self._datafile = TestCaseFile()
         self._populator = TestDataPopulator(self._datafile)

-    def test_end_of_line_setting_comment(self):
+    def test_setting_table(self):
self._create_table('settings', [['Force Tags', 'Foo', 'Bar', '#comment'],
                                         ['Library', 'Foo', '#Lib comment'],
['#comment', 'between rows', 'in many cells'],
@@ -316,6 +324,10 @@
         self._assert_import(1, 'varz.py', ['arg'], ' between values')
self._assert_meta(0, 'metaname', 'metavalue', 'last line is commented')

+    def test_variable_table(self):
+ self._create_table('variables', [['${varname}', 'varvalue', '#has comment'],
+                                         ])
+        self._assert_variable(0, '${varname}', ['varvalue'], 'has comment')

 if __name__ == '__main__':
     unittest.main()

Reply via email to