Author: jprantan
Date: Wed Mar 25 07:30:08 2009
New Revision: 1543

Modified:
   trunk/src/robot/libraries/BuiltIn.py
   trunk/src/robot/running/namespace.py

Log:
Implementation fixes for issue 203.

Modified: trunk/src/robot/libraries/BuiltIn.py
==============================================================================
--- trunk/src/robot/libraries/BuiltIn.py        (original)
+++ trunk/src/robot/libraries/BuiltIn.py        Wed Mar 25 07:30:08 2009
@@ -1113,37 +1113,35 @@
         NAMESPACES.current.import_variables(path.replace('/', os.sep),
                                             args, overwrite=True)

-    def set_library_order(self, *libraries):
-        """Sets order in which keywords are looked from libraries.
+    def set_library_search_order(self, *libraries):
+ """Sets order in which keywords are looked from libraries and returns the old order.

- By setting order in which keywords are serached it is possible to use - libraries providing keywords with same name without using long format
-        LibraryName.Keyword Name notation. This keyword is usefull in case
- there is need to use multiple applications through the same library. By - changing library which is used, it is possible to use same resources
-        instead dublicating the keywords for all the applications.
-
-        Examples:
-        | Import Library | MyLibrary | WITH NAME | application1 |
-        | Import Library | MyLibrary | WITH NAME | application2 |
-        | Set Default Library | application1 |
-        | Comment | Next step opens application1 using User Keyword |
- | Comment | Open Application which contains multiple keywords from MyLibrary |
-        | Open Application |
-        | Set Default Library | application2 |
-        | Comment | Now the same keyword is used for opening application2 |
-        | Open Application |
+ This keyword can be used to set the library search order. It is used
+        when multiple keywords are found with the same name. When multiple
+        keywords are found, libraries are gone through in the search order.
+ The first library containing the keyword is selected and the keyword
+        from that library is used. If keyword is not found, test execution
+        fails. When this keyword is used, there is no need to use the long
+ format LibraryName.Keyword Name notation. Library search order is valid
+        in the suite this keyword was used in.
+
+        Instead of having
+
+        | MyLibrary.Keyword | arg |
+        | MyLibrary.Another Keyword |
+        | MyLibrary.Keyword | xxx |
+
+        you can have

- Note: Set Library Order keyword cannot be used inside parallel keywords.
+        | Set Library Order | MyLibrary |
+        | Keyword | arg |
+        | Another Keyword |
+        | Keyword | xxx |
         """
-        library_order = NAMESPACES.current.library_order
-        NAMESPACES.current.library_order = libraries
-        return library_order
+        library_search_order = NAMESPACES.current.library_search_order
+        NAMESPACES.current.library_search_order = libraries
+        return library_search_order

-    def _get_var(self, name):
-        if NAMESPACES.current.variables.has_key(name):
-            return NAMESPACES.current.variables[lib]
-        return name

     def get_time(self, format='timestamp'):
         """Returns the current time in the requested format.

Modified: trunk/src/robot/running/namespace.py
==============================================================================
--- trunk/src/robot/running/namespace.py        (original)
+++ trunk/src/robot/running/namespace.py        Wed Mar 25 07:30:08 2009
@@ -42,8 +42,8 @@
         self.variables = _VariableScopes(suite, parent)
         self.suite = suite
         self.test = None
-        self.library_order = []
         self.uk_handlers = []
+        self.library_search_order = []
         self._testlibs = {}
         self._userlibs = []
         self._imported_resource_files = []
@@ -63,9 +63,9 @@
         ns.suite = self.suite
         ns.test = self.test
         ns.uk_handlers = self.uk_handlers[:]
+        ns.library_search_order = self.library_search_order[:]
         ns._testlibs = self._testlibs
         ns._userlibs = self._userlibs
-        ns.library_order = self.library_order[:]
         return ns

     def _handle_imports(self, import_settings):
@@ -203,7 +203,8 @@
         # 3) Try to find unique keyword from base keywords
         found = [ lib.get_handler(name)
for lib in self._testlibs.values() if lib.has_handler(name) ]
-        found = self._get_handler_based_on_default_library_order(found)
+        if len(found) > 1:
+            found = self._get_handler_based_on_library_search_order(found)
         if len(found) == 2:
             found = self._filter_stdlib_handler(found[0], found[1])
         if len(found) > 1:
@@ -212,12 +213,12 @@
             return found[0]
         return None

-    def _get_handler_based_on_default_library_order(self, handlers):
-        libraries = [handler.library.name for handler in handlers ]
-        for name in self.library_order:
-            if name in libraries:
- return [handler for handler in handlers if handler.library.name == name]
-        return handlers
+    def _get_handler_based_on_library_search_order(self, handlers):
+        for libname in self.library_search_order:
+            for handler in handlers:
+                if handler.library.name == libname:
+                    return [handler]
+        return handlers

     def _filter_stdlib_handler(self, hand1, hand2):
         if hand1.library.orig_name in STDLIB_NAMES:

Reply via email to