2 new revisions:

Revision: 16a29bd4e450
Author:   Pekka Klärck
Date:     Sat Jun 11 14:51:08 2011
Log: Implementation and tests for ignoring variables in embedded args durin...
http://code.google.com/p/robotframework/source/detail?r=16a29bd4e450

Revision: a1530c26bee6
Author:   Pekka Klärck
Date:     Sat Jun 11 15:59:22 2011
Log:      Keyword type to start/end_keyword listener methods...
http://code.google.com/p/robotframework/source/detail?r=a1530c26bee6

==============================================================================
Revision: 16a29bd4e450
Author:   Pekka Klärck
Date:     Sat Jun 11 14:51:08 2011
Log: Implementation and tests for ignoring variables in embedded args during dry-run. Also some cleanup for existing tests.

Update issue 860
Status: Done
I had a little extra time and decided to create the tests for this so that the issue can be closed.
http://code.google.com/p/robotframework/source/detail?r=16a29bd4e450

Modified:
 /atest/robot/cli/dryrun/dryrun.txt
 /atest/testdata/cli/dryrun/dryrun.txt
 /src/robot/running/userkeyword.py

=======================================
--- /atest/robot/cli/dryrun/dryrun.txt  Mon May  9 04:35:19 2011
+++ /atest/robot/cli/dryrun/dryrun.txt  Sat Jun 11 14:51:08 2011
@@ -8,17 +8,48 @@
 Passing keywords
     ${tc}=  Check Test Case  ${TESTNAME}
     Should have correct number of keywords  ${tc}  3
-    Status should be  ${tc}  PASS
-    Status should be  ${tc.kws[0]}  NOT_RUN
-    Should have correct number of keywords  ${tc.kws[2]}  1
-
-Userkeyword return value
-    Check Test Case  ${TESTNAME}
+    Name and status should be  ${tc.kws[0]}  BuiltIn.Log  NOT_RUN
+ Name and status should be ${tc.kws[1]} \${contents} = OperatingSystem.List Directory NOT_RUN
+    Name and status should be  ${tc.kws[2]}  resource.Simple UK  PASS
+    Name and status should be  ${tc.kws[2].kws[0]}  BuiltIn.Log  NOT_RUN
+
+Keywords with embedded arguments
+    ${tc}=  Check Test Case  ${TESTNAME}
+    Should have correct number of keywords  ${tc}  2
+    Name and status should be  ${tc.kws[0]}  Embedded arguments here  PASS
+ Name and status should be ${tc.kws[0].kws[0]} BuiltIn.No Operation NOT_RUN
+    Name and status should be  ${tc.kws[1]}  Embedded args rock here  PASS
+ Name and status should be ${tc.kws[1].kws[0]} BuiltIn.No Operation NOT_RUN

 Keywords that would fail
     ${tc}=  Check Test Case  ${TESTNAME}
     Should have correct number of keywords  ${tc}  3
+    Name and status should be  ${tc.kws[0]}  BuiltIn.Fail  NOT_RUN
+    Name and status should be  ${tc.kws[1]}  resource.Fail In UK  PASS
     Should have correct number of keywords  ${tc.kws[1]}  2
+    Name and status should be  ${tc.kws[1].kws[0]}  BuiltIn.Fail  NOT_RUN
+    Name and status should be  ${tc.kws[1].kws[1]}  BuiltIn.Fail  NOT_RUN
+
+Scalar variables are not checked in keyword arguments
+ [Documentation] Variables are too often set somehow dynamically that we cannot expect them to always exist.
+    ${tc}=  Check Test Case  ${TESTNAME}
+    Name and status should be  ${tc.kws[0]}  BuiltIn.Log  NOT_RUN
+    Name and status should be  ${tc.kws[1]}  BuiltIn.Log  NOT_RUN
+
+List variables are not checked in keyword arguments
+    [Documentation]  See the doc of the previous test
+    Check Test Case  ${TESTNAME}
+
+Variables are not checked in when arguments are embedded
+    [Documentation]  See the doc of the previous test
+    ${tc}=  Check Test Case  ${TESTNAME}
+ Name and status should be ${tc.kws[0]} Embedded \${TESTNAME} here PASS + Name and status should be ${tc.kws[0].kws[0]} BuiltIn.No Operation NOT_RUN
+    Name and status should be  ${tc.kws[1]}  Embedded \${nonex} here  PASS
+ Name and status should be ${tc.kws[1].kws[0]} BuiltIn.No Operation NOT_RUN
+
+User keyword return value
+    Check Test Case  ${TESTNAME}

 Test Setup and Teardown
     ${tc}=  Check Test Case  ${TESTNAME}
