Skip to content

Commit fdd7a9c

Browse files
committed
Fix Libdoc with defaults containing non-ASCII bytes
Fixes robotframework#3259.
1 parent 62049b6 commit fdd7a9c

5 files changed

Lines changed: 77 additions & 39 deletions

File tree

atest/robot/libdoc/console_viewer.robot

Lines changed: 7 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -10,9 +10,13 @@ List all keywords
1010
... Keyword with tags 2
1111
... Keyword With Tags 3
1212
... Multiline Doc With Split Short Doc
13-
... Non Ascii Doc
14-
... Non Ascii Doc With Bytes
15-
... Non Ascii Doc With Declared Utf 8
13+
... Non Ascii Bytes Defaults
14+
... Non Ascii String Defaults
15+
... Non Ascii String Doc
16+
... Non Ascii String Doc With Escapes
17+
... Non Ascii Unicode Defaults
18+
... Non Ascii Unicode Doc
19+
... Non String Defaults
1620
... Set Name Using Robot Name Attribute
1721
... Takes \${embedded} \${args}
1822

atest/robot/libdoc/html_output.robot

Lines changed: 17 additions & 14 deletions
Original file line numberDiff line numberDiff line change
@@ -28,35 +28,38 @@ Inits
2828
${MODEL['inits']}
2929

3030
Keyword Names
31-
${MODEL['keywords'][0]['name']} Get Hello
32-
${MODEL['keywords'][1]['name']} Keyword
33-
${MODEL['keywords'][9]['name']} Set Name Using Robot Name Attribute
31+
${MODEL['keywords'][0]['name']} Get Hello
32+
${MODEL['keywords'][1]['name']} Keyword
33+
${MODEL['keywords'][13]['name']} Set Name Using Robot Name Attribute
3434

3535
Keyword Arguments
3636
[Template] Should Be Equal As Strings
37-
${MODEL['keywords'][0]['args']} []
38-
${MODEL['keywords'][1]['args']} ['a1=d', '*a2']
39-
${MODEL['keywords'][9]['args']} ['a', 'b', '*args', '**kwargs']
37+
${MODEL['keywords'][0]['args']} []
38+
${MODEL['keywords'][1]['args']} ['a1=d', '*a2']
39+
${MODEL['keywords'][6]['args']} ['arg=hyv\\\\xe4']
40+
${MODEL['keywords'][10]['args']} ['arg=hyvä']
41+
${MODEL['keywords'][12]['args']} ['a=1', 'b=True', 'c=(1, 2, None)']
42+
${MODEL['keywords'][13]['args']} ['a', 'b', '*args', '**kwargs']
4043

4144
Embedded Arguments
4245
[Template] NONE
43-
Should Be Equal ${MODEL['keywords'][10]['name']} Takes \${embedded} \${args}
44-
Should Be Empty ${MODEL['keywords'][10]['args']}
46+
Should Be Equal ${MODEL['keywords'][14]['name']} Takes \${embedded} \${args}
47+
Should Be Empty ${MODEL['keywords'][14]['args']}
4548

4649
Keyword Documentation
4750
${MODEL['keywords'][1]['doc']} <p>A keyword.</p>\n<p>See <a href="#Get%20Hello" class="name">get hello</a> for details.</p>
4851
${MODEL['keywords'][0]['doc']} <p>Get hello.</p>\n<p>See <a href="#Importing" class="name">importing</a> for explanation of nothing and <a href="#Introduction" class="name">introduction</a> for no more information.</p>
4952
${MODEL['keywords'][5]['doc']} <p>This is short doc. It can span multiple physical lines.</p>\n<p>This is body. It can naturally also contain multiple lines.</p>\n<p>And paragraphs.</p>
5053

5154
Non-ASCII Keyword Documentation
52-
${MODEL['keywords'][6]['doc']} <p>Hyvää yötä.</p>\n<p>Спасибо!</p>
53-
${MODEL['keywords'][8]['doc']} <p>Hyvää yötä.</p>
55+
${MODEL['keywords'][8]['doc']} <p>Hyvää yötä.</p>
56+
${MODEL['keywords'][11]['doc']} <p>Hyvää yötä.</p>\n<p>Спасибо!</p>
5457

5558
Keyword Short Doc
56-
${MODEL['keywords'][1]['shortdoc']} A keyword.
57-
${MODEL['keywords'][0]['shortdoc']} Get hello.
58-
${MODEL['keywords'][6]['shortdoc']} Hyvää yötä.
59-
${MODEL['keywords'][8]['shortdoc']} Hyvää yötä.
59+
${MODEL['keywords'][1]['shortdoc']} A keyword.
60+
${MODEL['keywords'][0]['shortdoc']} Get hello.
61+
${MODEL['keywords'][8]['shortdoc']} Hyvää yötä.
62+
${MODEL['keywords'][11]['shortdoc']} Hyvää yötä.
6063

6164
Keyword Short Doc Spanning Multiple Physical Lines
6265
${MODEL['keywords'][5]['shortdoc']} This is short doc. It can span multiple physical lines.

atest/robot/libdoc/module_library.robot

Lines changed: 30 additions & 15 deletions
Original file line numberDiff line numberDiff line change
@@ -2,6 +2,9 @@
22
Suite Setup Run Libdoc And Parse Output ${TESTDATADIR}/module.py
33
Resource libdoc_resource.robot
44

5+
*** Variables ***
6+
${PY3 or IPY} $INTERPRETER.is_py3 or $INTERPRETER.is_ironpython
7+
58
*** Test Cases ***
69
Name
710
Name Should Be module
@@ -28,18 +31,29 @@ Has No Inits
2831
Should Have No Init
2932

