Skip to content

Commit 0052dbe

Browse files
committed
Type conversion: Enhanced error reporting. #2890 #2947
1 parent 4b3c5b5 commit 0052dbe

File tree

12 files changed

+265
-158
lines changed

12 files changed

+265
-158
lines changed

atest/robot/keywords/type_conversion/annotations.robot

Lines changed: 6 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -106,6 +106,12 @@ Iterable abc
106106
Invalid iterable abc
107107
Check Test Case ${TESTNAME}
108108

109+
Sequence abc
110+
Check Test Case ${TESTNAME}
111+
112+
Invalid sequence abc
113+
Check Test Case ${TESTNAME}
114+
109115
Mapping abc
110116
Check Test Case ${TESTNAME}
111117

atest/robot/keywords/type_conversion/annotations_with_typing.robot

Lines changed: 9 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -40,6 +40,15 @@ Iterable with params
4040
Invalid iterable
4141
Check Test Case ${TESTNAME}
4242

43+
Sequence
44+
Check Test Case ${TESTNAME}
45+
46+
Sequence with params
47+
Check Test Case ${TESTNAME}
48+
49+
Invalid sequence
50+
Check Test Case ${TESTNAME}
51+
4352
Mapping
4453
Check Test Case ${TESTNAME}
4554

atest/robot/keywords/type_conversion/keyword_decorator.robot

Lines changed: 6 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -113,6 +113,12 @@ Iterable abc
113113
Invalid iterable abc
114114
Check Test Case ${TESTNAME}
115115

116+
Sequence abc
117+
Check Test Case ${TESTNAME}
118+
119+
Invalid sequence abc
120+
Check Test Case ${TESTNAME}
121+
116122
Mapping abc
117123
Check Test Case ${TESTNAME}
118124

atest/testdata/keywords/type_conversion/Annotations.py

Lines changed: 4 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -87,6 +87,10 @@ def iterable(argument: abc.Iterable, expected=None):
8787
_validate_type(argument, expected)
8888

8989

90+
def sequence(argument: abc.Sequence, expected=None):
91+
_validate_type(argument, expected)
92+
93+
9094
def mapping(argument: abc.Mapping, expected=None):
9195
_validate_type(argument, expected)
9296

atest/testdata/keywords/type_conversion/AnnotationsWithTyping.py

Lines changed: 9 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -1,4 +1,4 @@
1-
from typing import Dict, List, Set, Iterable, Mapping
1+
from typing import Dict, List, Set, Iterable, Mapping, Sequence
22

33

44
def dict_(argument: Dict, expected=None):
@@ -33,6 +33,14 @@ def iterable_with_params(argument: Iterable[bool], expected=None):
3333
_validate_type(argument, expected)
3434

3535

36+
def sequence(argument: Sequence, expected=None):
37+
_validate_type(argument, expected)
38+
39+
40+
def sequence_with_params(argument: Sequence[bool], expected=None):
41+
_validate_type(argument, expected)
42+
43+
3644
def mapping(argument: Mapping, expected=None):
3745
_validate_type(argument, expected)
3846

atest/testdata/keywords/type_conversion/KeywordDecorator.py

Lines changed: 5 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -113,6 +113,11 @@ def iterable(argument, expected=None):
113113
_validate_type(argument, expected)
114114

115115

116+
@keyword(types={'argument': abc.Sequence})
117+
def sequence(argument, expected=None):
118+
_validate_type(argument, expected)
119+
120+
116121
@keyword(types={'argument': abc.Mapping})
117122
def mapping(argument, expected=None):
118123
_validate_type(argument, expected)

atest/testdata/keywords/type_conversion/annotations.robot

Lines changed: 69 additions & 55 deletions
Original file line numberDiff line numberDiff line change
@@ -69,7 +69,9 @@ Bytes
6969

7070
Invalid bytes
7171
[Template] Conversion Should Fail
72-
Bytes \u0100
72+
Bytes \u0100 error=Character '\u0100' cannot be mapped to a byte.
73+
Bytes \u00ff\u0100\u0101 error=Character '\u0100' cannot be mapped to a byte.
74+
Bytes Hyvä esimerkki! \u2603 error=Character '\u2603' cannot be mapped to a byte.
7375

