Revision: 3810
Author: pekka.klarck
Date: Tue Jul 13 07:00:06 2010
Log: 1) Better tests for importing Java libraries with arguments. This includes test for imports with variables which demonstrates the bug in issue 584. 2) Some enhancements for Python library import tests.
http://code.google.com/p/robotframework/source/detail?r=3810

Added:
 /trunk/atest/robot/test_libraries/resource_for_importing_libs_with_args.txt
 /trunk/atest/testdata/test_libraries/java_vars_for_imports.py
 /trunk/atest/testresources/testlibs/DefaultArgs.class
 /trunk/atest/testresources/testlibs/DefaultArgs.java
 /trunk/atest/testresources/testlibs/MandatoryArgs.class
 /trunk/atest/testresources/testlibs/MandatoryArgs.java
Deleted:
 /trunk/atest/testresources/testlibs/JavaVarArgsConstructor.class
 /trunk/atest/testresources/testlibs/JavaVarArgsConstructor.java
Modified:
 /trunk/atest/robot/test_libraries/java_library_imports_with_args.txt
 /trunk/atest/robot/test_libraries/library_imports_with_args.txt
 /trunk/atest/testdata/test_libraries/java_library_imports_with_args.txt
 /trunk/atest/testdata/test_libraries/library_imports_with_args.txt
 /trunk/atest/testresources/testlibs/libswithargs.py

=======================================
--- /dev/null
+++ /trunk/atest/robot/test_libraries/resource_for_importing_libs_with_args.txt Tue Jul 13 07:00:06 2010
@@ -0,0 +1,15 @@
+*** Settings ***
+Resource        atest_resource.txt
+
+
+***Keywords***
+
+Library import should have been successful
+    [Arguments]  ${lib}  @{params}
+    Check Test Case  ${TEST NAME}
+    ${par} =  Catenate  SEPARATOR=${SPACE}|${SPACE}  @{params}
+ Check Syslog Contains Imported library '${lib}' with arguments [ ${par} ]
+
+Library import should have failed
+    [Arguments]  ${lib}  ${err}
+    Check Syslog Contains  Test Library '${lib}' expected ${err}
=======================================
--- /dev/null
+++ /trunk/atest/testdata/test_libraries/java_vars_for_imports.py Tue Jul 13 07:00:06 2010
@@ -0,0 +1,6 @@
+import JavaObject as _JO
+from java.util import HashMap as _HM
+
+JAVA_OBJECT = _JO("The name of the JavaObject")
+LIST__LIST_WITH_OBJECTS = [_HM({'key': 'value'}), True]
+
=======================================
--- /dev/null
+++ /trunk/atest/testresources/testlibs/DefaultArgs.class Tue Jul 13 07:00:06 2010
@@ -0,0 +1,16 @@
+Êþº¾2"
+            
+
+
+
+
+argsLjava/lang/String;<init>(Ljava/lang/String;)VCodeLineNumberTable'(Ljava/lang/String;Ljava/lang/String;)V9(Ljava/lang/String;Ljava/lang/String;Ljava/lang/String;)VgetArgs()Ljava/lang/String;
+SourceFileDefaultArgs.java
+
+ java/lang/StringBuilder   & ! DefaultArgsjava/lang/Object()Vappend-(Ljava/lang/String;)Ljava/lang/StringBuilder;toString! 
+
+*
+*·*+µ±  ...@ *·*»Y·+¶¶,¶¶µ± 
+I)*·*»Y·+¶¶,¶¶-¶¶µ±

