提交 87c35457 authored 作者: notoraptor's avatar notoraptor

Update tests for enumerations types.

上级 194290a8
...@@ -81,18 +81,19 @@ def test_cdata(): ...@@ -81,18 +81,19 @@ def test_cdata():
class MyOpEnumList(Op): class MyOpEnumList(Op):
__props__ = ('op_chosen',) __props__ = ('op_chosen',)
params_type = EnumList('ADD', 'SUB', 'MULTIPLY', 'DIVIDE', ctype='unsigned long long') params_type = EnumList(('ADD', '+'), ('SUB', '-'), ('MULTIPLY', '*'), ('DIVIDE', '/'), ctype='unsigned long long')
def __init__(self, choose_op): def __init__(self, choose_op):
assert self.params_type.ADD == 0 assert self.params_type.ADD == 0
assert self.params_type.SUB == 1 assert self.params_type.SUB == 1
assert self.params_type.MULTIPLY == 2 assert self.params_type.MULTIPLY == 2
assert self.params_type.DIVIDE == 3 assert self.params_type.DIVIDE == 3
op_to_const = {'+': self.params_type.ADD, assert self.params_type.fromalias('+') == self.params_type.ADD
'-': self.params_type.SUB, assert self.params_type.fromalias('-') == self.params_type.SUB
'*': self.params_type.MULTIPLY, assert self.params_type.fromalias('*') == self.params_type.MULTIPLY
'/': self.params_type.DIVIDE} assert self.params_type.fromalias('/') == self.params_type.DIVIDE
self.op_chosen = op_to_const[choose_op] assert self.params_type.has_alias(choose_op)
self.op_chosen = choose_op
def get_params(self, node): def get_params(self, node):
return self.op_chosen return self.op_chosen
...@@ -204,7 +205,7 @@ class TestEnumTypes(TestCase): ...@@ -204,7 +205,7 @@ class TestEnumTypes(TestCase):
# Check that invalid enum value raises exception. # Check that invalid enum value raises exception.
try: try:
EnumType(INVALID_VALUE='string is not allowed.') EnumType(INVALID_VALUE='string is not allowed.')
except ValueError: except TypeError:
pass pass
else: else:
raise Exception('EnumType with invalid value should fail.') raise Exception('EnumType with invalid value should fail.')
...@@ -218,6 +219,15 @@ class TestEnumTypes(TestCase): ...@@ -218,6 +219,15 @@ class TestEnumTypes(TestCase):
# Check access to attributes. # Check access to attributes.
assert len((e1.ctype, e1.C1, e1.C2, e1.C3, e1.C4, e1.C5, e1.C6)) == 7 assert len((e1.ctype, e1.C1, e1.C2, e1.C3, e1.C4, e1.C5, e1.C6)) == 7
# Check enum with aliases.
e1 = EnumType(A=('alpha', 0), B=('beta', 1), C=2)
e2 = EnumType(A=('alpha', 0), B=('beta', 1), C=2)
e3 = EnumType(A=('a', 0), B=('beta', 1), C=2)
assert e1 == e2
assert e1 != e3
assert e1.filter('beta') == e1.fromalias('beta') == e1.B == 1
assert e1.filter('C') == e1.fromalias('C') == e1.C == 2
def test_op_with_enumlist(self): def test_op_with_enumlist(self):
a = scalar.int32() a = scalar.int32()
b = scalar.int32() b = scalar.int32()
......
Markdown 格式
0%
您添加了 0 到此讨论。请谨慎行事。
请先完成此评论的编辑!
注册 或者 后发表评论