Author: janne.t.harkonen
Date: Tue Apr  7 05:43:45 2009
New Revision: 1713

Modified:
   trunk/src/robot/running/namespace.py
   trunk/src/robot/running/testlibraries.py

Log:
Refactored how test libraries are copied.

Modified: trunk/src/robot/running/namespace.py
==============================================================================
--- trunk/src/robot/running/namespace.py        (original)
+++ trunk/src/robot/running/namespace.py        Tue Apr  7 05:43:45 2009
@@ -14,6 +14,7 @@


 import os.path
+import copy

 from robot import utils
 from robot.errors import FrameworkError, DataError
@@ -113,7 +114,7 @@
             return
         lib = IMPORTER.import_library(code_name, args)
         if code_name != lib_name:
-            lib = lib.copy(lib_name)
+            lib = self._copy_library(lib, lib_name)
             LOGGER.info("Imported library '%s' with name '%s'"
                         % (code_name, lib_name))
         self._testlibs[lib_name] = lib
@@ -133,7 +134,19 @@
         else:
             lib_name = name
         return name, lib_name, args
-
+
+    def _copy_library(self, lib, newname):
+        libcopy = copy.copy(lib)
+        libcopy.name = newname
+        libcopy.init_scope_handling()
+        libcopy.handlers = utils.NormalizedDict(ignore=['_'])
+        for handler in lib.handlers.values():
+            handcopy = copy.copy(handler)
+            handcopy.library = libcopy
+            handcopy.longname = '%s.%s' % (libcopy.name, handcopy.name)
+            libcopy.handlers[handler.name] = handcopy
+        return libcopy
+
     def _import_deprecated_standard_libs(self, name):
         if name in ['BuiltIn', 'OperatingSystem']:
             self.import_library('Deprecated' + name)

Modified: trunk/src/robot/running/testlibraries.py
==============================================================================
--- trunk/src/robot/running/testlibraries.py    (original)
+++ trunk/src/robot/running/testlibraries.py    Tue Apr  7 05:43:45 2009
@@ -16,7 +16,6 @@
 import os
 import types
 import inspect
-import copy

 from robot import utils
 from robot.errors import DataError
@@ -76,25 +75,8 @@
             self.init =  self._create_init_handler(libcode)
             self._libinst = self.get_instance()
             self.handlers = self._create_handlers(self._libinst)
-            self._init_scope_handling()
+            self.init_scope_handling()

-    def copy(self, name):
-        lib = _BaseTestLibrary(None, self.version, name, self.args)
-        lib.orig_name = self.name
-        lib.doc = self.doc
-        lib.scope = self.scope
-        lib._libcode = self._libcode
-        lib._libinst = self._libinst
-        lib.init = self.init
-        lib._init_scope_handling()
-        lib.handlers = utils.NormalizedDict(ignore=['_'])
-        for handler_name, handler in self.handlers.items():
-            copied = copy.copy(handler)
-            copied.library = lib
-            copied.longname = '%s.%s' % (lib.name, copied.name)
-            lib.handlers[handler_name] = copied
-        return lib
-
     def start_suite(self):
         pass

@@ -129,7 +111,7 @@
             return True
         return False

-    def _init_scope_handling(self):
+    def init_scope_handling(self):
         if self.scope == 'GLOBAL':
             return
         self._libinst = None

Reply via email to