Avoid py3k warnings related to sort() of unrelated types.

This commit is contained in:
Antoine Pitrou 2012-02-22 00:28:46 +01:00
parent 66e565ee48
commit 93291534b7
1 changed files with 7 additions and 3 deletions

View File

@ -209,8 +209,12 @@ class BasicTestMappingProtocol(unittest.TestCase):
d.update(SimpleUserDict())
i1 = d.items()
i2 = self.reference.items()
i1.sort()
i2.sort()
def safe_sort_key(kv):
k, v = kv
return id(type(k)), id(type(v)), k, v
i1.sort(key=safe_sort_key)
i2.sort(key=safe_sort_key)
self.assertEqual(i1, i2)
class Exc(Exception): pass
@ -343,7 +347,7 @@ class TestMappingProtocol(BasicTestMappingProtocol):
self.assertTrue(not d.has_key('a'))
d = self._full_mapping({'a': 1, 'b': 2})
k = d.keys()
k.sort()
k.sort(key=lambda k: (id(type(k)), k))
self.assertEqual(k, ['a', 'b'])
self.assertRaises(TypeError, d.has_key)