3033
Keyword Names
31-
Keyword Name Should Be 0 Get Hello
32-
Keyword Name Should Be 1 Keyword
33-
Keyword Name Should Be 9 Set Name Using Robot Name Attribute
34+
Keyword Name Should Be 0 Get Hello
35+
Keyword Name Should Be 1 Keyword
36+
Keyword Name Should Be 13 Set Name Using Robot Name Attribute
3437

3538
Keyword Arguments
3639
Keyword Arguments Should Be 0
37-
Keyword Arguments Should Be 1 a1=d *a2
38-
Keyword Arguments Should Be 9 a b *args **kwargs
40+
Keyword Arguments Should Be 1 a1=d *a2
41+
Keyword Arguments Should Be 12 a=1 b=True c=(1, 2, None)
42+
Keyword Arguments Should Be 13 a b *args **kwargs
43+
44+
Non-ASCII Unicode Defaults
45+
Keyword Arguments Should Be 10 arg=hyvä
46+
47+
Non-ASCII Bytes Defaults
48+
Keyword Arguments Should Be 6 arg=hyv\\xe4
49+
50+
Non-ASCII String Defaults
51+
${expected} = Set Variable If ${PY3 or IPY} hyvä hyv\\xc3\\xa4
52+
Keyword Arguments Should Be 7 arg=${expected}
3953

4054
Embedded Arguments
41-
Keyword Name Should Be 10 Takes \${embedded} \${args}
42-
Keyword Arguments Should Be 10
55+
Keyword Name Should Be 14 Takes \${embedded} \${args}
56+
Keyword Arguments Should Be 14
4357

4458
Keyword Documentation
4559
Keyword Doc Should Be 1 A keyword.\n\nSee `get hello` for details.
@@ -57,16 +71,17 @@ Multiline Documentation With Split Short Doc
5771
... contain multiple lines.
5872
... ${EMPTY}
5973
... And paragraphs.
60-
Keyword Doc Should Be 5 ${doc}
74+
Keyword Doc Should Be 5 ${doc}
75+
76+
Non-ASCII Unicode doc
77+
Keyword Doc Should Be 11 Hyvää yötä.\n\nСпасибо!
6178

62-
Valid non-ASCII
63-
Keyword Doc Should Be 6 Hyvää yötä.\n\nСпасибо!
64-
Keyword Doc Should Be 8 Hyvää yötä.
79+
Non-ASCII string doc
80+
Keyword Doc Should Be 8 Hyvää yötä.
6581

66-
Invalid non-ASCII
67-
${expected} = Set Variable If $INTERPRETER.is_py3 or $INTERPRETER.is_ironpython
68-
... Hyvää yötä. Hyv\\xe4\\xe4 y\\xf6t\\xe4.
69-
Keyword Doc Should Be 7 ${expected}
82+
Non-ASCII string doc with escapes
83+
${expected} = Set Variable If ${PY3 or IPY} Hyvää yötä. Hyv\\xe4\\xe4 y\\xf6t\\xe4.
84+
Keyword Doc Should Be 9 ${expected}
7085

7186
Keyword tags
7287
Keyword Tags Should Be 1

atest/testdata/libdoc/module.py

Lines changed: 21 additions & 5 deletions
Original file line numberDiff line numberDiff line change
@@ -25,6 +25,22 @@ def get_hello():
2525
return 'foo'
2626

2727

28+
def non_string_defaults(a=1, b=True, c=(1, 2, None)):
29+
pass
30+
31+
32+
def non_ascii_unicode_defaults(arg=u'hyvä'):
33+
pass
34+
35+
36+
def non_ascii_string_defaults(arg='hyvä'):
37+
pass
38+
39+
40+
def non_ascii_bytes_defaults(arg=b'hyv\xe4'):
41+
pass
42+
43+
2844
def multiline_doc_with_split_short_doc():
2945
"""This is short doc.
3046
It can span multiple
@@ -38,19 +54,19 @@ def multiline_doc_with_split_short_doc():
3854
"""
3955

4056

41-
def non_ascii_doc():
57+
def non_ascii_unicode_doc():
4258
u"""Hyv\u00E4\u00E4 y\u00F6t\u00E4.
4359
4460
\u0421\u043F\u0430\u0441\u0438\u0431\u043E!
4561
"""
4662

4763

48-
def non_ascii_doc_with_bytes():
49-
"""Hyv\xE4\xE4 y\xF6t\xE4."""
64+
def non_ascii_string_doc():
65+
"""Hyvää yötä."""
5066

5167

52-
def non_ascii_doc_with_declared_utf_8():
53-
"""Hyvää yötä."""
68+
def non_ascii_string_doc_with_escapes():
69+
"""Hyv\xE4\xE4 y\xF6t\xE4."""
5470

5571

5672
@deco.keyword('Set Name Using Robot Name Attribute')

src/robot/libdocpkg/robotbuilder.py

Lines changed: 2 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -19,7 +19,7 @@
1919
from robot.errors import DataError
2020
from robot.parsing import disable_curdir_processing
2121
from robot.running import TestLibrary, UserLibrary, UserErrorHandler
22-
from robot.utils import split_tags_from_doc, unescape
22+
from robot.utils import split_tags_from_doc, unescape, unic
2323

2424
from .model import LibraryDoc, KeywordDoc
2525

@@ -132,7 +132,7 @@ def _format_arg(self, arg, argspec):
132132
if argspec.types is not None and arg in argspec.types:
133133
result = '%s: %s' % (result, self._format_type(argspec.types[arg]))
134134
if arg in argspec.defaults:
135-
result = '%s=%s' % (result, argspec.defaults[arg])
135+
result = '%s=%s' % (result, unic(argspec.defaults[arg]))
136136
return result
137137

138138
def _format_type(self, type_):

0 commit comments

Comments
 (0)