Revision: ba9aef3a8d69
Branch:   default
Author:   Pekka Klärck
Date:     Mon Sep  9 11:30:15 2013 UTC
Log:      Support variables in library name given using WITH NAME syntax

Update issue 1488
Status: Done
Summary: Support variables in library name given using WITH NAME syntax
Fixed this support with `Import Library` keyword and added the support also to `Library` setting. Both with tests.
http://code.google.com/p/robotframework/source/detail?r=ba9aef3a8d69

Modified:
 /atest/robot/test_libraries/with_name.txt
 /atest/testdata/standard_libraries/builtin/import_library.txt
 /atest/testdata/test_libraries/with_name_2.txt
 /src/robot/running/importer.py

=======================================
--- /atest/robot/test_libraries/with_name.txt   Thu May 27 10:42:17 2010 UTC
+++ /atest/robot/test_libraries/with_name.txt   Mon Sep  9 11:30:15 2013 UTC
@@ -1,5 +1,5 @@
 *** Settings ***
-Suite Setup     My Setup
+Suite Setup     Run 'With Name' Tests
 Force Tags      regression
 Default Tags    pybot  jybot
 Resource        atest_resource.txt
@@ -41,15 +41,18 @@
     Should Be Equal  ${test.kws[1].name}  OS.Should Exist
Check Syslog Contains Imported library 'OperatingSystem' with name 'OS'

