Revision: 4115
Author: jprantan
Date: Thu Sep 23 11:58:50 2010
Log: Added import resource keyword. Issue 578.
http://code.google.com/p/robotframework/source/detail?r=4115

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

=======================================
--- /trunk/src/robot/libraries/BuiltIn.py       Wed Sep 22 15:56:29 2010
+++ /trunk/src/robot/libraries/BuiltIn.py       Thu Sep 23 11:58:50 2010
@@ -1277,6 +1277,22 @@
         NAMESPACES.current.import_variables(path.replace('/', os.sep),
                                             args, overwrite=True)

+    def import_resource(self, path):
+        """Imports a resource file with the given path.
+
+ Resources imported with this keyword are set into the test suite scope + similarly when importing them in the Setting table using the Resource
+        setting.
+
+ The given path must be absolute. Forward slashes can be used as path
+        separator regardless the operating system.
+
+        Examples:
+        | Import Resource | ${CURDIR}/resource.txt |
+        | Import Resource | ${CURDIR}/../resources/resource.html |
+        """
+        NAMESPACES.current.import_resource(path.replace('/', os.sep))
+
     def set_library_search_order(self, *libraries):
"""Sets the resolution order to use when a name matches multiple keywords.

=======================================
--- /trunk/src/robot/running/namespace.py       Tue Aug 31 04:06:38 2010
+++ /trunk/src/robot/running/namespace.py       Thu Sep 23 11:58:50 2010
@@ -21,7 +21,7 @@
 from robot.variables import GLOBAL_VARIABLES
 from robot.common import UserErrorHandler
 from robot.output import LOGGER
-from robot.parsing.settings import Library, Variables
+from robot.parsing.settings import Library, Variables, Resource
 import robot

 from userkeyword import UserLibrary
@@ -79,7 +79,10 @@
         except KeyError:
raise FrameworkError("Invalid import setting: %s" % import_setting)

-    def _import_resource(self, import_setting, variables):
+    def import_resource(self, name):
+            self._import_resource(Resource(None, name))
+
+    def _import_resource(self, import_setting, variables=None):
         path = self._resolve_name(import_setting, variables)
         if path not in self._imported_resource_files:
             self._imported_resource_files.append(path)

Reply via email to