diff options
author | Nick Coghlan <ncoghlan@gmail.com> | 2008-08-11 15:45:58 (GMT) |
---|---|---|
committer | Nick Coghlan <ncoghlan@gmail.com> | 2008-08-11 15:45:58 (GMT) |
commit | 48361f5cbf419cce361fd1aa0389d6304ad167db (patch) | |
tree | e3fb92982d5564830f6ce9a3f725acc51553ec50 /Lib/test/test_hash.py | |
parent | f8d62d23e9b02c557b2bbe69f693fc14c2574281 (diff) | |
download | cpython-48361f5cbf419cce361fd1aa0389d6304ad167db.zip cpython-48361f5cbf419cce361fd1aa0389d6304ad167db.tar.gz cpython-48361f5cbf419cce361fd1aa0389d6304ad167db.tar.bz2 |
Issue 2235: Py3k warnings are now emitted for classes that will no longer inherit a__hash__ implementation from a parent class in Python 3.x. The standard library and test suite have been updated to not emit these warnings.
Diffstat (limited to 'Lib/test/test_hash.py')
-rw-r--r-- | Lib/test/test_hash.py | 24 |
1 files changed, 10 insertions, 14 deletions
diff --git a/Lib/test/test_hash.py b/Lib/test/test_hash.py index f3954c2..47c66d1 100644 --- a/Lib/test/test_hash.py +++ b/Lib/test/test_hash.py @@ -52,6 +52,9 @@ class FixedHash(object): class OnlyEquality(object): def __eq__(self, other): return self is other + # Trick to suppress Py3k warning in 2.x + __hash__ = None +del OnlyEquality.__hash__ class OnlyInequality(object): def __ne__(self, other): @@ -60,6 +63,9 @@ class OnlyInequality(object): class OnlyCmp(object): def __cmp__(self, other): return cmp(id(self), id(other)) + # Trick to suppress Py3k warning in 2.x + __hash__ = None +del OnlyCmp.__hash__ class InheritedHashWithEquality(FixedHash, OnlyEquality): pass class InheritedHashWithInequality(FixedHash, OnlyInequality): pass @@ -71,18 +77,15 @@ class NoHash(object): class HashInheritanceTestCase(unittest.TestCase): default_expected = [object(), DefaultHash(), + OnlyEquality(), + OnlyInequality(), + OnlyCmp(), ] fixed_expected = [FixedHash(), InheritedHashWithEquality(), InheritedHashWithInequality(), InheritedHashWithCmp(), ] - # TODO: Change these to expecting an exception - # when forward porting to Py3k - warning_expected = [OnlyEquality(), - OnlyInequality(), - OnlyCmp(), - ] error_expected = [NoHash()] def test_default_hash(self): @@ -93,20 +96,13 @@ class HashInheritanceTestCase(unittest.TestCase): for obj in self.fixed_expected: self.assertEqual(hash(obj), _FIXED_HASH_VALUE) - def test_warning_hash(self): - for obj in self.warning_expected: - # TODO: Check for the expected Py3k warning here - obj_hash = hash(obj) - self.assertEqual(obj_hash, _default_hash(obj)) - def test_error_hash(self): for obj in self.error_expected: self.assertRaises(TypeError, hash, obj) def test_hashable(self): objects = (self.default_expected + - self.fixed_expected + - self.warning_expected) + self.fixed_expected) for obj in objects: self.assert_(isinstance(obj, Hashable), repr(obj)) |