Revision: 2107d1d1f08f
Branch:   default
Author:   Robot Framework Developers (robotframew...@gmail.com)
Date:     Thu Oct 24 11:35:16 2013 UTC
Log:      Initial implementation for flattening keywords when reading XML.

Update issue 1551
Status: Started
Owner: pekka.klarck
Initial implementation based on a standalone script I wrote earlier.
Integrating that functionality to the core turned out to be rather
straightforward. Plenty of tasks still to do, though:

1) Require patterns to be given as NAME:<pattern>. Currently given values are
   used as-is.

2) Tests.

3) --help documentation

4) UG documentation.
http://code.google.com/p/robotframework/source/detail?r=2107d1d1f08f

Modified:
 /src/robot/conf/settings.py
 /src/robot/rebot.py
 /src/robot/reporting/resultwriter.py
 /src/robot/result/resultbuilder.py
 /src/robot/run.py

=======================================
--- /src/robot/conf/settings.py Wed Sep 11 15:47:19 2013 UTC
+++ /src/robot/conf/settings.py Thu Oct 24 11:35:16 2013 UTC
@@ -52,6 +52,7 @@
                  'TagDoc'           : ('tagdoc', []),
                  'TagStatLink'      : ('tagstatlink', []),
                  'RemoveKeywords'   : ('removekeywords', []),
+                 'FlattenKeywords'  : ('flattenkeywords', []),
                  'NoStatusRC'       : ('nostatusrc', False),
                  'MonitorColors'    : ('monitorcolors', 'AUTO'),
                  'StdOut'           : ('stdout', None),
@@ -336,6 +337,14 @@
     def non_critical_tags(self):
         return self['NonCritical']

+    @property
+    def remove_keywords(self):
+        return self['RemoveKeywords']
+
+    @property
+    def flatten_keywords(self):
+        return self['FlattenKeywords']
+

 class RobotSettings(_BaseSettings):
     _extra_cli_opts = {'Output'             : ('output', 'output.xml'),
@@ -439,7 +448,7 @@
             'include_suites': self['SuiteNames'],
             'include_tests': self['TestNames'],
             'empty_suite_ok': self['ProcessEmptySuite'],
-            'remove_keywords': self['RemoveKeywords'],
+            'remove_keywords': self.remove_keywords,
             'log_level': self['LogLevel'],
             'critical_tags': self.critical_tags,
             'non_critical_tags': self.non_critical_tags,
=======================================
--- /src/robot/rebot.py Wed Sep 11 15:47:19 2013 UTC
+++ /src/robot/rebot.py Thu Oct 24 11:35:16 2013 UTC
@@ -201,7 +201,8 @@
                           for:     remove passed iterations from for loops
                           wuks:    remove all but the last failing keyword
from `BuiltIn.Wait Until Keyword Succeeds`
-                          none:    remove nothing (default)
+                          none:    remove nothing (default behavior)
+    --flattenkeywords name:<pattern> *
--starttime timestamp Set starting time of test execution when creating
                           reports. Timestamp must be given in format
`2007-10-01 15:12:42.268` where all separators are
=======================================
--- /src/robot/reporting/resultwriter.py        Sat Jun  8 00:35:54 2013 UTC
+++ /src/robot/reporting/resultwriter.py        Thu Oct 24 11:35:16 2013 UTC
@@ -113,8 +113,10 @@
     def result(self):
         if self._result is None:
include_keywords = bool(self._settings.log or self._settings.output) - self._result = ExecutionResult(include_keywords=include_keywords,
-                                           *self._sources)
+            flattened = self._settings.flatten_keywords
+            self._result = ExecutionResult(*self._sources,
+ include_keywords=include_keywords,
+                                           flattened_keywords=flattened)
             self._result.configure(self._settings.status_rc,
                                    self._settings.suite_config,
                                    self._settings.statistics_config)
=======================================
--- /src/robot/result/resultbuilder.py  Sat Jun  8 09:14:24 2013 UTC
+++ /src/robot/result/resultbuilder.py  Thu Oct 24 11:35:16 2013 UTC
@@ -15,7 +15,7 @@
 from __future__ import with_statement

 from robot.errors import DataError
-from robot.utils import ET, ETSource, get_error_message
+from robot.utils import ET, ETSource, MultiMatcher, get_error_message

 from .xmlelementhandlers import XmlElementHandler
 from .executionresult import Result, CombinedResult
@@ -55,7 +55,7 @@

 class ExecutionResultBuilder(object):

-    def __init__(self, source, include_keywords=True):
+ def __init__(self, source, include_keywords=True, flattened_keywords=None):
         """Builds :class:`~.executionresult.Result` objects from existing
         output XML files on the file system.

@@ -66,6 +66,7 @@
         self._source = source \
             if isinstance(source, ETSource) else ETSource(source)
         self._include_keywords = include_keywords
+        self._flattened_keywords = flattened_keywords

     def build(self, result):
# Parsing is performance optimized. Do not change without profiling!
@@ -79,6 +80,8 @@
         context = ET.iterparse(source, events=('start', 'end'))
         if not self._include_keywords:
             context = self._omit_keywords(context)
+        elif self._flattened_keywords:
+ context = self._flatten_keywords(context, self._flattened_keywords)
         for event, elem in context:
             if event == 'start':
                 start(elem)
@@ -99,3 +102,23 @@
                 elem.clear()
             if kw and not start:
                 started_kws -= 1
+
+    def _flatten_keywords(self, context, flattened):
+        match = MultiMatcher(flattened).match
+        started = -1
+        for event, elem in context:
+            tag = elem.tag
+            if event == 'start' and tag == 'kw':
+                if started >= 0:
+                    started += 1
+                elif match(elem.attrib['name']):
+                    started = 0
+            if started == 0 and event == 'start' and tag == 'doc':
+                elem.text = ('%s\n\n_*Keyword content flattened.*_'
+                             % (elem.text or '')).strip()
+            if started <= 0 or tag == 'msg':
+                yield event, elem
+            else:
+                elem.clear()
+            if started >= 0 and event == 'end' and tag == 'kw':
+                started -= 1
=======================================
--- /src/robot/run.py   Wed Sep 11 15:47:19 2013 UTC
+++ /src/robot/run.py   Thu Oct 24 11:35:16 2013 UTC
@@ -240,7 +240,8 @@
                           for:     remove passed iterations from for loops
                           wuks:    remove all but the last failing keyword
from `BuiltIn.Wait Until Keyword Succeeds`
-                          none:    remove nothing (default)
+                          none:    remove nothing (default behavior)
+    --flattenkeywords name:<pattern> *
     --listener class *    A class for monitoring test execution. Gets
notifications e.g. when a test case starts and ends. Arguments to listener class can be given after class

--

--- You received this message because you are subscribed to the Google Groups "robotframework-commit" group.
To unsubscribe from this group and stop receiving emails from it, send an email 
to robotframework-commit+unsubscr...@googlegroups.com.
For more options, visit https://groups.google.com/groups/opt_out.

Reply via email to