Fix scoped enums comparison for equal/not equal cases (#1339) (#1571)

This commit is contained in:
Tarcísio Fischer
2018-10-24 06:18:58 -03:00
committed by Wenzel Jakob
parent 1377fbf73c
commit 54eb8193e5
2 changed files with 25 additions and 12 deletions

View File

@@ -47,10 +47,12 @@ Members:
EOne : Docstring for EOne'''
# no TypeError exception for unscoped enum ==/!= int comparisons
# Unscoped enums will accept ==/!= int comparisons
y = m.UnscopedEnum.ETwo
assert y == 2
assert 2 == y
assert y != 3
assert 3 != y
assert int(m.UnscopedEnum.ETwo) == 2
assert str(m.UnscopedEnum(2)) == "UnscopedEnum.ETwo"
@@ -75,11 +77,20 @@ def test_scoped_enum():
z = m.ScopedEnum.Two
assert m.test_scoped_enum(z) == "ScopedEnum::Two"
# expected TypeError exceptions for scoped enum ==/!= int comparisons
# Scoped enums will *NOT* accept ==/!= int comparisons (Will always return False)
assert not z == 3
assert not 3 == z
assert z != 3
assert 3 != z
# Scoped enums will *NOT* accept >, <, >= and <= int comparisons (Will throw exceptions)
with pytest.raises(TypeError):
assert z == 2
z > 3
with pytest.raises(TypeError):
assert z != 3
z < 3
with pytest.raises(TypeError):
z >= 3
with pytest.raises(TypeError):
z <= 3
# order
assert m.ScopedEnum.Two < m.ScopedEnum.Three