-With Arguments And Import Same Library Twice
- ${test} = Check Test Case With Arguments And Import Same Library Twice
+Arguments Containing Variables And Import Same Library Twice
+ ${test} = Check Test Case Arguments Containing Variables And Import Same Library Twice Should Be Equal ${test.kws[0].name} \${a1}, \${a2} = Param1.Parameters Should Be Equal ${test.kws[3].name} \${a1}, \${a2} = Param2.Parameters - Check Syslog Contains Imported library 'ParameterLibrary' with arguments [ arg1a | arg1b ] (version <unknown>, class type, testcase scope, + Check Syslog Contains Imported library 'ParameterLibrary' with arguments [ 1 | 2 ] (version <unknown>, class type, testcase scope, Check Syslog Contains Imported library 'ParameterLibrary' with name 'Param1' - Check Syslog Contains Imported library 'ParameterLibrary' with arguments [ arg2a | arg2b ] (version <unknown>, class type, testcase scope, + Check Syslog Contains Imported library 'ParameterLibrary' with arguments [ VAR | 42 ] (version <unknown>, class type, testcase scope, Check Syslog Contains Imported library 'ParameterLibrary' with name 'Param2'

+Alias Containing Variable
+    Check Test Case  Alias Containing Variable
+
 With Name Has No Effect If Not Second Last
     ${test} =  Check Test Case  With Name Has No Effect If Not Second Last
Should Be Equal ${test.kws[0].name} \${a1}, \${a2} = ParameterLibrary.Parameters
@@ -121,7 +124,7 @@
Check Syslog Contains Imported library 'ParameterLibrary' with arguments [ 1 | 2 ]

 *** Keywords ***
-My Setup
+Run 'With Name' Tests
Run Tests ${EMPTY} test_libraries/with_name_1.txt test_libraries/with_name_2.txt test_libraries/with_name_3.txt
     Should Be Equal  ${SUITE.name}  With Name 1 & With Name 2 & With Name 3

=======================================
--- /atest/testdata/standard_libraries/builtin/import_library.txt Mon May 6 14:20:46 2013 UTC +++ /atest/testdata/standard_libraries/builtin/import_library.txt Mon Sep 9 11:30:15 2013 UTC
@@ -20,8 +20,8 @@

 Import Library With Variables And WITH NAME
     ${name} =  Set Variable  ParameterLibrary
-    Import Library  ${name}  ${42}  ${name}  WITH NAME  Variables
-    ${first}  ${second} =  Variables.Parameters
+    Import Library  ${name}  ${42}  ${name}  WITH NAME  Variables-${42}
+    ${first}  ${second} =  Variables-42.Parameters
     Should Be Equal  ${first}  ${42}
     Should Be Equal  ${second}  ParameterLibrary

=======================================
--- /atest/testdata/test_libraries/with_name_2.txt Tue May 25 15:14:16 2010 UTC +++ /atest/testdata/test_libraries/with_name_2.txt Mon Sep 9 11:30:15 2013 UTC
@@ -1,8 +1,9 @@
 *** Settings ***
 Documentation   NO RIDE because it could change WITH NAME format.
 Library         OperatingSystem  WITH NAME  OS
-Library         ParameterLibrary  arg1a  arg1b  with name  Param1
-Library         ParameterLibrary  arg2a  arg2b  WITH NAME  Param2
+Library         ParameterLibrary  1  2  with name  Param1
+Library         ParameterLibrary  ${VAR}  ${42}  WITH NAME  Param2
+Library         ParameterLibrary  a  b  WITH NAME  ${VAR}
 Library         ParameterLibrary  whatever  with name
 Library         BuiltIn  With Name  B2
 Library         module_library  with name  MOD1
@@ -16,6 +17,9 @@
 Library         libraryscope.Suite  WITH NAME  S Scope
 Library         libraryscope.Test  WITH NAME  T Scope

+*** Variables ***
+${VAR}          VAR
+
 *** Test Cases ***
 No Arguments
[Documentation] FAIL No keyword with name 'OperatingSystem.Should Exist' found.
@@ -23,15 +27,23 @@
     Should Exist  ${CURDIR}
     OperatingSystem.Should Exist  ${CURDIR}

-With Arguments And Import Same Library Twice
+Arguments Containing Variables And Import Same Library Twice
     ${a1}  ${a2} =  Param1.parameters
-    BuiltIn.Should Be Equal  ${a1}  arg1a
-    BuiltIn.Should Be Equal  ${a1}  arg1a
+    BuiltIn.Should Be Equal  ${a1}  1
+    BuiltIn.Should Be Equal  ${a2}  2
     ${a1}  ${a2} =  par am 2 . par A meter S
-    BuiltIn.Should Be Equal  ${a1}  arg2a
-    BuiltIn.Should Be Equal  ${a2}  arg2b
+    BuiltIn.Should Be Equal  ${a1}  VAR
+    BuiltIn.Should Be Equal  ${a2}  ${42}
+
+Alias Containing Variable
+    ${a1}  ${a2} =  VAR.parameters
+    BuiltIn.Should Be Equal  ${a1}  a
+    BuiltIn.Should Be Equal  ${a2}  b
+    ${a1}  ${a2} =  Run Keyword  ${VAR}.parameters
+    BuiltIn.Should Be Equal  ${a1}  a
+    BuiltIn.Should Be Equal  ${a2}  b

-WIth Name Has No Effect If Not Second Last
+With Name Has No Effect If Not Second Last
     ${a1}  ${a2} =  ParameterLibrary.parameters
     BuiltIn.Should Be Equal  ${a1}  whatever
     BuiltIn.Should Be Equal  ${a2}  with name
@@ -76,7 +88,10 @@
     BuiltIn.Should Be Equal  ${a2}  second arg

Correct Error When Using Keyword From Same Library With Different Names Without Prefix 2 - [Documentation] FAIL Multiple keywords with name 'Parameters' found.\n Give the full name of the keyword you want to use.\n Found: 'MyParamLib.Parameters', 'Param1.Parameters', 'Param2.Parameters' and 'ParameterLibrary.Parameters'
+    [Documentation]  FAIL
+    ...  Multiple keywords with name 'Parameters' found.
+    ...  Give the full name of the keyword you want to use.
+ ... Found: 'MyParamLib.Parameters', 'Param1.Parameters', 'Param2.Parameters', 'ParameterLibrary.Parameters' and 'VAR.Parameters'
     Parameters

 Dynamic Library
=======================================
--- /src/robot/running/importer.py      Thu Jun  6 14:00:44 2013 UTC
+++ /src/robot/running/importer.py      Mon Sep  9 11:30:15 2013 UTC
@@ -32,11 +32,12 @@
     def reset(self):
         self.__init__()

-    def import_library(self, name, args=None, alias=None, variables=None):
+    def import_library(self, name, args, alias, variables):
         lib = TestLibrary(name, args, variables, create_handlers=False)
         positional, named = lib.positional_args, lib.named_args
         lib = self._import_library(name, positional, named, lib)
-        if alias and name != alias:
+        if alias:
+            alias = variables.replace_scalar(alias)
             lib = self._copy_library(lib, alias)
LOGGER.info("Imported library '%s' with name '%s'" % (name, alias))
         return lib

--

--- 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