2 new revisions:

Revision: 115a0fd4613c
Author:   Janne Härkönen <[email protected]>
Date:     Tue Jan 17 00:34:57 2012
Log:      parsing.model: prune old style headers
http://code.google.com/p/robotframework/source/detail?r=115a0fd4613c

Revision: aaa63036e01f
Author:   Janne Härkönen <[email protected]>
Date:     Tue Jan 17 00:49:38 2012
Log:      TidyLib: cleanup and keyword docs
http://code.google.com/p/robotframework/source/detail?r=aaa63036e01f

==============================================================================
Revision: 115a0fd4613c
Author:   Janne Härkönen <[email protected]>
Date:     Tue Jan 17 00:34:57 2012
Log:      parsing.model: prune old style headers
http://code.google.com/p/robotframework/source/detail?r=115a0fd4613c

Modified:
 /src/robot/parsing/model.py
 /utest/parsing/test_model.py

=======================================
--- /src/robot/parsing/model.py Wed Dec 14 05:29:24 2011
+++ /src/robot/parsing/model.py Tue Jan 17 00:34:57 2012
@@ -222,7 +222,14 @@
         self._header = None

     def set_header(self, header):
-        self._header = header
+        self._header = self._prune_old_style_headers(header)
+
+    def _prune_old_style_headers(self, header):
+        if len(header) < 3:
+            return header
+        if self._old_header_matcher.match(header):
+            return [header[0]]
+        return header

     @property
     def header(self):
@@ -283,6 +290,10 @@
             adder_method(name, value[1:], comment)
         return adder

+    @property
+    def _old_header_matcher(self):
+        return OldStyleSettingAndVariableTableHeaderMatcher()
+
     def add_metadata(self, name, value='', comment=None):
self.metadata.append(Metadata('Metadata', self, name, value, comment))
         return self.metadata[-1]
@@ -377,6 +388,10 @@
         _Table.__init__(self, parent)
         self.variables = []

+    @property
+    def _old_header_matcher(self):
+        return OldStyleSettingAndVariableTableHeaderMatcher()
+
     def add(self, name, value, comment=None):
         self.variables.append(Variable(name, value, comment))

@@ -394,6 +409,10 @@
         _Table.__init__(self, parent)
         self.tests = []

+    @property
+    def _old_header_matcher(self):
+        return OldStyleTestAndKeywordTableHeaderMatcher()
+
     def add(self, name):
         self.tests.append(TestCase(self, name))
         return self.tests[-1]
@@ -415,6 +434,10 @@
         _Table.__init__(self, parent)
         self.keywords = []

+    @property
+    def _old_header_matcher(self):
+        return OldStyleTestAndKeywordTableHeaderMatcher()
+
     def add(self, name):
         self.keywords.append(UserKeyword(self, name))
         return self.keywords[-1]
@@ -620,3 +643,21 @@
         if include_comment and self.comment:
             ret += self.comment.as_list()
         return ret
+
+
+class OldStyleSettingAndVariableTableHeaderMatcher(object):
+
+    def match(self, header):
+        return all((True if e.lower() == 'value' else False)
+                    for e in header[1:])
+
+
+class OldStyleTestAndKeywordTableHeaderMatcher(object):
+
+    def match(self, header):
+        if header[1].lower() != 'action':
+            return False
+        for h in header[2:]:
+            if not h.lower().startswith('arg'):
+                return False
+        return True
=======================================
--- /utest/parsing/test_model.py        Tue Oct 11 21:34:35 2011
+++ /utest/parsing/test_model.py        Tue Jan 17 00:34:57 2012
@@ -129,6 +129,10 @@
         assert_equal(imp.alias, alias)
         assert_equal(imp.type, type(imp).__name__)

+    def test_old_style_headers_are_ignored(self):
+        self.table.set_header(['Settings', 'Value', 'value', 'Value'])
+        assert_equals(self.table.header, ['Settings'])
+

 class TestVariableTable(unittest.TestCase):

@@ -161,6 +165,10 @@
         assert_equal(self.table.variables[0].name, 'not var')
         assert_equal(self.table.variables[0].value, ['the value'])

+    def test_old_style_headers_are_ignored(self):
+        self.table.set_header(['Variable', 'value', 'Value'])
+        assert_equals(self.table.header, ['Variable'])
+

 class TestTestCaseTable(unittest.TestCase):

@@ -200,6 +208,10 @@
         loop = self.test.add_for_loop(['${var}', 'IN', 'value'])
         assert_equal(self.test.steps, [loop])

+    def test_old_style_headers_are_ignored(self):
+        self.table.set_header(['test case', 'Action', 'Arg', 'Argument'])
+        assert_equals(self.table.header, ['test case'])
+

 class TestKeywordTable(unittest.TestCase):

@@ -239,6 +251,10 @@
         loop = self.kw.add_for_loop(['${var}', 'IN', 'value'])
         assert_equal(self.kw.steps, [loop])

+    def test_old_style_headers_are_ignored(self):
+        self.table.set_header(['keywords', 'Action', 'Arg', 'Argument'])
+        assert_equals(self.table.header, ['keywords'])
+

 class TestStep(unittest.TestCase):


==============================================================================
Revision: aaa63036e01f
Author:   Janne Härkönen <[email protected]>
Date:     Tue Jan 17 00:49:38 2012
Log:      TidyLib: cleanup and keyword docs
http://code.google.com/p/robotframework/source/detail?r=aaa63036e01f

