From 59d87d53b10a201ef03077c96011523bdd1342e8 Mon Sep 17 00:00:00 2001 From: Petr Viktorin Date: Fri, 18 Sep 2015 11:30:15 +0200 Subject: 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 --- ipatests/test_ipapython/test_ipautil.py | 2 +- ipatests/util.py | 10 ++++++++-- 2 files changed, 9 insertions(+), 3 deletions(-) (limited to 'ipatests') diff --git a/ipatests/test_ipapython/test_ipautil.py b/ipatests/test_ipapython/test_ipautil.py index 609e1f0e5..e19cd2cb6 100644 --- a/ipatests/test_ipapython/test_ipautil.py +++ b/ipatests/test_ipapython/test_ipautil.py @@ -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): diff --git a/ipatests/util.py b/ipatests/util.py index d180c91b7..85b5dbc5e 100644 --- a/ipatests/util.py +++ b/ipatests/util.py @@ -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,)) -- cgit