I am writing a new RF library which are expected to take string arguments because the (pre-existing) Python library that I use is expecting strings, not unicode. Ofcourse I can convert each unicode to string before calling my existing function which supports only strings.
import ConfigParser
class RFConfigParser:
def get (self,section, option):
print type (section) #prints unicode
section = str (section) #works but I dont want to do this
return self._config.get (section, option) #this pre-existing function expect a string input
The problem is I have lots of similar functions and in each of these functions I will have to call this unicode to string conversion circus.
Is there a straight forward way of doing this, so that the RF function will directly accept in string format
Another question is the default unicode support a Robot Framework feature or a RIDE feature ? (I am using RIDE, is that why I am getting this problem)
You can cast those Unicode strings to normal strings using Evaluate keyword before you pass them to your library.
Something like this:
lib.py:
def foo(foo):
print type(foo)
test.txt
*** Settings ***
Library lib.py
*** Test Cases ***
demo
${bar} Evaluate str('bar')
foo ${bar}
What the best solution is depends on the exact situation. Maybe one solution is to write a keyword that does that casting for you and then calls the library function. Maybe the best option still is to just modify your library to accept Unicode strings. It depends.