7476
Bytearray
7577
Bytearray foo bytearray(b'foo')
@@ -80,7 +82,9 @@ Bytearray
8082

8183
Invalid bytearray
8284
[Template] Conversion Should Fail
83-
Bytearray \u0100
85+
Bytearray \u0100 error=Character '\u0100' cannot be mapped to a byte.
86+
Bytearray \u00ff\u0100\u0101 error=Character '\u0100' cannot be mapped to a byte.
87+
Bytearray Hyvä esimerkki! \u2603 error=Character '\u2603' cannot be mapped to a byte.
8488

8589
Datetime
8690
DateTime 2014-06-11T10:07:42 datetime(2014, 6, 11, 10, 7, 42)
@@ -89,10 +93,10 @@ Datetime
8993

9094
Invalid datetime
9195
[Template] Conversion Should Fail
92-
DateTime foobar
93-
DateTime 1975:06
94-
DateTime 2018
95-
DateTime 201808081443421234567
96+
DateTime foobar error=Invalid timestamp 'foobar'.
97+
DateTime 1975:06 error=Invalid timestamp '1975:06'.
98+
DateTime 2018 error=Invalid timestamp '2018'.
99+
DateTime 201808081443421234567 error=Invalid timestamp '201808081443421234567'.
96100

97101
Date
98102
Date 2014-06-11 date(2014, 6, 11)
@@ -101,11 +105,11 @@ Date
101105

102106
Invalid date
103107
[Template] Conversion Should Fail
104-
Date foobar
105-
Date 1975:06
106-
Date 2018
107-
Date 2014-06-11T10:07:42
108-
Date 20180808000000000001
108+
Date foobar error=Invalid timestamp 'foobar'.
109+
Date 1975:06 error=Invalid timestamp '1975:06'.
110+
Date 2018 error=Invalid timestamp '2018'.
111+
Date 2014-06-11T10:07:42 error=Value is datetime, not date.
112+
Date 20180808000000000001 error=Value is datetime, not date.
109113

110114
Timedelta
111115
Timedelta 10 timedelta(seconds=10)
@@ -121,18 +125,18 @@ Timedelta
121125

122126
Invalid timedelta
123127
[Template] Conversion Should Fail
124-
Timedelta foobar
125-
Timedelta 1 foo
126-
Timedelta 01:02:03:04
127-
128+
Timedelta foobar error=Invalid time string 'foobar'.
129+
Timedelta 1 foo error=Invalid time string '1 foo'.
130+
Timedelta 01:02:03:04 error=Invalid time string '01:02:03:04'.
128131
Enum
132+
129133
Enum FOO MyEnum.FOO
130134
Enum bar MyEnum.bar
131135

132136
Invalid Enum
133137
[Template] Conversion Should Fail
134-
Enum foobar type=MyEnum
135-
Enum BAR type=MyEnum
138+
Enum foobar type=MyEnum error=MyEnum does not have member 'foobar'. Available: 'FOO' and 'bar'
139+
Enum BAR type=MyEnum error=MyEnum does not have member 'BAR'. Available: 'FOO' and 'bar'
136140

137141
NoneType
138142
NoneType None None
@@ -149,13 +153,13 @@ List
149153

150154
Invalid list
151155
[Template] Conversion Should Fail
152-
List [1, ooops]
153-
List ()
154-
List {}
155-
List ooops
156-
List ${EMPTY}
157-
List !"#¤%&/(invalid expression)\=?
158-
List 1 / 0
156+
List [1, ooops] error=Invalid expression.
157+
List () error=Value is tuple, not list.
158+
List {} error=Value is dictionary, not list.
159+
List ooops error=Invalid expression.
160+
List ${EMPTY} error=Invalid expression.
161+
List !"#¤%&/(invalid expression)\=? error=Invalid expression.
162+
List 1 / 0 error=Invalid expression.
159163

160164
Tuple
161165
Tuple () ()
@@ -164,10 +168,10 @@ Tuple
164168

