Skip to content

Commit 08c6ae8

Browse files
committed
typeconverter: EnumConverter: Do not convert none
1 parent 61f7c51 commit 08c6ae8

File tree

3 files changed

+13
-1
lines changed

3 files changed

+13
-1
lines changed

atest/testdata/keywords/type_conversion/Annotations.py

Lines changed: 8 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -14,6 +14,10 @@ class MyEnum(Enum):
1414
foo = 'yyy'
1515
normalize_me = True
1616

17+
class NoneEnum(Enum):
18+
NONE = 1
19+
NTWO = 2
20+
NTHREE = 3
1721

1822
class Unknown(object):
1923
pass
@@ -75,6 +79,10 @@ def enum_(argument: MyEnum, expected=None):
7579
_validate_type(argument, expected)
7680

7781

82+
def none_enum_(argument: NoneEnum, expected=None):
83+
_validate_type(argument, expected)
84+
85+
7886
def nonetype(argument: type(None), expected=None):
7987
_validate_type(argument, expected)
8088

atest/testdata/keywords/type_conversion/annotations.robot

Lines changed: 4 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -167,6 +167,9 @@ Enum
167167
Enum FOO MyEnum.FOO
168168
Enum bar MyEnum.bar
169169
Enum foo MyEnum.foo
170+
None enum NTWO NoneEnum.NTWO
171+
None enum None NoneEnum.NONE
172+
None enum NONE NoneEnum.NONE
170173

171174
Normalized enum member match
172175
Enum b a r MyEnum.bar
@@ -184,6 +187,7 @@ Invalid Enum
184187
[Template] Conversion Should Fail
185188
Enum foobar type=MyEnum error=MyEnum does not have member 'foobar'. Available: 'FOO', 'bar', 'foo' and 'normalize_me'
186189
Enum bar! type=MyEnum error=MyEnum does not have member 'bar!'. Available: 'FOO', 'bar', 'foo' and 'normalize_me'
190+
Enum None type=MyEnum error=MyEnum does not have member 'None'. Available: 'FOO', 'bar', 'foo' and 'normalize_me'
187191

188192
NoneType
189193
NoneType None None
@@ -390,7 +394,6 @@ String None is converted to None object
390394
Dictionary
391395
Set
392396
Frozenset
393-
Enum
394397
DateTime
395398
Date
396399
Timedelta

src/robot/running/arguments/typeconverters.py

Lines changed: 1 addition & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -244,6 +244,7 @@ def _convert(self, value, explicit_type=True):
244244
@TypeConverter.register
245245
class EnumConverter(TypeConverter):
246246
type = Enum
247+
convert_none = False
247248

248249
def __init__(self, enum=None):
249250
self._enum = enum

0 commit comments

Comments
 (0)