Revision: 3344
Author: janne.t.harkonen
Date: Thu May 20 03:30:13 2010
Log: started adding support for comments in test case table
http://code.google.com/p/robotframework/source/detail?r=3344

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        Thu May 20 03:13:42 2010
+++ /trunk/src/robot/parsing/newmodel.py        Thu May 20 03:30:13 2010
@@ -212,8 +212,8 @@

 class _WithSteps(object):

-    def add_step(self, content):
-        self.steps.append(Step(content))
+    def add_step(self, content, comment=None):
+        self.steps.append(Step(content, comment))
         return self.steps[-1]


@@ -261,13 +261,14 @@

 class Step(object):

-    def __init__(self, content):
+    def __init__(self, content, comment=None):
         self.assign = self._get_assigned_vars(content)
         try:
             self.keyword = content[len(self.assign)]
         except IndexError:
             self.keyword = ''
         self.args = content[len(self.assign)+1:]
+        self.comment = comment

     def _get_assigned_vars(self, content):
         vars = []
=======================================
--- /trunk/src/robot/parsing/populator.py       Wed May 19 04:06:46 2010
+++ /trunk/src/robot/parsing/populator.py       Thu May 20 03:30:13 2010
@@ -40,7 +40,7 @@
         self._comments = []

     def add(self, row):
-        if row.is_commented():
+        if self._is_cacheable_comment_row(row):
             self._comments.append(row)
             return
         if not self._is_continuing(row):
@@ -61,6 +61,9 @@
     def _is_continuing(self, row):
         return row.is_continuing()

+    def _is_cacheable_comment_row(self, row):
+        return row.is_commented()
+

 class SettingTablePopulator(_TablePopulator):
     olde_metadata_prefix = 'meta:'
@@ -132,7 +135,10 @@
         return TestCasePopulator(self._table.add)

     def _is_continuing(self, row):
-        return row.is_indented()
+        return row.is_indented() or row.is_commented()
+
+    def _is_cacheable_comment_row(self, row):
+ return row.is_commented() and isinstance(self._populator, NullPopulator)

 class KeywordTablePopulator(_TablePopulator):

@@ -182,8 +188,12 @@
         self._test_or_uk_creator = test_or_uk_creator
         self._test_or_uk = None
         self._populator = NullPopulator()
+        self._comments = []

     def add(self, row):
+        if row.is_commented():
+            self._comments.append(row)
+            return
         if not self._test_or_uk:
             self._test_or_uk = self._test_or_uk_creator(row.head)
         dedented_row = row.dedent()
@@ -191,10 +201,23 @@
             if not self._continues(dedented_row):
                 self._populator.populate()
                 self._populator = self._get_populator(dedented_row)
+                self._populate_cached_comments()
+            else:
+                for crow in self._comments:
+                    self._populator.add(crow)
+                self._comments = []
             self._populator.add(dedented_row)

+    def _populate_cached_comments(self):
+        for crow in self._comments:
+            populator = StepPopulator(self._test_or_uk.add_step)
+            populator.add(crow)
+            populator.populate()
+        self._comments = []
+
     def populate(self):
         self._populator.populate()
+        self._populate_cached_comments()

     def _get_populator(self, row):
         if row.starts_test_or_user_keyword_setting():
@@ -322,12 +345,14 @@

 class StepPopulator(_PropertyPopulator):

-    def add(self, row):
+    def _add(self, row):
+        if row.is_continuing():
+            row = row.dedent()
         self._value.extend(row.all)

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


 class NullPopulator(Populator):
@@ -394,15 +419,17 @@
         self.all = self.cells

     def dedent(self):
-        return DataRow(self.tail)
+        dedented = DataRow(self.tail)
+        dedented.comments = self.comments
+        return dedented

     def startswith(self, value):
         return self.head() == value

     def starts_for_loop(self):
-        if not self.head.startswith(':'):
-            return False
-        return self.head.replace(':', '').upper().strip() == 'FOR'
+        if self.head and self.head.startswith(':'):
+            return self.head.replace(':', '').upper().strip() == 'FOR'
+        return False

     def starts_test_or_user_keyword_setting(self):
         head = self.head
@@ -415,7 +442,7 @@
         return self.head == self._row_continuation_marker

     def is_commented(self):
-        return not self.cells and self.comments
+        return bool(not self.cells and self.comments)

     def _parse(self, row):
         return self._purge_empty_cells(self._extract_data(row)), \
=======================================
--- /trunk/utest/parsing/test_populator.py      Wed May 19 04:59:59 2010
+++ /trunk/utest/parsing/test_populator.py      Thu May 20 03:30:13 2010
@@ -2,7 +2,7 @@
 import os
 from StringIO import StringIO

-from robot.parsing.populator import TestDataPopulator
+from robot.parsing.populator import TestDataPopulator, DataRow
 from robot.parsing.newmodel import TestCaseFile
 from robot.utils.asserts import assert_equals, assert_true, assert_false

@@ -71,6 +71,12 @@
     def _setting_with(self, name):
         return getattr(self._datafile.setting_table, name)

+    def _nth_test(self, index):
+        return self._datafile.testcase_table.tests[index-1]
+
+    def _first_test(self):
+        return self._nth_test(1)
+

 class TestCaseFilePopulatingTest(_PopulatorTest):

@@ -288,12 +294,6 @@
         if eof:
             self._populator.eof()

-    def _nth_test(self, index):
-        return self._datafile.testcase_table.tests[index-1]
-
-    def _first_test(self):
-        return self._nth_test(1)
-
     def _nth_uk(self, index):
         return self._datafile.keyword_table.keywords[index]

@@ -336,5 +336,27 @@
self._assert_variable(1, '@{items}', ['1', '2', '3'], 'label | A | B | C') self._assert_variable(2, '${ohtervarname}', ['otherval'], '#end comment\ncomment\nEOT')

+    def test_test_case_table(self):
+        self._create_table('test cases', [['#start of table comment'],
+                                          ['Test case'],
+ ['', 'No operation', '#step comment'], + ['', '', '#This step has only comment'], + ['Another test', '#comment in name row'],
+                                          ['', 'Log many', 'argh'],
+ ['#', 'Comment between step def'],
+                                          ['', '...', 'urgh']
+                                          ])
+ assert_equals(self._first_test().steps[0].comment, 'start of table comment')
+        assert_equals(self._first_test().steps[1].comment, 'step comment')
+ assert_equals(self._first_test().steps[2].comment, 'This step has only comment') + assert_equals(self._nth_test(2).steps[0].comment, 'comment in name row') + assert_equals(self._nth_test(2).steps[1].comment, ' | Comment between step def')
+        assert_equals(self._nth_test(2).steps[1].args, ['argh', 'urgh'])
+
+class DataRowTest(unittest.TestCase):
+
+    def test_commented_row(self):
+        assert_true(DataRow(['#start of table comment']).is_commented())
+
 if __name__ == '__main__':
     unittest.main()

Reply via email to