1
0
mirror of https://github.com/ARM-software/workload-automation.git synced 2025-01-18 12:06:08 +00:00

utils/types: implement __ne__ for level

This should have been handled by the @total_ordering decorator, but
isn't due to

        https://bugs.python.org/issue25732

(briefly, total_ordering is back-ported from Python 3, where the base
object provides the default implementation of __ne__ based on __eq__, so
total_ordering did not override it; this, however does not happen in
Python 2).

Also update unit tests to catch this edge case.
This commit is contained in:
Sergei Trofimov 2018-06-14 14:46:48 +01:00 committed by setrofim
parent 64f9cf79e4
commit 6ee40c2170
2 changed files with 11 additions and 0 deletions

View File

@ -114,6 +114,8 @@ class TestEnumLevel(TestCase):
assert_in('names', e.levels)
assert_list_equal(e.names, ['names', 'one', 'two'])
assert_equal(e.NAMES, 'names')
result = not (e.NAMES != 'names')
assert_true(result)
def test_enum_behavior(self):
e = enum(['one', 'two', 'three'])

View File

@ -569,6 +569,15 @@ class level(object):
else:
return self.value < other
def __ne__(self, other):
if isinstance(other, level):
return self.value != other.value
elif isinstance(other, basestring):
return self.name != other
else:
return self.value != other
class _EnumMeta(type):