mirror of
https://github.com/python/cpython.git
synced 2025-08-31 14:07:50 +00:00
Followup to #7502: add __hash__ method and tests.
This commit is contained in:
parent
92ed3877b4
commit
165b1283ff
2 changed files with 30 additions and 0 deletions
|
@ -454,6 +454,10 @@ class Example:
|
|||
def __ne__(self, other):
|
||||
return not self == other
|
||||
|
||||
def __hash__(self):
|
||||
return hash((self.source, self.want, self.lineno, self.indent,
|
||||
self.exc_msg))
|
||||
|
||||
|
||||
class DocTest:
|
||||
"""
|
||||
|
@ -517,6 +521,9 @@ class DocTest:
|
|||
def __ne__(self, other):
|
||||
return not self == other
|
||||
|
||||
def __hash__(self):
|
||||
return hash((self.docstring, self.name, self.filename, self.lineno))
|
||||
|
||||
# This lets us sort tests by name:
|
||||
def __lt__(self, other):
|
||||
if not isinstance(other, DocTest):
|
||||
|
@ -2245,6 +2252,10 @@ class DocTestCase(unittest.TestCase):
|
|||
def __ne__(self, other):
|
||||
return not self == other
|
||||
|
||||
def __hash__(self):
|
||||
return hash((self._dt_optionflags, self._dt_setUp, self._dt_tearDown,
|
||||
self._dt_checker))
|
||||
|
||||
def __repr__(self):
|
||||
name = self._dt_test.name.split('.')
|
||||
return "%s (%s)" % (name[-1], '.'.join(name[:-1]))
|
||||
|
|
Loading…
Add table
Add a link
Reference in a new issue