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
664fe399
Commit
664fe399
authored
Jun 01, 2019
by
Rob Day
Committed by
Raymond Hettinger
May 31, 2019
Browse files
Options
Browse Files
Download
Email Patches
Plain Diff
bpo-29984: Improve 'heapq' test coverage (GH-992)
parent
5c22476c
Changes
2
Hide whitespace changes
Inline
Side-by-side
Showing
2 changed files
with
33 additions
and
2 deletions
+33
-2
Lib/heapq.py
Lib/heapq.py
+2
-2
Lib/test/test_heapq.py
Lib/test/test_heapq.py
+31
-0
No files found.
Lib/heapq.py
View file @
664fe399
...
@@ -597,5 +597,5 @@ except ImportError:
...
@@ -597,5 +597,5 @@ except ImportError:
if
__name__
==
"__main__"
:
if
__name__
==
"__main__"
:
import
doctest
import
doctest
# pragma: no cover
print
(
doctest
.
testmod
())
print
(
doctest
.
testmod
())
# pragma: no cover
Lib/test/test_heapq.py
View file @
664fe399
...
@@ -2,6 +2,7 @@
...
@@ -2,6 +2,7 @@
import
random
import
random
import
unittest
import
unittest
import
doctest
from
test
import
support
from
test
import
support
from
unittest
import
TestCase
,
skipUnless
from
unittest
import
TestCase
,
skipUnless
...
@@ -26,6 +27,23 @@ class TestModules(TestCase):
...
@@ -26,6 +27,23 @@ class TestModules(TestCase):
self
.
assertEqual
(
getattr
(
c_heapq
,
fname
).
__module__
,
'_heapq'
)
self
.
assertEqual
(
getattr
(
c_heapq
,
fname
).
__module__
,
'_heapq'
)
def
load_tests
(
loader
,
tests
,
ignore
):
# The 'merge' function has examples in its docstring which we should test
# with 'doctest'.
#
# However, doctest can't easily find all docstrings in the module (loading
# it through import_fresh_module seems to confuse it), so we specifically
# create a finder which returns the doctests from the merge method.
class
HeapqMergeDocTestFinder
:
def
find
(
self
,
*
args
,
**
kwargs
):
dtf
=
doctest
.
DocTestFinder
()
return
dtf
.
find
(
py_heapq
.
merge
)
tests
.
addTests
(
doctest
.
DocTestSuite
(
py_heapq
,
test_finder
=
HeapqMergeDocTestFinder
()))
return
tests
class
TestHeap
:
class
TestHeap
:
def
test_push_pop
(
self
):
def
test_push_pop
(
self
):
...
@@ -135,6 +153,13 @@ class TestHeap:
...
@@ -135,6 +153,13 @@ class TestHeap:
x
=
self
.
module
.
heappushpop
(
h
,
11
)
x
=
self
.
module
.
heappushpop
(
h
,
11
)
self
.
assertEqual
((
h
,
x
),
([
11
],
10
))
self
.
assertEqual
((
h
,
x
),
([
11
],
10
))
def
test_heappop_max
(
self
):
# _heapop_max has an optimization for one-item lists which isn't
# covered in other tests, so test that case explicitly here
h
=
[
3
,
2
]
self
.
assertEqual
(
self
.
module
.
_heappop_max
(
h
),
3
)
self
.
assertEqual
(
self
.
module
.
_heappop_max
(
h
),
2
)
def
test_heapsort
(
self
):
def
test_heapsort
(
self
):
# Exercise everything with repeated heapsort checks
# Exercise everything with repeated heapsort checks
for
trial
in
range
(
100
):
for
trial
in
range
(
100
):
...
@@ -168,6 +193,12 @@ class TestHeap:
...
@@ -168,6 +193,12 @@ class TestHeap:
list
(
self
.
module
.
merge
(
*
seqs
,
key
=
key
,
reverse
=
reverse
)))
list
(
self
.
module
.
merge
(
*
seqs
,
key
=
key
,
reverse
=
reverse
)))
self
.
assertEqual
(
list
(
self
.
module
.
merge
()),
[])
self
.
assertEqual
(
list
(
self
.
module
.
merge
()),
[])
def
test_empty_merges
(
self
):
# Merging two empty lists (with or without a key) should produce
# another empty list.
self
.
assertEqual
(
list
(
self
.
module
.
merge
([],
[])),
[])
self
.
assertEqual
(
list
(
self
.
module
.
merge
([],
[],
key
=
lambda
:
6
)),
[])
def
test_merge_does_not_suppress_index_error
(
self
):
def
test_merge_does_not_suppress_index_error
(
self
):
# Issue 19018: Heapq.merge suppresses IndexError from user generator
# Issue 19018: Heapq.merge suppresses IndexError from user generator
def
iterable
():
def
iterable
():
...
...
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