@@ -53,9 +84,6 @@

 Invalid syntax in UK
     Check Test Case  ${TESTNAME}
-
-Arguments given as list variable
-    Check Test Case  ${TESTNAME}

 Multiple Failures
     Check Test Case  ${TESTNAME}
@@ -74,7 +102,7 @@
     Log  ${test or uk.kws}
Should Be Equal As Integers ${test or uk.kw_count} ${exp number of kws}

-Status should be
-    [Arguments]  ${tc or kw}  ${exp status}
-    Should Be Equal  ${tc or kw.status}  ${exp status}
-
+Name and status should be
+    [Arguments]  ${kw}  ${name}  ${status}
+    Should Be Equal  ${kw.name}    ${name}
+    Should Be Equal  ${kw.status}  ${status}
=======================================
--- /atest/testdata/cli/dryrun/dryrun.txt       Mon May  9 04:35:19 2011
+++ /atest/testdata/cli/dryrun/dryrun.txt       Sat Jun 11 14:51:08 2011
@@ -15,12 +15,34 @@
     ${contents}=  List Directory  .
     Simple UK

+Keywords with embedded arguments
+    Embedded arguments here
+    Embedded args rock here
+
 Keywords that would fail
     Fail  Not actually executed so won't fail.
     Fail In Uk
     No Operation

-Userkeyword return value
+Scalar variables are not checked in keyword arguments
+ [Documentation] Variables are too often set somehow dynamically that we cannot expect them to always exist.
+    Log  ${TESTNAME}
+    Log  ${this does not exist}
+
+List variables are not checked in keyword arguments
+    [Documentation]  See the doc of the previous test
+    @{list} =  Create List  1  2  3  4
+    Log  @{list}
+    Anarchy in the UK  @{list}
+    Anarchy in the UK  @{nonex}
+    Fail   @{list}  @{nonex}
+
+Variables are not checked in when arguments are embedded
+    [Documentation]  See the doc of the previous test
+    Embedded ${TESTNAME} here
+    Embedded ${nonex} here
+
+User keyword return value
     ${quux}=  Some Return Value  ${foo}  ${bar}

 Test Setup And Teardown
@@ -73,18 +95,11 @@
     UK with multiple failures
     Does not exist

