Skip to content
Projects
Groups
Snippets
Help
Loading...
Help
Support
Keyboard shortcuts
?
Submit feedback
Contribute to GitLab
Sign in / Register
Toggle navigation
C
cpython
Project overview
Project overview
Details
Activity
Releases
Repository
Repository
Files
Commits
Branches
Tags
Contributors
Graph
Compare
Issues
0
Issues
0
List
Boards
Labels
Milestones
Merge Requests
0
Merge Requests
0
Analytics
Analytics
Repository
Value Stream
Wiki
Wiki
Members
Members
Collapse sidebar
Close sidebar
Activity
Graph
Create a new issue
Commits
Issue Boards
Open sidebar
Kirill Smelkov
cpython
Commits
165b1283
Commit
165b1283
authored
Dec 18, 2011
by
Antoine Pitrou
Browse files
Options
Browse Files
Download
Email Patches
Plain Diff
Followup to #7502: add __hash__ method and tests.
parent
92ed3877
Changes
2
Hide whitespace changes
Inline
Side-by-side
Showing
2 changed files
with
30 additions
and
0 deletions
+30
-0
Lib/doctest.py
Lib/doctest.py
+11
-0
Lib/test/test_doctest.py
Lib/test/test_doctest.py
+19
-0
No files found.
Lib/doctest.py
View file @
165b1283
...
@@ -454,6 +454,10 @@ class Example:
...
@@ -454,6 +454,10 @@ class Example:
def
__ne__
(
self
,
other
):
def
__ne__
(
self
,
other
):
return
not
self
==
other
return
not
self
==
other
def
__hash__
(
self
):
return
hash
((
self
.
source
,
self
.
want
,
self
.
lineno
,
self
.
indent
,
self
.
exc_msg
))
class
DocTest
:
class
DocTest
:
"""
"""
...
@@ -517,6 +521,9 @@ class DocTest:
...
@@ -517,6 +521,9 @@ class DocTest:
def
__ne__
(
self
,
other
):
def
__ne__
(
self
,
other
):
return
not
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:
# This lets us sort tests by name:
def
__lt__
(
self
,
other
):
def
__lt__
(
self
,
other
):
if
not
isinstance
(
other
,
DocTest
):
if
not
isinstance
(
other
,
DocTest
):
...
@@ -2245,6 +2252,10 @@ class DocTestCase(unittest.TestCase):
...
@@ -2245,6 +2252,10 @@ class DocTestCase(unittest.TestCase):
def
__ne__
(
self
,
other
):
def
__ne__
(
self
,
other
):
return
not
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
):
def
__repr__
(
self
):
name
=
self
.
_dt_test
.
name
.
split
(
'.'
)
name
=
self
.
_dt_test
.
name
.
split
(
'.'
)
return
"%s (%s)"
%
(
name
[
-
1
],
'.'
.
join
(
name
[:
-
1
]))
return
"%s (%s)"
%
(
name
[
-
1
],
'.'
.
join
(
name
[:
-
1
]))
...
...
Lib/test/test_doctest.py
View file @
165b1283
...
@@ -258,6 +258,21 @@ unless it's `None`:
...
@@ -258,6 +258,21 @@ unless it's `None`:
>>> e = doctest.Example('raise X()', '', exc_msg)
>>> e = doctest.Example('raise X()', '', exc_msg)
>>> e.exc_msg
>>> e.exc_msg
'\n'
'\n'
Compare `Example`:
>>> example = doctest.Example('print 1', '1\n')
>>> same_example = doctest.Example('print 1', '1\n')
>>> other_example = doctest.Example('print 42', '42\n')
>>> example == same_example
True
>>> example != same_example
False
>>> hash(example) == hash(same_example)
True
>>> example == other_example
False
>>> example != other_example
True
"""
"""
def
test_DocTest
():
r"""
def
test_DocTest
():
r"""
...
@@ -361,6 +376,8 @@ Compare `DocTest`:
...
@@ -361,6 +376,8 @@ Compare `DocTest`:
True
True
>>> test != same_test
>>> test != same_test
False
False
>>> hash(test) == hash(same_test)
True
>>> docstring = '''
>>> docstring = '''
... >>> print 42
... >>> print 42
... 42
... 42
...
@@ -382,6 +399,8 @@ Compare `DocTestCase`:
...
@@ -382,6 +399,8 @@ Compare `DocTestCase`:
True
True
>>> test_case != same_test_case
>>> test_case != same_test_case
False
False
>>> hash(test_case) == hash(same_test_case)
True
>>> test == other_test_case
>>> test == other_test_case
False
False
>>> test != other_test_case
>>> test != other_test_case
...
...
Write
Preview
Markdown
is supported
0%
Try again
or
attach a new file
Attach a file
Cancel
You are about to add
0
people
to the discussion. Proceed with caution.
Finish editing this message first!
Cancel
Please
register
or
sign in
to comment