Revision: a480a0e9cc09
Branch:   default
Author:   Tatu Kairi <[email protected]>
Date:     Tue Jun 25 06:55:33 2013
Log:      --removekeywords -options takes additional option name:<pattern>

Update issue 1480
Status: Review

Initial implementation done with tests. Documentation missing but ready for code review.

Need opinion especially what to do with `atest/robot/cli/rebot/remove_keywords/combinations.txt`
http://code.google.com/p/robotframework/source/detail?r=a480a0e9cc09

Modified:
 /atest/robot/cli/rebot/remove_keywords/combinations.txt
 /atest/robot/cli/runner/remove_keywords.txt
 /atest/testdata/cli/remove_keywords/all_combinations.txt
 /src/robot/result/keywordremover.py
 /src/robot/result/testsuite.py

=======================================
--- /atest/robot/cli/rebot/remove_keywords/combinations.txt Mon Sep 17 05:46:37 2012 +++ /atest/robot/cli/rebot/remove_keywords/combinations.txt Tue Jun 25 06:55:33 2013
@@ -35,6 +35,8 @@
     Check Suite Contains Tests    ${SUITE}    Passing    Failing
     ...    For when test fails    For when test passes
     ...    WUKS when test fails    WUKS when test passes
+    ...    NAME when test fails    NAME when test passes
+ ... NAME with pattern when test fails NAME with pattern when test passes

 Create Output
Create Output With Robot ${INPUTFILE} ${EMPTY} cli/remove_keywords/all_combinations.txt
=======================================
--- /atest/robot/cli/runner/remove_keywords.txt Mon Sep 17 07:06:43 2012
+++ /atest/robot/cli/runner/remove_keywords.txt Tue Jun 25 06:55:33 2013
@@ -10,6 +10,10 @@
 ${KEPT FOR MESSAGE}        +FOR -ALL
 ${REMOVED WUKS MESSAGE}    -WUKS -ALL
 ${KEPT WUKS MESSAGE}       +WUKS -ALL
+${REMOVED BY NAME MESSAGE}    -BYNAME -ALL
+${KEPT BY NAME MESSAGE}    +BYNAME -ALL
+${REMOVED BY PATTERN MESSAGE}    -BYPATTERN -ALL
+${KEPT BY PATTERN MESSAGE}    +BYPATTERN -ALL

 *** Test Cases ***

@@ -31,6 +35,15 @@
     Log should contain    ${KEPT WUKS MESSAGE}
     Output should contain WUKS messages

+NAME option
+    Log should not contain    ${REMOVED BY NAME MESSAGE}
+    Log should contain    ${KEPT BY NAME MESSAGE}
+    Output should contain NAME messages
+
+NAME option with pattern
+    Log should not contain    ${REMOVED BY PATTERN MESSAGE}
+    Log should contain    ${KEPT BY PATTERN MESSAGE}
+    Output should contain NAME messages with pattern

 *** Keywords ***

@@ -39,6 +52,8 @@
     ...    --removekeywords passed
     ...    --RemoveKeywords FoR
     ...    --removek WUKS
+    ...    --removekeywords "name:Remove By Name"
+    ...    --removekeywords "name:This should be*"
     ...    --log log.html
     Run tests    ${opts}    cli/remove_keywords/all_combinations.txt
     ${LOG} =    Get file    ${OUTDIR}/log.html
@@ -83,3 +98,26 @@
Check log message ${tc.kws[0].kws[0].kws[1].kws[0].msgs[0]} ${REMOVED WUKS MESSAGE} FAIL Check log message ${tc.kws[0].kws[8].kws[1].kws[0].msgs[0]} ${REMOVED WUKS MESSAGE} FAIL Check log message ${tc.kws[0].kws[9].kws[2].kws[0].msgs[0]} ${KEPT WUKS MESSAGE} FAIL
+
+Output should contain NAME messages
+    Test should contain NAME messages    NAME when test passes
+    Test should contain NAME messages    NAME when test fails
+
+Output should contain NAME messages with pattern
+ Test should contain NAME messages with patterns NAME with pattern when test passes + Test should contain NAME messages with patterns NAME with pattern when test fails
+
+Test should contain NAME messages
+    [Arguments]    ${name}
+    ${tc}=    Check test case    ${name}
+ Check log message ${tc.kws[0].kws[0].msgs[0]} ${REMOVED BY NAME MESSAGE} + Check log message ${tc.kws[1].kws[0].kws[0].msgs[0]} ${REMOVED BY NAME MESSAGE} + Check log message ${tc.kws[1].kws[1].msgs[0]} ${KEPT BY NAME MESSAGE}
+
+Test should contain NAME messages with patterns
+    [Arguments]    ${name}
+    ${tc}=    Check test case    ${name}
+ Check log message ${tc.kws[0].kws[0].msgs[0]} ${REMOVED BY PATTERN MESSAGE} + Check log message ${tc.kws[1].kws[0].msgs[0]} ${REMOVED BY PATTERN MESSAGE} + Check log message ${tc.kws[2].kws[0].kws[0].msgs[0]} ${REMOVED BY PATTERN MESSAGE} + Check log message ${tc.kws[2].kws[1].msgs[0]} ${KEPT BY PATTERN MESSAGE}
=======================================
--- /atest/testdata/cli/remove_keywords/all_combinations.txt Mon Sep 17 05:46:37 2012 +++ /atest/testdata/cli/remove_keywords/all_combinations.txt Tue Jun 25 06:55:33 2013
@@ -6,7 +6,10 @@
 ${KEPT FOR MESSAGE}        +FOR -ALL
 ${REMOVED WUKS MESSAGE}    -WUKS -ALL
 ${KEPT WUKS MESSAGE}       +WUKS -ALL
