Revision: 3808
Author: pekka.klarck
Date: Tue Jul 13 04:29:39 2010
Log: 1) Improved tests for importing Python libs with arguments, 2)
Separated test data for importing Java libs with arguments into a separate
suite (and will continue improving Java tests to fix issue 584)
http://code.google.com/p/robotframework/source/detail?r=3808
Added:
/trunk/atest/testdata/test_libraries/java_library_imports_with_args.txt
/trunk/atest/testresources/testlibs/libswithargs.py
Modified:
/trunk/atest/robot/test_libraries/library_imports_with_args.txt
/trunk/atest/testdata/test_libraries/library_imports_with_args.txt
/trunk/atest/testresources/testlibs/PythonVarArgsConstructor.py
=======================================
--- /dev/null
+++ /trunk/atest/testdata/test_libraries/java_library_imports_with_args.txt
Tue Jul 13 04:29:39 2010
@@ -0,0 +1,10 @@
+*** Settings ***
+Library JavaVarArgsConstructor WITH NAME JavaVarArgs1
+Library JavaVarArgsConstructor mandatory WITH NAME JavaVarArgs2
+Library JavaVarArgsConstructor valid argument another arg
+
+
+*** Test Cases ***
+Test
+ Comment Tests only failing library imports.
+
=======================================
--- /dev/null
+++ /trunk/atest/testresources/testlibs/libswithargs.py Tue Jul 13 04:29:39
2010
@@ -0,0 +1,32 @@
+class Normal:
+
+ def __init__(self, mandatory1, mandatory2):
+ self.mandatory1 = mandatory1
+ self.mandatory2 = mandatory2
+
+ def get_args(self):
+ return self.mandatory1, self.mandatory2
+
+
+class Defaults(object):
+
+ def __init__(self, mandatory, default1='value', default2=None):
+ self.mandatory = mandatory
+ self.default1 = default1
+ self.default2 = default2
+
+ def get_args(self):
+ return self.mandatory, self.default1, self.default2
+
+
+class Varargs(Normal):
+
+ def __init__(self, mandatory, *varargs):
+ Normal.__init__(self, mandatory, ' '.join(str(a) for a in varargs))
+
+
+class Mixed(Defaults):
+
+ def __init__(self, mandatory, default=42, *extra):
+ Defaults.__init__(self, mandatory, default,
+ ' '.join(str(a) for a in extra))
=======================================
--- /trunk/atest/robot/test_libraries/library_imports_with_args.txt Tue Jul
13 01:58:23 2010
+++ /trunk/atest/robot/test_libraries/library_imports_with_args.txt Tue Jul
13 04:29:39 2010
@@ -3,20 +3,52 @@
Suite Setup Run Tests ${EMPTY}
test_libraries/library_imports_with_args.txt
Force Tags regression pybot jybot
Resource atest_resource.txt
+Test Template Library import should have been successful
+
*** Test Cases ***
-Importing Python Library With Arguments
- Check Syslog Contains Imported library 'PythonVarArgsConstructor'
with arguments [ valid argument | another arg ]
-
-Importing Python Library With Default Arguments
- Check Syslog Contains Imported library 'PythonVarArgsConstructor'
with arguments [ mandatory ]
-
-Importing Python Library With Too Many Arguments
- Check Syslog Contains Test Library 'ExampleLibrary' expected 0
arguments, got 1.
-
-Importing Python Library With Too Few Arguments
- Check Syslog Contains Test Library 'PythonVarArgsConstructor'
expected at least 1 argument, got 0.
-
-Importing Python Library With List And Dictinary Arguments
- Check Syslog Contains Imported library 'ParameterLibrary' with
arguments [ [1, 2, 3, 4, 'foo', 'bar'] | {'a': 1} ]
-
+Mandatory arguments
+ libswithargs.Normal valid argument another arg
+
+Default values
+ libswithargs.Defaults m1
+ libswithargs.Defaults m2 d1
+ libswithargs.Defaults m3 1 2
+
+Varargs
+ libswithargs.Varargs m1
+ libswithargs.Varargs m2 v1
+ libswithargs.Varargs m3 1 2
+
+Mixed
+ libswithargs.Mixed m1
+ libswithargs.Mixed m2 d1
+ libswithargs.Mixed m3 d2 v
+ libswithargs.Mixed m4 d3 v1 v2
+
+Variables containing objects
+ libswithargs.Mixed [1, 2, 3, 4, 'foo', 'bar'] {'a': 1} None 42
+
+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.
+
+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}
=======================================
--- /trunk/atest/testdata/test_libraries/library_imports_with_args.txt Tue
Jul 13 01:58:23 2010
+++ /trunk/atest/testdata/test_libraries/library_imports_with_args.txt Tue
Jul 13 04:29:39 2010
@@ -1,16 +1,61 @@
*** Settings ***
-Library ExampleLibrary invalid
-Library ExampleJavaLibrary invalid
-Library PythonVarArgsConstructor WITH NAME VarArgs1
-Library PythonVarArgsConstructor mandatory WITH NAME VarArgs2
-Library PythonVarArgsConstructor valid argument another arg
-Library JavaVarArgsConstructor WITH NAME JavaVarArgs1
-Library JavaVarArgsConstructor mandatory WITH NAME JavaVarArgs2
-Library JavaVarArgsConstructor valid argument another arg
-Variables ../../testresources/res_and_var_files/different_variables.py
-Library ParameterLibrary ${list1} ${dictionary1}
+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
+
+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.Varargs
+
+Library libswithargs.Normal too many args here
+Library libswithargs.Defaults too many args here too
+
+Library Collections
+
*** Test Cases ***
-Test
- Comment Tests only failing library imports.
-
+
+Mandatory arguments
+ ${mandatory} ${varargs} = libswithargs.Normal.Get Args
+ Should Be Equal ${mandatory} valid argument
+ Should Be Equal ${varargs} another arg
+
+Default values
+ Verify arguments D1 m1 value ${None}
+ Verify arguments D2 m2 d1 ${None}
+ Verify arguments D3 m3 ${1} ${2}
+
+Varargs
+ Verify arguments V1 m1 ${EMPTY}
+ Verify arguments V2 m2 v1
+ Verify arguments V3 m3 1 2
+
+Mixed
+ Verify arguments M1 m1 ${42} ${EMPTY}
+ Verify arguments M2 m2 d1 ${EMPTY}
+ Verify arguments M3 m3 d2 v
+ Verify arguments M4 m4 d3 v1 v2
+
+Variables containing objects
+ Verify arguments libswithargs.Mixed ${LIST1} ${DICTIONARY1} None 42
+
+
+***Keywords***
+Verify arguments
+ [Arguments] ${lib} @{expected args}
+ ${actual args} = Run Keyword ${lib}.Get Args
+ Lists should be equal ${actual args} ${expected args}
=======================================
--- /trunk/atest/testresources/testlibs/PythonVarArgsConstructor.py Mon Nov
24 06:11:44 2008
+++ /trunk/atest/testresources/testlibs/PythonVarArgsConstructor.py Tue Jul
13 04:29:39 2010
@@ -1,4 +1,9 @@
class PythonVarArgsConstructor:
def __init__(self, mandatory, *varargs):
- pass
+ self.mandatory = mandatory
+ self.varargs = varargs
+
+ def get_args(self):
+ return self.mandatory, ' '.join(self.varargs)
+