Revision: ae8798910555
Branch:   default
Author:   Robot Framework Developers (robotframew...@gmail.com)
Date:     Tue Oct  9 06:48:37 2012
Log: refactored how library scope and version are got from imported library object
http://code.google.com/p/robotframework/source/detail?r=ae8798910555

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

=======================================
--- /src/robot/running/testlibraries.py Fri Oct  5 05:56:31 2012
+++ /src/robot/running/testlibraries.py Tue Oct  9 06:48:37 2012
@@ -138,11 +138,19 @@
         pass

     def _get_version(self, code):
-        for version_attr in 'ROBOT_LIBRARY_VERSION', '__version__':
-            if hasattr(code, version_attr):
-                return utils.unic(getattr(code, version_attr))
+ return self._get_string_attr(code, 'ROBOT_LIBRARY_VERSION', '__version__')
+
+    def _get_string_attr(self, object, *attrs):
+        for attr in attrs:
+            if hasattr(object, attr):
+                return utils.unic(getattr(object, attr))
         return ''

+    def _get_scope(self, libcode):
+        scope = self._get_string_attr(libcode, 'ROBOT_LIBRARY_SCOPE')
+        scope = utils.normalize(scope, ignore='_').upper()
+        return scope if scope in ['GLOBAL','TESTSUITE'] else 'TESTCASE'
+
     def _create_init_handler(self, libcode):
         return InitHandler(self, self._resolve_init_method(libcode))

@@ -174,14 +182,6 @@
     def _restoring_end(self):
         self._libinst = self._instance_cache.pop()

-    def _get_scope(self, libcode):
-        try:
-            scope = libcode.ROBOT_LIBRARY_SCOPE
-            scope = utils.normalize(scope, ignore=['_']).upper()
-        except (AttributeError, TypeError):
-            scope = 'TESTCASE'
-        return scope if scope in ['GLOBAL','TESTSUITE'] else 'TESTCASE'
-
     def get_instance(self):
         if self._libinst is None:
             self._libinst = self._get_instance()

Reply via email to