Decorator confusing Robot Framework's library parsing?

267 views
Skip to first unread message

Guy Kisel

unread,
Jan 18, 2013, 8:11:12 PM1/18/13
to robotframe...@googlegroups.com
Background: I noticed that Robot Framework was providing arguments to my Python library methods as Unicode strings. For my purposes (interacting with REST APIs, writing to a Linux or Windows shell), it's easier to work with ASCII strings. Instead of converting Unicode to ASCII manually in every method, I wrote a decorator to do it:

def _decode_unicode_args(function_to_decorate):
    """
    Decorator that converts unicode arguments to ASCII.
    """
    def wrapper(*args, **kwargs):
        for arg in args:
            if type(arg) == types.UnicodeType:
                arg = arg.encode('ascii', 'ignore')
        for _, arg in kwargs.items():
            if type(arg) == types.UnicodeType:
                arg = arg.encode('ascii', 'ignore')
        function_to_decorate(*args, **kwargs)
    return wrapper

Problem is, methods that I decorate using this are detected in RIDE and libdoc as having the argument *args instead of having their actual arguments. Are decorators just generally incompatible with Robot Framework? Is there a better way to do this?

Pekka Klärck

unread,
Jan 19, 2013, 5:54:52 PM1/19/13
to guy....@gmail.com, robotframe...@googlegroups.com
2013/1/19 Guy Kisel <guy....@gmail.com>:
>
> Problem is, methods that I decorate using this are detected in RIDE and
> libdoc as having the argument *args instead of having their actual
> arguments. Are decorators just generally incompatible with Robot Framework?

This problem occurs because Robot uses introspection to find what
arguments your methods implement and it only sees decorators.

> Is there a better way to do this?

You can use decorator module to the attach the original arguments to
your decorators. The documentation of the module also explains the
root cause of this problem pretty thoroughly:
http://micheles.googlecode.com/hg/decorator/documentation.html

Alternatively, if you have only few keywords, you could consider doing
the conversion as the first step in your methods.

Cheers,
.peke
--
Agile Tester/Developer/Consultant :: http://eliga.fi
Lead Developer of Robot Framework :: http://robotframework.org

Guy Kisel

unread,
Jan 21, 2013, 2:00:05 PM1/21/13
to robotframe...@googlegroups.com, guy....@gmail.com
Thank you, the decorator module works perfectly (and is easy to use!) I suspected the problem was something like that. I searched for information on decorators in the Robot Framework User Guide, but didn't find much. I doubt this is a common problem, but it might be worth documenting somewhere.

Pekka Klärck

unread,
Jan 24, 2013, 4:29:26 PM1/24/13
to guy....@gmail.com, robotframe...@googlegroups.com
2013/1/21 Guy Kisel <guy....@gmail.com>:
> Thank you, the decorator module works perfectly (and is easy to use!) I
> suspected the problem was something like that. I searched for information on
> decorators in the Robot Framework User Guide, but didn't find much. I doubt
> this is a common problem, but it might be worth documenting somewhere.

You are right, mentioning this in the User Guide under the test
library API section would be a good idea. Could you submit an issue
about that? Even better if you have an idea where to add the note and
what the note should contain.

Guy Kisel

unread,
Jan 25, 2013, 1:20:52 PM1/25/13
to robotframe...@googlegroups.com, guy....@gmail.com
Reply all
Reply to author
Forward
0 new messages