Skip to content
Projeler
Gruplar
Parçacıklar
Yardım
Yükleniyor...
Oturum aç / Kaydol
Gezinmeyi değiştir
C
cpython
Proje
Proje
Ayrıntılar
Etkinlik
Cycle Analytics
Depo (repository)
Depo (repository)
Dosyalar
Kayıtlar (commit)
Dallar (branch)
Etiketler
Katkıda bulunanlar
Grafik
Karşılaştır
Grafikler
Konular (issue)
0
Konular (issue)
0
Liste
Pano
Etiketler
Kilometre Taşları
Birleştirme (merge) Talepleri
0
Birleştirme (merge) Talepleri
0
CI / CD
CI / CD
İş akışları (pipeline)
İşler
Zamanlamalar
Grafikler
Paketler
Paketler
Wiki
Wiki
Parçacıklar
Parçacıklar
Üyeler
Üyeler
Collapse sidebar
Close sidebar
Etkinlik
Grafik
Grafikler
Yeni bir konu (issue) oluştur
İşler
Kayıtlar (commit)
Konu (issue) Panoları
Kenar çubuğunu aç
Batuhan Osman TASKAYA
cpython
Commits
f472a90d
Kaydet (Commit)
f472a90d
authored
Ock 10, 2013
tarafından
Ezio Melotti
Dosyalara gözat
Seçenekler
Dosyalara Gözat
İndir
Eposta Yamaları
Sade Fark
#16897: test_bisect now works with unittest test discovery. Initial patch by Zachary Ware.
üst
e212370f
Hide whitespace changes
Inline
Side-by-side
Showing
2 changed files
with
38 additions
and
77 deletions
+38
-77
test_bisect.py
Lib/test/test_bisect.py
+35
-77
NEWS
Misc/NEWS
+3
-0
No files found.
Lib/test/test_bisect.py
Dosyayı görüntüle @
f472a90d
...
@@ -3,25 +3,8 @@ import unittest
...
@@ -3,25 +3,8 @@ import unittest
from
test
import
support
from
test
import
support
from
collections
import
UserList
from
collections
import
UserList
# We do a bit of trickery here to be able to test both the C implementation
py_bisect
=
support
.
import_fresh_module
(
'bisect'
,
blocked
=
[
'_bisect'
])
# and the Python implementation of the module.
c_bisect
=
support
.
import_fresh_module
(
'bisect'
,
fresh
=
[
'_bisect'
])
# Make it impossible to import the C implementation anymore.
sys
.
modules
[
'_bisect'
]
=
0
# We must also handle the case that bisect was imported before.
if
'bisect'
in
sys
.
modules
:
del
sys
.
modules
[
'bisect'
]
# Now we can import the module and get the pure Python implementation.
import
bisect
as
py_bisect
# Restore everything to normal.
del
sys
.
modules
[
'_bisect'
]
del
sys
.
modules
[
'bisect'
]
# This is now the module with the C implementation.
import
bisect
as
c_bisect
class
Range
(
object
):
class
Range
(
object
):
"""A trivial range()-like object without any integer width limitations."""
"""A trivial range()-like object without any integer width limitations."""
...
@@ -45,9 +28,7 @@ class Range(object):
...
@@ -45,9 +28,7 @@ class Range(object):
self
.
last_insert
=
idx
,
item
self
.
last_insert
=
idx
,
item
class
TestBisect
(
unittest
.
TestCase
):
class
TestBisect
:
module
=
None
def
setUp
(
self
):
def
setUp
(
self
):
self
.
precomputedCases
=
[
self
.
precomputedCases
=
[
(
self
.
module
.
bisect_right
,
[],
1
,
0
),
(
self
.
module
.
bisect_right
,
[],
1
,
0
),
...
@@ -218,17 +199,15 @@ class TestBisect(unittest.TestCase):
...
@@ -218,17 +199,15 @@ class TestBisect(unittest.TestCase):
self
.
module
.
insort
(
a
=
data
,
x
=
25
,
lo
=
1
,
hi
=
3
)
self
.
module
.
insort
(
a
=
data
,
x
=
25
,
lo
=
1
,
hi
=
3
)
self
.
assertEqual
(
data
,
[
10
,
20
,
25
,
25
,
25
,
30
,
40
,
50
])
self
.
assertEqual
(
data
,
[
10
,
20
,
25
,
25
,
25
,
30
,
40
,
50
])
class
TestBisectPython
(
TestBisect
):
class
TestBisectPython
(
TestBisect
,
unittest
.
TestCase
):
module
=
py_bisect
module
=
py_bisect
class
TestBisectC
(
TestBisect
):
class
TestBisectC
(
TestBisect
,
unittest
.
TestCase
):
module
=
c_bisect
module
=
c_bisect
#==============================================================================
#==============================================================================
class
TestInsort
(
unittest
.
TestCase
):
class
TestInsort
:
module
=
None
def
test_vsBuiltinSort
(
self
,
n
=
500
):
def
test_vsBuiltinSort
(
self
,
n
=
500
):
from
random
import
choice
from
random
import
choice
for
insorted
in
(
list
(),
UserList
()):
for
insorted
in
(
list
(),
UserList
()):
...
@@ -255,15 +234,14 @@ class TestInsort(unittest.TestCase):
...
@@ -255,15 +234,14 @@ class TestInsort(unittest.TestCase):
self
.
module
.
insort_right
(
lst
,
5
)
self
.
module
.
insort_right
(
lst
,
5
)
self
.
assertEqual
([
5
,
10
],
lst
.
data
)
self
.
assertEqual
([
5
,
10
],
lst
.
data
)
class
TestInsortPython
(
TestInsort
):
class
TestInsortPython
(
TestInsort
,
unittest
.
TestCase
):
module
=
py_bisect
module
=
py_bisect
class
TestInsortC
(
TestInsort
):
class
TestInsortC
(
TestInsort
,
unittest
.
TestCase
):
module
=
c_bisect
module
=
c_bisect
#==============================================================================
#==============================================================================
class
LenOnly
:
class
LenOnly
:
"Dummy sequence class defining __len__ but not __getitem__."
"Dummy sequence class defining __len__ but not __getitem__."
def
__len__
(
self
):
def
__len__
(
self
):
...
@@ -284,9 +262,7 @@ class CmpErr:
...
@@ -284,9 +262,7 @@ class CmpErr:
__eq__
=
__lt__
__eq__
=
__lt__
__ne__
=
__lt__
__ne__
=
__lt__
class
TestErrorHandling
(
unittest
.
TestCase
):
class
TestErrorHandling
:
module
=
None
def
test_non_sequence
(
self
):
def
test_non_sequence
(
self
):
for
f
in
(
self
.
module
.
bisect_left
,
self
.
module
.
bisect_right
,
for
f
in
(
self
.
module
.
bisect_left
,
self
.
module
.
bisect_right
,
self
.
module
.
insort_left
,
self
.
module
.
insort_right
):
self
.
module
.
insort_left
,
self
.
module
.
insort_right
):
...
@@ -313,58 +289,40 @@ class TestErrorHandling(unittest.TestCase):
...
@@ -313,58 +289,40 @@ class TestErrorHandling(unittest.TestCase):
self
.
module
.
insort_left
,
self
.
module
.
insort_right
):
self
.
module
.
insort_left
,
self
.
module
.
insort_right
):
self
.
assertRaises
(
TypeError
,
f
,
10
)
self
.
assertRaises
(
TypeError
,
f
,
10
)
class
TestErrorHandlingPython
(
TestErrorHandling
):
class
TestErrorHandlingPython
(
TestErrorHandling
,
unittest
.
TestCase
):
module
=
py_bisect
module
=
py_bisect
class
TestErrorHandlingC
(
TestErrorHandling
):
class
TestErrorHandlingC
(
TestErrorHandling
,
unittest
.
TestCase
):
module
=
c_bisect
module
=
c_bisect
#==============================================================================
#==============================================================================
libreftest
=
"""
class
TestDocExample
:
Example from the Library Reference: Doc/library/bisect.rst
def
test_grades
(
self
):
def
grade
(
score
,
breakpoints
=
[
60
,
70
,
80
,
90
],
grades
=
'FDCBA'
):
The bisect() function is generally useful for categorizing numeric data.
i
=
self
.
module
.
bisect
(
breakpoints
,
score
)
This example uses bisect() to look up a letter grade for an exam total
return
grades
[
i
]
(say) based on a set of ordered numeric breakpoints: 85 and up is an `A',
75..84 is a `B', etc.
result
=
[
grade
(
score
)
for
score
in
[
33
,
99
,
77
,
70
,
89
,
90
,
100
]]
self
.
assertEqual
(
result
,
[
'F'
,
'A'
,
'C'
,
'C'
,
'B'
,
'A'
,
'A'
])
>>> grades = "FEDCBA"
>>> breakpoints = [30, 44, 66, 75, 85]
def
test_colors
(
self
):
>>> from bisect import bisect
data
=
[(
'red'
,
5
),
(
'blue'
,
1
),
(
'yellow'
,
8
),
(
'black'
,
0
)]
>>> def grade(total):
data
.
sort
(
key
=
lambda
r
:
r
[
1
])
... return grades[bisect(breakpoints, total)]
keys
=
[
r
[
1
]
for
r
in
data
]
...
bisect_left
=
self
.
module
.
bisect_left
>>> grade(66)
self
.
assertEqual
(
data
[
bisect_left
(
keys
,
0
)],
(
'black'
,
0
))
'C'
self
.
assertEqual
(
data
[
bisect_left
(
keys
,
1
)],
(
'blue'
,
1
))
>>> list(map(grade, [33, 99, 77, 44, 12, 88]))
self
.
assertEqual
(
data
[
bisect_left
(
keys
,
5
)],
(
'red'
,
5
))
['E', 'A', 'B', 'D', 'F', 'A']
self
.
assertEqual
(
data
[
bisect_left
(
keys
,
8
)],
(
'yellow'
,
8
))
class
TestDocExamplePython
(
TestDocExample
,
unittest
.
TestCase
):
module
=
py_bisect
"""
class
TestDocExampleC
(
TestDocExample
,
unittest
.
TestCase
):
module
=
c_bisect
#------------------------------------------------------------------------------
#------------------------------------------------------------------------------
__test__
=
{
'libreftest'
:
libreftest
}
def
test_main
(
verbose
=
None
):
from
test
import
test_bisect
test_classes
=
[
TestBisectPython
,
TestBisectC
,
TestInsortPython
,
TestInsortC
,
TestErrorHandlingPython
,
TestErrorHandlingC
]
support
.
run_unittest
(
*
test_classes
)
support
.
run_doctest
(
test_bisect
,
verbose
)
# verify reference counting
if
verbose
and
hasattr
(
sys
,
"gettotalrefcount"
):
import
gc
counts
=
[
None
]
*
5
for
i
in
range
(
len
(
counts
)):
support
.
run_unittest
(
*
test_classes
)
gc
.
collect
()
counts
[
i
]
=
sys
.
gettotalrefcount
()
print
(
counts
)
if
__name__
==
"__main__"
:
if
__name__
==
"__main__"
:
test_main
(
verbose
=
True
)
unittest
.
main
(
)
Misc/NEWS
Dosyayı görüntüle @
f472a90d
...
@@ -408,6 +408,9 @@ Library
...
@@ -408,6 +408,9 @@ Library
Tests
Tests
-----
-----
- Issue #16897: test_bisect now works with unittest test discovery.
Initial patch by Zachary Ware.
- Issue #16852: test_genericpath, test_posixpath, test_ntpath, and test_macpath
- Issue #16852: test_genericpath, test_posixpath, test_ntpath, and test_macpath
now work with unittest test discovery. Patch by Zachary Ware.
now work with unittest test discovery. Patch by Zachary Ware.
...
...
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