Modified:
 /atest/robot/tidy/TidyLib.py
 /atest/robot/tidy/tidy.txt

=======================================
--- /atest/robot/tidy/TidyLib.py        Tue Jan 17 00:30:48 2012
+++ /atest/robot/tidy/TidyLib.py        Tue Jan 17 00:49:38 2012
@@ -1,8 +1,10 @@
 from __future__ import with_statement
+
 import os
 from os.path import abspath, dirname, join
 from subprocess import call, STDOUT
 import tempfile
+
 from robot import DataError
 from robot.utils.asserts import assert_equals
 from robot.tidy import TidyCommandLine
@@ -19,8 +21,8 @@
         self._env = os.environ
         self._env.update({path_var: ROBOT_SRC})

-
-    def run_tidy_and_return_output(self, input, options):
+    def run_tidy_and_return_output(self, options, input):
+        """Runs tidy in the operating system and returns output."""
         options = options.split(' ') if options else []
         with tempfile.TemporaryFile() as output:
             rc = call(self._cmd + options + [self._path(input)],
@@ -32,8 +34,9 @@
                 raise RuntimeError(content)
             return content

-    def run_tidy_and_check_result(self, input, options, expected):
-        result = self.run_tidy_and_return_output(input, options)
+    def run_tidy_and_check_result(self, options, input, expected):
+ """Runs tidy and checks that output matches content of file `expected`."""
+        result = self.run_tidy_and_return_output(options, input)
         self._assert_result(result, open(self._path(expected)).read())

     def _path(self, path):
@@ -45,7 +48,9 @@
             assert_equals(repr(unicode(line1)), repr(unicode(line2)), msg)

     def run_tidy(self, argument_string):
+ """Runs tidy programmatically. Fails if there are any expections."""
+        runner = TidyCommandLine(robot.tidy.__doc__)
         try:
- TidyCommandLine(robot.tidy.__doc__).run([str(a) for a in argument_string.split()])
+            runner.run([str(a) for a in argument_string.split()])
         except DataError, err:
             raise RuntimeError(unicode(err))
=======================================
--- /atest/robot/tidy/tidy.txt  Mon Jan 16 05:02:08 2012
+++ /atest/robot/tidy/tidy.txt  Tue Jan 17 00:49:38 2012
@@ -26,17 +26,17 @@
     --format html    ${DATADIR}/golden_resource.html

 Tidying single init file
- Run tidy and check result ${DATADIR}/__init__.txt ${EMPTY} ${DATADIR}/__init__.txt + Run tidy and check result ${EMPTY} ${DATADIR}/__init__.txt ${DATADIR}/__init__.txt

 Tidying single file in place
     [Setup]    Copy File    ${DATADIR}/golden.txt    ${TIDYDIR}/golden.txt
- Run tidy and check result ${TIDYDIR}/golden.txt --inplace --use-pipes ${DATADIR}/golden_pipes.txt + Run tidy and check result --inplace --use-pipes ${TIDYDIR}/golden.txt ${DATADIR}/golden_pipes.txt
     Check file count    ${TIDYDIR}    *.txt    1
     [Teardown]    Empty Directory     ${TIDYDIR}

 Tidying single file in place and change format
     [Setup]    Copy File    ${DATADIR}/golden.txt    ${TIDYDIR}/golden.txt
- Run tidy and check result ${TIDYDIR}/golden.txt --inplace --format html ${DATADIR}/golden.html + Run tidy and check result --inplace --format html ${TIDYDIR}/golden.txt ${DATADIR}/golden.html
     Check file count    ${TIDYDIR}    *.html    1
     Check file count    ${TIDYDIR}    *.txt    0
     [Teardown]    Empty Directory     ${TIDYDIR}
@@ -44,7 +44,7 @@
 Tidying many files in place
     [Setup]    Copy Golden Files
     List Directory      ${TIDYDIR}
- Run tidy and return output ${TIDYDIR}/golden* --inplace --format html + Run tidy and return output --inplace --format html ${TIDYDIR}/golden*
     List Directory      ${TIDYDIR}
     Check file count    ${TIDYDIR}    *.html    2
     Check file count    ${TIDYDIR}    *.txt    0
@@ -54,7 +54,7 @@
 Tidying directory
     [Setup]    Copy Directory    ${DATADIR}/tests    ${TEMPDIR}/tests
     ${output_before}=    Run Robot Directly    ${DATADIR}/tests
- Run Tidy and return output ${TEMPDIR}/tests --recursive --format tsv + Run Tidy and return output --recursive --format tsv ${TEMPDIR}/tests
     Check file count    ${TEMPDIR}/tests    *.tsv    2
     Check file count    ${TEMPDIR}/tests    *.txt    0
     ${output_after}=    Run Robot Directly    ${TEMPDIR}/tests
@@ -64,11 +64,11 @@
 *** Keywords ***
 Run tidy with golden file and check result
     [Arguments]    ${options}    ${expected_result_file}
- Run tidy and check result ${DATADIR}/golden.txt ${options} ${expected_result_file} + Run tidy and check result ${options} ${DATADIR}/golden.txt ${expected_result_file}

 Run tidy with golden resource file and check result
     [Arguments]    ${options}    ${expected_result_file}
- Run tidy and check result ${DATADIR}/golden_resource.txt ${options} ${expected_result_file} + Run tidy and check result ${options} ${DATADIR}/golden_resource.txt ${expected_result_file}

 Check file count
     [Arguments]    ${directory}    ${pattern}    ${expected count}

Reply via email to