-
+${REMOVED BY NAME MESSAGE}    -BYNAME -ALL
+${KEPT BY NAME MESSAGE}    +BYNAME -ALL
+${REMOVED BY PATTERN MESSAGE}    -BYPATTERN -ALL
+${KEPT BY PATTERN MESSAGE}    +BYPATTERN -ALL

 *** Test Case ***

@@ -34,6 +37,28 @@
 WUKS when test passes
      Wait Until Keyword Succeeds    2s    0.01s    My WUKS

+NAME when test passes
+    Remove By Name
+    Do not remove by name
+
+NAME when test fails
+    [Documentation]    FAIL this fails
+    Remove By Name
+    Do not remove by name
+    Fail    this fails
+
+NAME with pattern when test passes
+    This should be removed
+    This should be removed also
+    This should not be removed
+
+NAME with pattern when test fails
+    [Documentation]    FAIL this fails
+    This should be removed
+    This should be removed also
+    This should not be removed
+    Fail    this fails
+
 *** Keywords ***

 My FOR
@@ -47,3 +72,20 @@
     Set Test Variable    $COUNTER    ${COUNTER + 1}
     Run Keyword If    ${COUNTER} < 10    Fail    ${REMOVED WUKS MESSAGE}
     Run Keyword If    ${COUNTER} == 10    Fail    ${KEPT WUKS MESSAGE}
+
+Remove By Name
+    Log    ${REMOVED BY NAME MESSAGE}
+
+Do not remove by name
+    Remove By Name
+    Log    ${KEPT BY NAME MESSAGE}
+
+This should be removed
+    Log    ${REMOVED BY PATTERN MESSAGE}
+
+This should be removed also
+    Log    ${REMOVED BY PATTERN MESSAGE}
+
+This should not be removed
+    This should be removed
+    Log    ${KEPT BY PATTERN MESSAGE}
=======================================
--- /src/robot/result/keywordremover.py Mon Jun 10 10:22:16 2013
+++ /src/robot/result/keywordremover.py Tue Jun 25 06:55:33 2013
@@ -18,6 +18,9 @@


 def KeywordRemover(how):
+    if ':' in how and how.startswith('NAME'):
+        _, pattern = how.split(':', 1)
+        return ByNameKeywordRemover(pattern)
     return {
         'PASSED': PassedKeywordRemover,
         'FOR': ForLoopItemsRemover,
@@ -132,3 +135,22 @@

     def set(self, kw, message=None):
kw.doc = ('%s\n\n_%s_' % (kw.doc, message or self._message)).strip()
+
+
+class ByNameKeywordRemover(_KeywordRemover):
+    def __init__(self, pattern):
+        super(ByNameKeywordRemover, self).__init__()
+        self._pattern = pattern.lower()
+
+    def start_keyword(self, keyword):
+        if self._matches(keyword.name):
+            self._clear_content(keyword)
+
+    def _matches(self, kw_name):
+        kw_name = kw_name.lower()
+        if '*' in self._pattern:
+            pattern = self._pattern.split('*', 1)[0]
+            return kw_name.startswith(pattern)
+        return kw_name == self._pattern
+
+
=======================================
--- /src/robot/result/testsuite.py      Tue Jun 11 04:48:21 2013
+++ /src/robot/result/testsuite.py      Tue Jun 25 06:55:33 2013
@@ -115,7 +115,9 @@
     def remove_keywords(self, how):
         """Remove keywords based on the given condition.

-        :param how: Is either ``ALL``, ``PASSED``, ``FOR``, or ``WUKS``.
+        :param how: Is either ``ALL``, ``PASSED``, ``FOR``, ``WUKS``, or
+                    ``NAME:<pattern>``.
+
These values have exact same semantics as values accepted by
                     ``--removekeywords`` command line option.
         """

--

--- 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 [email protected].
For more options, visit https://groups.google.com/groups/opt_out.


Reply via email to