Do not compare types that are not comparable in Python 3

In Python 3, different types are generally not comparable (except for equality),
and None can't be compared to None.
Fix cases of these comparisons.

In ipatest.util, give up on sorting lists if the sorting raises a TypeError.

Reviewed-By: Tomas Babej <tbabej@redhat.com>
This commit is contained in:
Petr Viktorin 2015-09-18 11:30:15 +02:00 committed by Tomas Babej
parent 5ff4170ff9
commit 59d87d53b1
3 changed files with 12 additions and 6 deletions

View File

@ -1157,9 +1157,9 @@ class Decimal(Number):
super(Decimal, self).__init__(name, *rules, **kw)
if (self.minvalue > self.maxvalue) \
and (self.minvalue is not None and \
self.maxvalue is not None):
if (self.minvalue is not None and
self.maxvalue is not None and
self.minvalue > self.maxvalue):
raise ValueError(
'%s: minvalue > maxvalue (minvalue=%s, maxvalue=%s)' % (
self.nice, self.minvalue, self.maxvalue)

View File

@ -321,7 +321,7 @@ class TestCIDict(object):
def test_fromkeys(self):
dct = ipautil.CIDict.fromkeys(('A', 'b', 'C'))
assert sorted(dct.keys()) == sorted(['A', 'b', 'C'])
assert sorted(dct.values()) == [None] * 3
assert list(dct.values()) == [None] * 3
class TestTimeParser(object):

View File

@ -331,8 +331,14 @@ def assert_deepequal(expected, got, doc='', stack=tuple()):
s_got = got
s_expected = expected
else:
s_got = sorted(got)
s_expected = sorted(expected)
try:
s_got = sorted(got)
except TypeError:
s_got = got
try:
s_expected = sorted(expected)
except TypeError:
s_expected = expected
for (i, e_sub) in enumerate(s_expected):
g_sub = s_got[i]
assert_deepequal(e_sub, g_sub, doc, stack + (i,))