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
8269a44d
Commit
8269a44d
authored
May 09, 2011
by
Ezio Melotti
Browse files
Options
Browse Files
Download
Email Patches
Plain Diff
#11910: Fix test_heapq to skip the C tests when _heapq is missing.
parent
199e0857
Changes
2
Hide whitespace changes
Inline
Side-by-side
Showing
2 changed files
with
29 additions
and
20 deletions
+29
-20
Lib/test/test_heapq.py
Lib/test/test_heapq.py
+27
-20
Misc/NEWS
Misc/NEWS
+2
-0
No files found.
Lib/test/test_heapq.py
View file @
8269a44d
"""Unittests for heapq."""
import
sys
import
random
import
unittest
from
test
import
support
import
sy
s
from
unittest
import
TestCase
,
skipUnles
s
# We do a bit of trickery here to be able to test both the C implementation
# and the Python implementation of the module.
import
heapq
as
c_heapq
py_heapq
=
support
.
import_fresh_module
(
'heapq'
,
blocked
=
[
'_heapq'
])
c_heapq
=
support
.
import_fresh_module
(
'heapq'
,
fresh
=
[
'_heapq'
])
# _heapq.nlargest/nsmallest are saved in heapq._nlargest/_smallest when
# _heapq is imported, so check them there
func_names
=
[
'heapify'
,
'heappop'
,
'heappush'
,
'heappushpop'
,
'heapreplace'
,
'_nlargest'
,
'_nsmallest'
]
class
TestModules
(
TestCase
):
def
test_py_functions
(
self
):
for
fname
in
func_names
:
self
.
assertEqual
(
getattr
(
py_heapq
,
fname
).
__module__
,
'heapq'
)
@
skipUnless
(
c_heapq
,
'requires _heapq'
)
def
test_c_functions
(
self
):
for
fname
in
func_names
:
self
.
assertEqual
(
getattr
(
c_heapq
,
fname
).
__module__
,
'_heapq'
)
class
TestHeap
(
unittest
.
TestCase
):
class
TestHeap
(
TestCase
):
module
=
None
def
test_push_pop
(
self
):
...
...
@@ -176,16 +191,12 @@ class TestHeap(unittest.TestCase):
self
.
assertEqual
(
list
(
self
.
module
.
nlargest
(
n
,
data
,
key
=
f
)),
sorted
(
data
,
key
=
f
,
reverse
=
True
)[:
n
])
class
TestHeapPython
(
TestHeap
):
module
=
py_heapq
# As an early adopter, we sanity check the
# test.support.import_fresh_module utility function
def
test_pure_python
(
self
):
self
.
assertFalse
(
sys
.
modules
[
'heapq'
]
is
self
.
module
)
self
.
assertTrue
(
hasattr
(
self
.
module
.
heapify
,
'__code__'
))
@
skipUnless
(
c_heapq
,
'requires _heapq'
)
class
TestHeapC
(
TestHeap
):
module
=
c_heapq
...
...
@@ -211,12 +222,6 @@ class TestHeapC(TestHeap):
self
.
assertEqual
(
hsort
(
data
,
LT
),
target
)
self
.
assertRaises
(
TypeError
,
data
,
LE
)
# As an early adopter, we sanity check the
# test.support.import_fresh_module utility function
def
test_accelerated
(
self
):
self
.
assertTrue
(
sys
.
modules
[
'heapq'
]
is
self
.
module
)
self
.
assertFalse
(
hasattr
(
self
.
module
.
heapify
,
'__code__'
))
#==============================================================================
...
...
@@ -313,7 +318,9 @@ def L(seqn):
'Test multiple tiers of iterators'
return
chain
(
map
(
lambda
x
:
x
,
R
(
Ig
(
G
(
seqn
)))))
class
TestErrorHandling
(
unittest
.
TestCase
):
@
skipUnless
(
c_heapq
,
'requires _heapq'
)
class
TestErrorHandling
(
TestCase
):
# only for C implementation
module
=
c_heapq
...
...
@@ -372,7 +379,7 @@ class TestErrorHandling(unittest.TestCase):
def
test_main
(
verbose
=
None
):
from
types
import
BuiltinFunctionType
test_classes
=
[
TestHeapPython
,
TestHeapC
,
TestErrorHandling
]
test_classes
=
[
Test
Modules
,
Test
HeapPython
,
TestHeapC
,
TestErrorHandling
]
support
.
run_unittest
(
*
test_classes
)
# verify reference counting
...
...
Misc/NEWS
View file @
8269a44d
...
...
@@ -353,6 +353,8 @@ Build
Tests
-----
- Issue #11910: Fix test_heapq to skip the C tests when _heapq is missing.
- Fix test_startfile to wait for child process to terminate before finishing.
- Issue #11719: Fix message about unexpected test_msilib skip on non-Windows
...
...
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