165169
Invalid tuple
166170
[Template] Conversion Should Fail
167-
Tuple (1, ooops)
168-
Tuple []
169-
Tuple {}
170-
Tuple ooops
171+
Tuple (1, ooops) error=Invalid expression.
172+
Tuple [] error=Value is list, not tuple.
173+
Tuple {} error=Value is dictionary, not tuple.
174+
Tuple ooops error=Invalid expression.
171175

172176
Dictionary
173177
Dictionary {} {}
@@ -176,11 +180,11 @@ Dictionary
176180

177181
Invalid dictionary
178182
[Template] Conversion Should Fail
179-
Dictionary {1: ooops}
180-
Dictionary []
181-
Dictionary ()
182-
Dictionary ooops
183-
Dictionary {{'not': 'hashable'}: 'xxx'}
183+
Dictionary {1: ooops} error=Invalid expression.
184+
Dictionary [] error=Value is list, not dict.
185+
Dictionary () error=Value is tuple, not dict.
186+
Dictionary ooops error=Invalid expression.
187+
Dictionary {{'not': 'hashable'}: 'xxx'} error=Evaluating expression failed: *
184188

185189
Set
186190
Set set() set()
@@ -189,13 +193,13 @@ Set
189193

190194
Invalid set
191195
[Template] Conversion Should Fail
192-
Set {1, ooops}
193-
Set {}
194-
Set ()
195-
Set []
196-
Set ooops
197-
Set {{'not', 'hashable'}}
198-
Set frozenset()
196+
Set {1, ooops} error=Invalid expression.
197+
Set {} error=Value is dictionary, not set.
198+
Set () error=Value is tuple, not set.
199+
Set [] error=Value is list, not set.
200+
Set ooops error=Invalid expression.
201+
Set {{'not', 'hashable'}} error=Evaluating expression failed: *
202+
Set frozenset() error=Invalid expression.
199203

200204
Frozenset
201205
Frozenset frozenset() frozenset()
@@ -205,10 +209,10 @@ Frozenset
205209

206210
Invalid frozenset
207211
[Template] Conversion Should Fail
208-
Frozenset {1, ooops} type=set
209-
Frozenset {} type=set
210-
Frozenset ooops type=set
211-
Frozenset {{'not', 'hashable'}} type=set
212+
Frozenset {1, ooops} type=set error=Invalid expression.
213+
Frozenset {} type=set error=Value is dictionary, not set.
214+
Frozenset ooops type=set error=Invalid expression.
215+
Frozenset {{'not', 'hashable'}} type=set error=Evaluating expression failed: *
212216

213217
Iterable abc
214218
Iterable ['list', 'is', 'ok'] ['list', 'is', 'ok']
@@ -218,17 +222,27 @@ Iterable abc
218222

219223
Invalid iterable abc
220224
[Template] Conversion Should Fail
221-
Iterable foobar
225+
Iterable foobar error=Failed to convert to list, tuple, set or dictionary.
226+
227+
Sequence abc
228+
Sequence ['list', 'is', 'ok'] ['list', 'is', 'ok']
229+
Sequence ('tuple',) ('tuple',)
230+
231+
Invalid sequence abc
232+
[Template] Conversion Should Fail
233+
Sequence foobar error=Failed to convert to list or tuple.
234+
Sequence {'a': 1, 'b': 2} error=Failed to convert to list or tuple.
235+
Sequence {1, 2, 3} error=Failed to convert to list or tuple.
222236

223237
Mapping abc
224238
Mapping {'foo': 1, 2: 'bar'} {'foo': 1, 2: 'bar'}
225239
Mutable mapping {'foo': 1, 2: 'bar'} {'foo': 1, 2: 'bar'}
226240

227241
Invalid mapping abc
228242
[Template] Conversion Should Fail
229-
Mapping foobar type=dictionary
230-
Mapping [] type=dictionary
231-
Mutable mapping barfoo type=dictionary
243+
Mapping foobar type=dictionary error=Invalid expression.
244+
Mapping [] type=dictionary error=Value is list, not dict.
245+
Mutable mapping barfoo type=dictionary error=Invalid expression.
232246

233247
Set abc
234248
Set abc set() set()
@@ -240,12 +254,12 @@ Set abc
240254

