waldenner / robotframework

Automatically exported from code.google.com/p/robotframework
Apache License 2.0
0 stars 0 forks source link

New BuiltIn keyword `Import Resource` #578

Closed GoogleCodeExporter closed 9 years ago

GoogleCodeExporter commented 9 years ago
In addition to import a library dynamicall with the "import library" keyword, 
it'd be nice, to do the same for resources.

Use-Case:
In the suite initialization script we set some variables, if they are not 
already present. [1] One of that variable points to the location of the 
resource files. Then, it's good practice to load libraries with via a resource 
file, to prevent initialization of the libaries with different parameters. When 
a Library is used in the __init__ and other resources and keywords, our 
__init__ file has to import the resource file after the variable that points to 
the resources has been set.

[1] 
http://groups.google.com/group/robotframework-users/browse_thread/thread/7326377
b3a02468a

Original issue reported on code.google.com by Andreas.EbbertKarroum@gmail.com on 24 Jun 2010 at 1:11

GoogleCodeExporter commented 9 years ago
We already have `Import Library` and `Import Variables` keywords so adding 
`Import Resource` is logical.

Andreas, do you have time and interest to look at implementing this yourself? 
The related code in robot/running/namespaces.py and robot/running/importer.py 
is not too good, but you can use the existing keywords as an example. All this 
code will likely be rewritten in RF 2.6 and adding this functionality after 
that is probably even easier than now.

Original comment by pekka.klarck on 28 Jun 2010 at 8:19

GoogleCodeExporter commented 9 years ago
Implemented this because I needed the keyword myself. Changes made:

@/robot/running/namespaces.py:

from robot.parsing.settings import Library, Variables, Resource

def import_resource(self, name, invalid_args=None, comment=None, 
variables=None):
        self._import_resource(Resource(None, name, invalid_args=invalid_args,  comment=comment), variables)

@/robot/libraries/BuiltIn.py:
    def import_resource(self, path, *args):
        NAMESPACES.current.import_resource(path.replace('/', os.sep), list(args))

I believe that was all the changes I made to make it work.

Original comment by grompy@gmail.com on 22 Sep 2010 at 1:24

GoogleCodeExporter commented 9 years ago
Interesting. Does this import both the keywords and the variables? We need to 
test this, and add also automated tests, but if everything works nicely we 
might still get this into 2.5.4.

If you grompy can create a patch against the current trunk testing this would 
be easier. The changes are so small that copying them to relevant places isn't 
too hard, though.

Original comment by pekka.klarck on 22 Sep 2010 at 9:14

GoogleCodeExporter commented 9 years ago

Original comment by jpran...@gmail.com on 23 Sep 2010 at 12:23

GoogleCodeExporter commented 9 years ago
Implementation in r4115 and atests r4116.

Original comment by jpran...@gmail.com on 23 Sep 2010 at 7:03

GoogleCodeExporter commented 9 years ago
Looks good otherwise but the doc should have note that this kw was added in 
2.5.4.

Original comment by pekka.klarck on 23 Sep 2010 at 7:13

GoogleCodeExporter commented 9 years ago
Updated r4117.

Original comment by jpran...@gmail.com on 23 Sep 2010 at 7:19