Skip to content

Commit e9ab9aa

Browse files
committed
test cleanup: create all more complex arguments in a variable file, move importing that variable file back to files where it is needed, fix test for handling control characters as arguments
1 parent b5c16ae commit e9ab9aa

5 files changed

Lines changed: 71 additions & 62 deletions

File tree

test/atest/argument_types.txt

Lines changed: 36 additions & 44 deletions
Original file line numberDiff line numberDiff line change
@@ -1,84 +1,76 @@
11
*** Settings ***
22
Resource resource.txt
3-
Library Collections
3+
Variables arguments.py
44

55
*** Test Cases ***
66
String As Argument
7-
Argument Should Accepted String As Argument 'Hello, world!'
7+
String As Argument ${BYTE STRING}
88

9-
Unicode String As Argument
10-
Unicode String As Argument ${UNICODE}
9+
Non-ASCII String As Argument
10+
Unicode String As Argument ${UNICODE STRING}
11+
12+
Control Char As Argument
13+
[Documentation] This may also fail with ExpatError
14+
Control Char As Argument ${CONTROL CHAR}
1115

1216
Empty String As Argument
13-
Argument Should Accepted Empty String As Argument ''
17+
Empty String As Argument ${EMPTY}
1418

1519
Integer As Argument
16-
Argument Should Accepted Integer As Argument 42
17-
Argument Should Accepted Negative Integer As Argument -1
20+
Integer As Argument ${42}
21+
Negative Integer As Argument ${-1}
1822

1923
Float As Argument
20-
Argument Should Accepted Float As Argument 3.14
21-
Argument Should Accepted Negative Float As Argument -0.5
24+
Float As Argument ${3.14}
25+
Negative Float As Argument ${-0.5}
2226

2327
Zero As Argument
24-
Argument Should Accepted Zero As Argument 0
28+
Zero As Argument ${0}
2529

2630
Boolean As Argument
27-
Argument Should Accepted Boolean True As Argument True
28-
Argument Should Accepted Boolean False As Argument False
31+
Boolean True As Argument ${True}
32+
Boolean False As Argument ${False}
2933

3034
None As Argument
31-
[Documentation] None/null is not supported by all XML-RPC versions and thus it is converted to a string
32-
Argument Should Accepted None As Argument None
35+
[Documentation] None is converted to empty string because it is not supported by all XML-RPC versions.
36+
None As Argument ${None}
3337

3438
Arbitrary Object As Argument
35-
[Documentation] Arbitrary objects cannot be transferred over XML-RPC and thus only their string presentation is used
36-
Object As Argument ${MyObject()}
39+
[Documentation] Arbitrary objects cannot be transferred over XML-RPC and thus only their string presentation is used
40+
Object As Argument ${MyObject()}
3741

3842
List As Argument
39-
Argument Should Accepted List As Argument ['One', -2, False]
40-
Argument Should Accepted Empty List As Argument []
43+
List As Argument ${LIST}
44+
Empty List As Argument ${EMPTY LIST}
4145

4246
List Containing None As Argument
43-
Argument Should Accepted List Containing None As Argument [None]
47+
List Containing None As Argument ${LIST WITH NONE}
4448

4549
List Containing Arbitrary Objects As Argument
46-
List Containing Objects As Argument ${LIST_WITH_OBJECTS}
50+
List Containing Objects As Argument ${LIST WITH OBJECTS}
4751

4852
Nested List As Argument
49-
Nested List As Argument ${NESTED_LIST}
53+
Nested List As Argument ${NESTED LIST}
5054

5155
Tuple As Argument
52-
[Documentation] Tuples are converted to lists
53-
Argument Should Accepted List As Argument ('One', -2, False)
54-
Argument Should Accepted Empty List As Argument ()
55-
Nested List As Argument ${NESTED_TUPLE}
56+
[Documentation] Tuples are converted to lists
57+
List As Argument ${TUPLE}
58+
Empty List As Argument ${EMPTY TUPLE}
59+
Nested List As Argument ${NESTED TUPLE}
5660

5761
Dictionary As Argument
58-
Argument Should Accepted Dictionary As Argument {'one': 1, 'spam': 'eggs'}
59-
Argument Should Accepted Empty Dictionary As Argument {}
62+
Dictionary As Argument ${DICT}
63+
Empty Dictionary As Argument ${EMPTY DICT}
6064

6165
Dictionary With Non-String Keys As Argument
62-
[Documentation] XML-RPC supports only strings as keys so must convert them
63-
Argument Should Accepted Dictionary With Non String Keys As Argument {1: 2, None: True}
66+
[Documentation] XML-RPC supports only strings as keys so must convert them
67+
Dictionary With Non String Keys As Argument ${DICT WITH NON STRING KEYS}
6468

6569
Dictionary Containing None As Argument
66-
Argument Should Accepted Dictionary Containing None As Argument {'As value': None, None: 'As key'}
70+
Dictionary Containing None As Argument ${DICT WITH NONE}
6771

6872
Dictionary Containing Objects As Argument
69-
Dictionary Containing Objects As Argument ${DICT_WITH_OBJECTS}
73+
Dictionary Containing Objects As Argument ${DICT WITH OBJECTS}
7074

7175
Nested Dictionary As Argument
72-
Nested Dictionary As Argument ${NESTED_DICT}
73-
74-
Control Char As Argument
75-
[Documentation] In this situation the received error is not that good FAIL REGEXP: .*ExpatError.*
76-
${arg} = Evaluate '\\x01'
77-
String As Argument ${arg}
78-
79-
*** Keywords ***
80-
Argument Should Accepted
81-
[Arguments] ${keyword} ${argument}
82-
${argument} = Evaluate ${argument}
83-
Run Keyword ${keyword} ${argument}
84-
76+
Nested Dictionary As Argument ${NESTED DICT}