-Arguments given as list variable
- [Documentation] FAIL Keyword 'BuiltIn.Should Be Equal' expected 2 to 4 arguments, got 1.
-    @{list} =  Create List  1  1
-    Should Be Equal  @{list}
-    Anarchy in the UK  @{list}
-    Anarchy in the UK  @{list}  1
-    @{empty list}  Create List
-    Convert to Number   1  @{empty list}  @{empty list}
-    Should Be Equal  @{foo
-

 *** Keywords ***
+Embedded ${args} here
+    No Operation
+
 Keyword with Teardown
     No Operation
     [Teardown]  Does not exist
=======================================
--- /src/robot/running/userkeyword.py   Fri May  6 06:28:25 2011
+++ /src/robot/running/userkeyword.py   Sat Jun 11 14:51:08 2011
@@ -234,10 +234,11 @@
         self.origname = template.name
         self._copy_attrs_from_template(template)

-
     def run(self, context, args):
-        for name, value in self.embedded_args:
- context.get_current_vars()[name] = context.get_current_vars().replace_scalar(value)
+        if not context.dry_run:
+            for name, value in self.embedded_args:
+                context.get_current_vars()[name] = \
+                    context.get_current_vars().replace_scalar(value)
         return UserKeywordHandler.run(self, context, args)

     def _copy_attrs_from_template(self, template):

==============================================================================
Revision: a1530c26bee6
Author:   Pekka Klärck
Date:     Sat Jun 11 15:59:22 2011
Log:      Keyword type to start/end_keyword listener methods

Update issue 859
Status: Started
Owner: pekka.klarck
Implementation and tests done. Attributes to start_keyword and end_keyword now contain 'type' that is either keyword, suite setup, suite teardown, test setup, or test teardown.

This is now implemented so that if a user keyword is used as a setup or teardown, only the top level keyword gets 'setup/teardown' type and others get type 'keyword'. Is that ok? At least the implementation this way is easier.

This also needs to be documented in the User Guide.
http://code.google.com/p/robotframework/source/detail?r=a1530c26bee6

Added:
 /atest/testdata/misc/setups_and_teardowns.txt
Modified:
 /atest/robot/output/listener_interface/listener_methods.txt
 /atest/testresources/listeners/JavaAttributeVerifyingListener.class
 /atest/testresources/listeners/JavaAttributeVerifyingListener.java
 /atest/testresources/listeners/attributeverifyinglistener.py
 /atest/testresources/listeners/listeners.py
 /src/robot/output/listeners.py

=======================================
--- /dev/null
+++ /atest/testdata/misc/setups_and_teardowns.txt       Sat Jun 11 15:59:22 2011
@@ -0,0 +1,11 @@
+***Settings***
+Documentation This suite was initially created for testing keyword types with
+...             listeners but can be used for other purposes too.
+Suite Setup     Log  Suite Setup
+Suite Teardown  Log  Suite Teardown
+Test Setup      Log  Test Setup
+Test Teardown   Log  Test Teardown
+
+***Test Cases***
+Test with setup and teardown
+    Log  Keyword
=======================================
--- /atest/robot/output/listener_interface/listener_methods.txt Tue May 17 05:07:30 2011 +++ /atest/robot/output/listener_interface/listener_methods.txt Sat Jun 11 15:59:22 2011
@@ -66,19 +66,23 @@
     ${status} =  Log File  ${TEMPDIR}/${ATTR_TYPE_FILE}
     Check Stderr Does Not Contain  attributeverifyinglistener
     Should Not Contain  ${status}  FAILED
-    Should Contain X Times  ${status}  PASSED  129
+    Should Contain X Times  ${status}  PASSED  149

 Correct Attributes To Java Listener Methods
     [Tags]  jybot
     ${status} =  Log File  ${JAVATEMPDIR}/${JAVA_ATTR_TYPE_FILE}
     Check Stderr Does Not Contain  JavaAttributeVerifyingListener
     Should Not Contain  ${status}  FAILED
-    Should Contain X Times  ${status}  PASSED  129
+    Should Contain X Times  ${status}  PASSED  149

 Suite And Test Counts
     Run Tests  --listener listeners.SuiteAndTestCounts  misc/suites/sub*
     Stderr Should Be Empty

+Keyword Type
+ Run Tests --listener listeners.KeywordType misc/setups_and_teardowns.txt
+    Stderr Should Be Empty
+
 Suite And Test Counts With Java
     [Tags]  jybot
     Run Tests  --listener JavaSuiteAndTestCountListener  misc/suites/sub*
=======================================
--- /atest/testresources/listeners/JavaAttributeVerifyingListener.java Thu Sep 16 13:17:56 2010 +++ /atest/testresources/listeners/JavaAttributeVerifyingListener.java Sat Jun 11 15:59:22 2011
@@ -6,7 +6,7 @@
 public class JavaAttributeVerifyingListener {
     public static final String ROBOT_LISTENER_API_VERSION = "2";
     private BufferedWriter outfile;
-    private Map expectedTypes;
+    private Map expectedTypes;

     public JavaAttributeVerifyingListener() throws IOException {
        createOutputFile();
@@ -31,7 +31,7 @@
                put("totaltests", Integer.class);
            }};
     }