+(
+*´°
=======================================
--- /dev/null
+++ /trunk/atest/testresources/testlibs/DefaultArgs.java Tue Jul 13 07:00:06 2010
@@ -0,0 +1,19 @@
+public class DefaultArgs {
+    private String args;
+
+    public DefaultArgs(String mandatory) {
+       args = mandatory;
+    }
+
+    public DefaultArgs(String mandatory, String default1) {
+       args = mandatory + " & " + default1;
+    }
+
+ public DefaultArgs(String mandatory, String default1, String default2) {
+       args = mandatory + " & " + default1 + " & " + default2;
+    }
+
+    public String getArgs() {
+       return args;
+    }
+}
=======================================
--- /dev/null
+++ /trunk/atest/testresources/testlibs/MandatoryArgs.class Tue Jul 13 07:00:06 2010
@@ -0,0 +1,16 @@
+Êþº¾2#
+
+
+
+
+
+          
+
+argsLjava/lang/String;<init>'(Ljava/lang/Object;Ljava/lang/Object;)VCodeLineNumberTablegetArgs()Ljava/lang/String;
+SourceFileMandatoryArgs.java
+
+java/lang/StringBuilder  & !"
+MandatoryArgsjava/lang/Object()Vappend-(Ljava/lang/Object;)Ljava/lang/StringBuilder;-(Ljava/lang/String;)Ljava/lang/StringBuilder;toString!
+
+...@ *·*»Y·+¶¶,¶¶µ±
+*´°   
=======================================
--- /dev/null
+++ /trunk/atest/testresources/testlibs/MandatoryArgs.java Tue Jul 13 07:00:06 2010
@@ -0,0 +1,12 @@
+public class MandatoryArgs {
+    private String args;
+
+    public MandatoryArgs(Object mandatory1, Object mandatory2) {
+       args = mandatory1 + " & " +  mandatory2;
+    }
+
+    public String getArgs() {
+       return args;
+    }
+
+}
=======================================
--- /trunk/atest/testresources/testlibs/JavaVarArgsConstructor.class Mon Nov 24 06:11:44 2008
+++ /dev/null
@@ -1,9 +0,0 @@
-Êþº¾0
-
-<init>(Ljava/lang/String;)VCodeLineNumberTable'(Ljava/lang/String;Ljava/lang/String;)V9(Ljava/lang/String;Ljava/lang/String;Ljava/lang/String;)V
-SourceFileJavaVarArgsConstructor.java
JavaVarArgsConstructorjava/lang/Object()V!!*·±
-!*·±
-        !*·±
-  
-
-
=======================================
--- /trunk/atest/testresources/testlibs/JavaVarArgsConstructor.java Mon Nov 24 06:11:44 2008
+++ /dev/null
@@ -1,12 +0,0 @@
-public class JavaVarArgsConstructor {
-
-       public JavaVarArgsConstructor(String mandatory) {
-       }
-
-       public JavaVarArgsConstructor(String mandatory, String optional) {
-       }
-
- public JavaVarArgsConstructor(String mandatory, String optional, String optional2) {
-       }
-
-}
=======================================
--- /trunk/atest/robot/test_libraries/java_library_imports_with_args.txt Tue Jul 13 01:58:23 2010 +++ /trunk/atest/robot/test_libraries/java_library_imports_with_args.txt Tue Jul 13 07:00:06 2010
@@ -1,19 +1,48 @@
 *** Settings ***
Documentation Tests for checking that library initialization arguments are handled correctly. Taking libraries without arguments is not tested here, because almost every other suite does that. -Suite Setup Run Tests ${EMPTY} test_libraries/library_imports_with_args.txt +Suite Setup Run Tests ${EMPTY} test_libraries/java_library_imports_with_args.txt
 Force Tags      regression  jybot
-Resource        atest_resource.txt
+Resource        resource_for_importing_libs_with_args.txt
+Test Template   Library import should have been successful
+

 *** Test Cases ***
-Importing Java Library With Arguments
- Check Syslog Contains Imported library 'JavaVarArgsConstructor' with arguments [ valid argument | another arg ]
-
-Importing Java Library With Default Arguments
- Check Syslog Contains Imported library 'JavaVarArgsConstructor' with arguments [ mandatory ]
-
-Importing Java Library With Too Many Arguments
- Check Syslog Contains Test Library 'ExampleJavaLibrary' expected 0 arguments, got 1.
-
-Importing Java Library With Too Few Arguments
- Check Syslog Contains Test Library 'JavaVarArgsConstructor' expected 1 to 3 arguments, got 0.
-
+Mandatory arguments
+    MandatoryArgs  first arg  another arg
+
+Default values
+    DefaultArgs  m1
+    DefaultArgs  m2  d1
+    DefaultArgs  m3  1  2
+
+Variables containing objects
+    MandatoryArgs  42  The name of the JavaObject
+    MandatoryArgs  {key=value}  True
+
+Too Few Arguments
+    [Template]  Library import should have failed
+    MandatoryArgs    2 arguments, got 1.
+    DefaultArgs      1 to 3 arguments, got 0.
+    Varargs          at least 1 argument, got 0.
+
+Too Many Arguments
+    [Template]  Library import should have failed
+    MandatoryArgs    2 arguments, got 4.
+    DefaultArgs      1 to 3 arguments, got 5.
+
+Non-existing variables
+    [Template]
+    Check syslog contains  Non-existing variable '\${NONEX}'.
+
+
+***Keywords***
+
+Library import should have been successful
+    [Arguments]  ${lib}  @{params}
+    Check Test Case  ${TEST NAME}
+    ${par} =  Catenate  SEPARATOR=${SPACE}|${SPACE}  @{params}
+ Check Syslog Contains Imported library '${lib}' with arguments [ ${par} ]
+
+Library import should have failed
+    [Arguments]  ${lib}  ${err}
+    Check Syslog Contains  Test Library '${lib}' expected ${err}
=======================================
--- /trunk/atest/robot/test_libraries/library_imports_with_args.txt Tue Jul 13 04:29:39 2010 +++ /trunk/atest/robot/test_libraries/library_imports_with_args.txt Tue Jul 13 07:00:06 2010
@@ -2,13 +2,14 @@
Documentation Tests for checking that library initialization arguments are handled correctly. Taking libraries without arguments is not tested here, because almost every other suite does that. Suite Setup Run Tests ${EMPTY} test_libraries/library_imports_with_args.txt
 Force Tags      regression  pybot  jybot
-Resource        atest_resource.txt
+Resource        resource_for_importing_libs_with_args.txt
 Test Template   Library import should have been successful


 *** Test Cases ***
+
 Mandatory arguments
-    libswithargs.Normal  valid argument  another arg
+    libswithargs.Mandatory  first arg  another arg

 Default values
     libswithargs.Defaults  m1
@@ -28,27 +29,19 @@

 Variables containing objects
     libswithargs.Mixed  [1, 2, 3, 4, 'foo', 'bar']  {'a': 1}  None  42
+    libswithargs.Defaults  None  1.0  True

 Too Few Arguments
     [Template]  Library import should have failed
-    libswithargs.Normal    2 arguments, got 1.
-    libswithargs.Defaults  1 to 3 arguments, got 0.
-    libswithargs.Varargs   at least 1 argument, got 0.
+    libswithargs.Mandatory  2 arguments, got 1.
+    libswithargs.Defaults   1 to 3 arguments, got 0.
+    libswithargs.Varargs    at least 1 argument, got 0.

 Too Many Arguments
     [Template]  Library import should have failed
-    libswithargs.Normal    2 arguments, got 4.
-    libswithargs.Defaults  1 to 3 arguments, got 5.
-
-
-***Keywords***
-
-Library import should have been successful
-    [Arguments]  ${lib}  @{params}
-    Check Test Case  ${TEST NAME}
-    ${par} =  Catenate  SEPARATOR=${SPACE}|${SPACE}  @{params}
- Check Syslog Contains Imported library '${lib}' with arguments [ ${par} ]
-
-Library import should have failed
-    [Arguments]  ${lib}  ${err}
-    Check Syslog Contains  Test Library '${lib}' expected ${err}
+    libswithargs.Mandatory  2 arguments, got 4.
+    libswithargs.Defaults   1 to 3 arguments, got 5.
+
+Non-existing variables
+    [Template]
+    Check syslog contains  Non-existing variable '\${NONEX}'.
=======================================
--- /trunk/atest/testdata/test_libraries/java_library_imports_with_args.txt Tue Jul 13 04:29:39 2010 +++ /trunk/atest/testdata/test_libraries/java_library_imports_with_args.txt Tue Jul 13 07:00:06 2010
@@ -1,10 +1,47 @@
 *** Settings ***
-Library         JavaVarArgsConstructor  WITH NAME  JavaVarArgs1
-Library         JavaVarArgsConstructor  mandatory  WITH NAME  JavaVarArgs2
-Library         JavaVarArgsConstructor  valid argument  another arg
+Library    MandatoryArgs  first arg    another arg
+
+Library    DefaultArgs    m1           WITH NAME  D1
+Library    DefaultArgs    m2  d1       WITH NAME  D2
+Library    DefaultArgs    m3  1  2     WITH NAME  D3
+
+Library    Varargs        m1           WITH NAME  V1
+Library    Varargs        m2  v1       WITH NAME  V2
+Library    Varargs        m3  1  2  3  WITH NAME  V3
+
+Variables  java_vars_for_imports.py
+Library    MandatoryArgs  ${42}  ${JAVA OBJECT}  WITH NAME  O1
+Library    MandatoryArgs  @{LIST WITH OBJECTS}   WITH NAME  O2
+
+Library    MandatoryArgs  too few
+Library    DefaultArgs
+Library    Varargs
+
+Library    MandatoryArgs  too  many  args  here
+Library    DefaultArgs    too  many  args  here  too
+
+Library    MandatoryArgs  ${NONEX}  hello


 *** Test Cases ***
-Test
-    Comment  Tests only failing library imports.
-
+
+Mandatory arguments
+    Verify arguments  MandatoryArgs  first arg  another arg
+
+Default values
+    Verify arguments  D1  m1
+    Verify arguments  D2  m2  d1
+    Verify arguments  D3  m3  1      2
+
+Variables containing objects
+    Verify arguments  O1  42  The name of the JavaObject
+    Verify arguments  O2  {key=value}  true
+
+
+***Keywords***
+
+Verify arguments
+    [Arguments]  ${lib}  @{expected args}
+    ${expected} =  Catenate  SEPARATOR=${SPACE}&${SPACE}  @{expected args}
+    ${actual} =  Run Keyword  ${lib}.Get Args
+    Should be equal  ${actual}  ${expected}
=======================================
--- /trunk/atest/testdata/test_libraries/library_imports_with_args.txt Tue Jul 13 04:29:39 2010 +++ /trunk/atest/testdata/test_libraries/library_imports_with_args.txt Tue Jul 13 07:00:06 2010
@@ -1,38 +1,43 @@
 *** Settings ***
-Library    libswithargs.Normal    valid argument  another arg
-
-Library    libswithargs.Defaults  m1              WITH NAME  D1
-Library    libswithargs.Defaults  m2  d1          WITH NAME  D2
-Library    libswithargs.Defaults  m3  ${1}  ${2}  WITH NAME  D3
-
-Library    libswithargs.Varargs   m1              WITH NAME  V1
-Library    libswithargs.Varargs   m2  v1          WITH NAME  V2
-Library    libswithargs.Varargs   m3  ${1}  ${2}  WITH NAME  V3
-
-Library    libswithargs.Mixed     m1              WITH NAME  M1
-Library    libswithargs.Mixed     m2  d1          WITH NAME  M2
-Library    libswithargs.Mixed     m3  d2  v       WITH NAME  M3
-Library    libswithargs.Mixed     m4  d3  v1  v2  WITH NAME  M4
+Library    libswithargs.Mandatory  first arg       another arg
+
+Library    libswithargs.Defaults   m1              WITH NAME  D1
+Library    libswithargs.Defaults   m2  d1          WITH NAME  D2
+Library    libswithargs.Defaults   m3  ${1}  ${2}  WITH NAME  D3
+
+Library    libswithargs.Varargs    m1              WITH NAME  V1
+Library    libswithargs.Varargs    m2  v1          WITH NAME  V2
+Library    libswithargs.Varargs    m3  ${1}  ${2}  WITH NAME  V3
+
+Library    libswithargs.Mixed      m1              WITH NAME  M1
+Library    libswithargs.Mixed      m2  d1          WITH NAME  M2
+Library    libswithargs.Mixed      m3  d2  v       WITH NAME  M3
+Library    libswithargs.Mixed      m4  d3  v1  v2  WITH NAME  M4

 Variables  ../../testresources/res_and_var_files/different_variables.py
-Library    libswithargs.Mixed     ${LIST1}  ${DICTIONARY1}  ${None}  ${42}
-
-Library    libswithargs.Normal    too few
-Library    libswithargs.Defaults
+Library    libswithargs.Mixed      ${LIST1}  ${DICTIONARY1}  ${None}  ${42}
+Library    libswithargs.Defaults   @{LIST WITH OBJECTS}
+
+Library    libswithargs.Mandatory  too few
+Library    libswithargs.Defaults
 Library    libswithargs.Varargs

-Library    libswithargs.Normal    too  many  args  here
-Library    libswithargs.Defaults  too  many  args  here  too
+Library    libswithargs.Mandatory  too  many  args  here
+Library    libswithargs.Defaults   too  many  args  here  too
+
+Library    libswithargs.Mandatory  ${NONEX}

 Library    Collections
+
+
+***Variables***
+...@{list WITH OBJECTS}  ${None}  ${1.0}  ${True}


 *** Test Cases ***

 Mandatory arguments
-    ${mandatory}  ${varargs} =  libswithargs.Normal.Get Args
-    Should Be Equal  ${mandatory}  valid argument
-    Should Be Equal  ${varargs}  another arg
+    Verify arguments  libswithargs.Mandatory  first arg  another arg

 Default values
     Verify arguments  D1  m1  value  ${None}
@@ -52,9 +57,11 @@

 Variables containing objects
     Verify arguments  libswithargs.Mixed  ${LIST1}  ${DICTIONARY1}  None 42
+    Verify arguments  libswithargs.Defaults  ${None}  ${1.0}  ${True}


 ***Keywords***
+
 Verify arguments
     [Arguments]  ${lib}  @{expected args}
     ${actual args} =  Run Keyword  ${lib}.Get Args
=======================================
--- /trunk/atest/testresources/testlibs/libswithargs.py Tue Jul 13 04:29:39 2010 +++ /trunk/atest/testresources/testlibs/libswithargs.py Tue Jul 13 07:00:06 2010
@@ -1,4 +1,4 @@
-class Normal:
+class Mandatory:

     def __init__(self, mandatory1, mandatory2):
         self.mandatory1 = mandatory1
@@ -19,10 +19,10 @@
         return self.mandatory, self.default1, self.default2


-class Varargs(Normal):
+class Varargs(Mandatory):

     def __init__(self, mandatory, *varargs):
-        Normal.__init__(self, mandatory, ' '.join(str(a) for a in varargs))
+ Mandatory.__init__(self, mandatory, ' '.join(str(a) for a in varargs))


 class Mixed(Defaults):

Reply via email to