test/atest/arguments.py

Lines changed: 21 additions & 7 deletions
Original file line numberDiff line numberDiff line change
@@ -5,12 +5,26 @@ def __init__(self, index=''):
55
def __str__(self):
66
return '<MyObject%s>' % self.index
77

8-
UNICODE = (u'Hyv\u00E4\u00E4 y\u00F6t\u00E4. '
9-
u'\u0421\u043F\u0430\u0441\u0438\u0431\u043E!')
8+
BYTE_STRING = 'Hello, world!'
9+
UNICODE_STRING = (u'Hyv\u00E4\u00E4 y\u00F6t\u00E4. '
10+
u'\u0421\u043F\u0430\u0441\u0438\u0431\u043E!')
11+
CONTROL_CHAR = '\x01'
12+
13+
LIST = ['One', -2, False]
14+
EMPTY_LIST = []
15+
LIST_WITH_NONE = [None]
1016
LIST_WITH_OBJECTS = [MyObject(1), MyObject(2)]
11-
NESTED_LIST = [ [True, False], [[1, None, MyObject(), {}]] ]
12-
NESTED_TUPLE = ( (True, False), [(1, None, MyObject(), {})] )
17+
NESTED_LIST = [[True, False], [[1, None, MyObject(), {}]]]
18+
19+
TUPLE = ('One', -2, False)
20+
EMPTY_TUPLE = ()
21+
NESTED_TUPLE = ((True, False), [(1, None, MyObject(), {})])
22+
23+
DICT = {'one': 1, 'spam': 'eggs'}
24+
EMPTY_DICT = {}
25+
DICT_WITH_NON_STRING_KEYS = {1: 2, None: True}
26+
DICT_WITH_NONE = {'As value': None, None: 'As key'}
1327
DICT_WITH_OBJECTS = {'As value': MyObject(1), MyObject(2): 'As key'}
14-
NESTED_DICT = { 1: {None: False},
15-
2: {'A': {'n': None},
16-
'B': {'o': MyObject(), 'e': {}}} }
28+
NESTED_DICT = {1: {None: False},
29+
2: {'A': {'n': None},
30+
'B': {'o': MyObject(), 'e': {}}}}

test/atest/logging.txt

Lines changed: 2 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -1,5 +1,6 @@
11
*** Settings ***
22
Resource resource.txt
3+
Variables arguments.py
34
Suite Setup Set Debug Log Level
45
Suite Teardown Reset Log Level
56

@@ -20,7 +21,7 @@ Multiple Messages With Different Levels
2021
Multiple Messages With Different Levels
2122

2223
Log Unicode
23-
[Documentation] LOG 1 INFO ${UNICODE}
24+
[Documentation] LOG 1 INFO ${UNICODE STRING}
2425
Log Unicode
2526

2627
Logging And Failing

test/atest/resource.txt

Lines changed: 0 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -1,6 +1,5 @@
11
*** Settings ***
22
Library Remote localhost:${PORT}
3-
Variables arguments.py
43

54
*** Variables ***
65
${PORT} 8270

test/libs/examplelib.py

Lines changed: 12 additions & 9 deletions
Original file line numberDiff line numberDiff line change
@@ -18,7 +18,7 @@ def passing(self):
1818
See `Failing`, `Logging`, and `Returning` for other basic keywords.
1919
"""
2020
pass
21-
21+
2222
def failing(self, message):
2323
"""This keyword fails with provided `message`"""
2424
raise AssertionError(message)
@@ -52,7 +52,7 @@ def multiple_messages_with_different_levels(self):
5252

5353
def log_unicode(self):
5454
print self._unicode
55-
55+
5656
def logging_and_failing(self):
5757
print '*INFO* This keyword will fail!'
5858
print '*WARN* Run for your lives!!'
@@ -133,6 +133,9 @@ def unicode_string_as_argument(self, arg):
133133
def empty_string_as_argument(self, arg):
134134
self._should_be_equal(arg, '')
135135

136+
def control_char_as_argument(self, char):
137+
self._should_be_equal(char, '\x01')
138+
136139
def integer_as_argument(self, arg):
137140
self._should_be_equal(arg, self.return_integer())
138141

@@ -197,7 +200,7 @@ def nested_dictionary_as_argument(self, arg):
197200
self._should_be_equal(arg, exp)
198201

199202
def _should_be_equal(self, arg, exp):
200-
if arg != exp:
203+
if arg != exp or type(arg) != type(exp):
201204
raise AssertionError('%r != %r' % (arg, exp))
202205

203206
# Return values
@@ -211,21 +214,24 @@ def return_unicode_string(self):
211214
def return_empty_string(self):
212215
return ''
213216

217+
def return_control_char(self):
218+
return '\x01'
219+
214220
def return_integer(self):
215221
return 42
216222

217223
def return_negative_integer(self):
218224
return -1
219-
225+
220226
def return_float(self):
221227
return 3.14
222-
228+
223229
def return_negative_float(self):
224230
return -0.5
225231

226232
def return_zero(self):
227233
return 0
228-
234+
229235
def return_boolean_true(self):
230236
return True
231237

@@ -281,9 +287,6 @@ def return_nested_dictionary(self):
281287
return { 1: {None: False},
282288
2: {'A': {'n': None}, 'B': {'o': MyObject(), 'e': {}}} }
283289

284-
def return_control_char(self):
285-
return '\x01'
286-
287290
# Not keywords
288291

289292
def _private_method(self):

0 commit comments

Comments
 (0)