Generating random UTF-8 strings

1,198 views
Skip to first unread message

Harri Paavola

unread,
Mar 28, 2012, 3:03:42 AM3/28/12
to robotframe...@googlegroups.com
Hi,

How can I get random UTF-8 strings from Python files to Robot Framework? Let's say I have we have Python script like this
import os
def generate_random_utf8_string(length=8):
    random_string = os.urandom(length)
    return random_string

And test suite like this
*** Settings ***
Library           String
Library           random_utf8_string

*** Test Cases ***
Foo
    ${string}    generate_random_utf8_string
    Log    ${string}
    Log    P=×& QÏ ᄆᄐ%ÎÅüツrネ>æミ T̆[PÙWqᆲOáGタᄆ> ヌʰヒþǗsàòÜ タンCハg1 ニニラò iAÉ( mnßvÕȆŁ K"bᄁÿᅠVᄌヨ:ABJᄐݤヤ

Only the latter Log will actually log UTF-8 string, the first one will log something like 9\xe7g\x7f\xae\x06\xeb\xe8g (always \x[something] repeated)

Harri Paavola

unread,
Mar 30, 2012, 6:33:30 AM3/30/12
to robotframe...@googlegroups.com
To answer my own question, the Python part should be like this:

# -*- coding: UTF-8

import os
def generate_random_utf8_string(length=8):
    random_string = os.urandom(length)
    return unicode(random_string, encoding='UTF-8')
Reply all
Reply to author
Forward
0 new messages