241255
Invalid set abc
242256
[Template] Conversion Should Fail
243-
Set abc {1, ooops} type=set
244-
Set abc {} type=set
245-
Set abc ooops type=set
246-
Mutable set {1, ooops} type=set
247-
Mutable set {} type=set
248-
Mutable set ooops type=set
257+
Set abc {1, ooops} type=set error=Invalid expression.
258+
Set abc {} type=set error=Value is dictionary, not set.
259+
Set abc ooops type=set error=Invalid expression.
260+
Mutable set {1, ooops} type=set error=Invalid expression.
261+
Mutable set {} type=set error=Value is dictionary, not set.
262+
Mutable set ooops type=set error=Invalid expression.
249263

250264
Unknown types are not converted
251265
Unknown foo 'foo'
@@ -272,7 +286,7 @@ Invalid positional as named
272286
[Template] Conversion Should Fail
273287
Integer argument=1.0
274288
Float argument=xxx
275-
Dictionary argument=[0]
289+
Dictionary argument=[0] error=Value is list, not dict.
276290

277291
Varargs
278292
Varargs 1 2 3 expected=(1, 2, 3)

atest/testdata/keywords/type_conversion/annotations_with_typing.robot

Lines changed: 27 additions & 13 deletions
Original file line numberDiff line numberDiff line change
@@ -15,9 +15,9 @@ Dict with params
1515

1616
Invalid dictionary
1717
[Template] Conversion Should Fail
18-
Dict {1: ooops} type=dictionary
19-
Dict [] type=dictionary
20-
Dict with params ooops type=dictionary
18+
Dict {1: ooops} type=dictionary error=Invalid expression.
19+
Dict [] type=dictionary error=Value is list, not dict.
20+
Dict with params ooops type=dictionary error=Invalid expression.
2121

2222
List
2323
List [] []
@@ -31,9 +31,9 @@ List with params
3131

3232
Invalid list
3333
[Template] Conversion Should Fail
34-
List [1, oops]
35-
List ()
36-
List with params ooops type=list
34+
List [1, oops] error=Invalid expression.
35+
List () error=Value is tuple, not list.
36+
List with params ooops type=list error=Invalid expression.
3737

3838
Set
3939
Set set() set()
@@ -47,9 +47,9 @@ Set with params
4747

4848
Invalid Set
4949
[Template] Conversion Should Fail
50-
Set {1, ooops}
51-
Set {}
52-
Set ooops
50+
Set {1, ooops} error=Invalid expression.
51+
Set {} error=Value is dictionary, not set.
52+
Set ooops error=Invalid expression.
5353

5454
Iterable
5555
Iterable ['list', 'is', 'ok'] ['list', 'is', 'ok']
@@ -65,7 +65,21 @@ Iterable with params
6565

6666
Invalid iterable
6767
[Template] Conversion Should Fail
68-
Iterable foobar
68+
Iterable foobar error=Failed to convert to list, tuple, set or dictionary.
69+
70+
Sequence
71+
Sequence ['list', 'is', 'ok'] ['list', 'is', 'ok']
72+
Sequence ('tuple',) ('tuple',)
73+
74+
Sequence with params
75+
Sequence with params ['list', 'is', 'ok'] ['list', 'is', 'ok']
76+
Sequence with params ('tuple',) ('tuple',)
77+
78+
Invalid sequence
79+
[Template] Conversion Should Fail
80+
Sequence foobar error=Failed to convert to list or tuple.
81+
Sequence {'a': 1, 'b': 2} error=Failed to convert to list or tuple.
82+
Sequence with params {1, 2, 3} type=sequence error=Failed to convert to list or tuple.
6983

7084
Mapping
7185
Mapping {} {}
@@ -79,6 +93,6 @@ Mapping with params
7993

8094
Invalid mapping
8195
[Template] Conversion Should Fail
82-
Mapping {1: ooops} type=dictionary
83-
Mapping [] type=dictionary
84-
Mapping with params ooops type=dictionary
96+
Mapping {1: ooops} type=dictionary error=Invalid expression.
97+
Mapping [] type=dictionary error=Value is list, not dict.
98+
Mapping with params ooops type=dictionary error=Invalid expression.

0 commit comments

Comments
 (0)