-
+
     public void startSuite(String name, Map attrs) {
         verifyAttributes("START SUITE", attrs,
new String[] {"doc", "starttime", "longname", "metadata", "tests", "suites", "totaltests"});
@@ -54,12 +54,12 @@

     public void startKeyword(String name, Map attrs) {
         verifyAttributes("START KEYWORD", attrs,
-                        new String[] {"doc", "starttime", "args"});
+                        new String[] {"doc", "starttime", "args", "type"});
     }

     public void endKeyword(String name, Map attrs) {
         verifyAttributes("END KEYWORD", attrs,
- new String[] {"doc", "starttime", "args", "endtime", "elapsedtime", "status"}); + new String[] {"doc", "starttime", "args", "type", "endtime", "elapsedtime", "status"});
     }

     public void close() throws IOException {
=======================================
--- /atest/testresources/listeners/attributeverifyinglistener.py Tue Sep 7 13:43:37 2010 +++ /atest/testresources/listeners/attributeverifyinglistener.py Sat Jun 11 15:59:22 2011
@@ -27,10 +27,10 @@
_verify_attributes('END TEST', attrs, END_ATTRIBUTES + ['longname', 'tags', 'message'])

 def start_keyword(name, attrs):
-    _verify_attributes('START KEYWORD', attrs, START_ATTRIBUTES + ['args'])
+ _verify_attributes('START KEYWORD', attrs, START_ATTRIBUTES + ['args', 'type'])

 def end_keyword(name, attrs):
-    _verify_attributes('END KEYWORD', attrs, END_ATTRIBUTES + ['args'])
+ _verify_attributes('END KEYWORD', attrs, END_ATTRIBUTES + ['args', 'type'])

 def _verify_attributes(method_name, attrs, names):
     OUTFILE.write(method_name + '\n')
=======================================
--- /atest/testresources/listeners/listeners.py Tue May 17 05:07:30 2011
+++ /atest/testresources/listeners/listeners.py Sat Jun 11 15:59:22 2011
@@ -62,6 +62,17 @@
                                (name, self.exp_data[name], data))


+class KeywordType(object):
+    ROBOT_LISTENER_API_VERSION = '2'
+
+    def start_keyword(self, name, attrs):
+        if attrs['type'] != attrs['args'][0].lower():
+            raise RuntimeError("Wrong keyword type '%s', expected '%s'."
+                               % (attrs['type'], attrs['args'][0].lower()))
+
+    end_keyword = start_keyword
+
+
 class KeywordExecutingListener(object):
     ROBOT_LISTENER_API_VERSION = '2'

=======================================
--- /src/robot/output/listeners.py      Tue May 17 05:09:21 2011
+++ /src/robot/output/listeners.py      Sat Jun 11 15:59:22 2011
@@ -30,6 +30,7 @@
_end_attrs = _start_attrs + ['endtime', 'elapsedtime', 'status', 'message']

     def __init__(self, listeners):
+        self._running_test = False
         self._listeners = self._import_listeners(listeners)

     def __nonzero__(self):
@@ -71,6 +72,7 @@
                 li.call_method(li.end_suite, suite.name, attrs)

     def start_test(self, test):
+        self._running_test = True
         for li in self._listeners:
             if li.version == 1:
li.call_method(li.start_test, test.name, test.doc, test.tags)
@@ -79,6 +81,7 @@
                 li.call_method(li.start_test, test.name, attrs)

     def end_test(self, test):
+        self._running_test = False
         for li in self._listeners:
             if li.version == 1:
                 li.call_method(li.end_test, test.status, test.message)
@@ -92,14 +95,21 @@
                 li.call_method(li.start_keyword, kw.name, kw.args)
             else:
                 attrs = self._get_start_attrs(kw, 'args', '-longname')
+                attrs['type'] = self._get_keyword_type(kw)
                 li.call_method(li.start_keyword, kw.name, attrs)

+    def _get_keyword_type(self, kw):
+        if kw.type == 'kw':
+            return 'keyword'
+ return '%s %s' % (('test' if self._running_test else 'suite'), kw.type)
+
     def end_keyword(self, kw):
         for li in self._listeners:
             if li.version == 1:
                 li.call_method(li.end_keyword, kw.status)
             else:
attrs = self._get_end_attrs(kw, 'args', '-longname', '-message')
+                attrs['type'] = self._get_keyword_type(kw)
                 li.call_method(li.end_keyword, kw.name, attrs)

     def log_message(self, msg):

Reply via email to