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
499b2ee8
Kaydet (Commit)
499b2ee8
authored
May 27, 2009
tarafından
Raymond Hettinger
Dosyalara gözat
Seçenekler
Dosyalara Gözat
İndir
Eposta Yamaları
Sade Fark
Stronger tests for namedtuple() to prevent future name conflict errors.
üst
089ba7f6
Hide whitespace changes
Inline
Side-by-side
Showing
1 changed file
with
31 additions
and
0 deletions
+31
-0
test_collections.py
Lib/test/test_collections.py
+31
-0
No files found.
Lib/test/test_collections.py
Dosyayı görüntüle @
499b2ee8
...
@@ -8,6 +8,8 @@ from test import mapping_tests
...
@@ -8,6 +8,8 @@ from test import mapping_tests
import
pickle
,
copy
import
pickle
,
copy
from
random
import
randrange
,
shuffle
from
random
import
randrange
,
shuffle
import
operator
import
operator
import
keyword
import
re
from
collections
import
Hashable
,
Iterable
,
Iterator
from
collections
import
Hashable
,
Iterable
,
Iterator
from
collections
import
Sized
,
Container
,
Callable
from
collections
import
Sized
,
Container
,
Callable
from
collections
import
Set
,
MutableSet
from
collections
import
Set
,
MutableSet
...
@@ -182,6 +184,35 @@ class TestNamedTuple(unittest.TestCase):
...
@@ -182,6 +184,35 @@ class TestNamedTuple(unittest.TestCase):
newt
=
t
.
_replace
(
itemgetter
=
10
,
property
=
20
,
self
=
30
,
cls
=
40
,
tuple
=
50
)
newt
=
t
.
_replace
(
itemgetter
=
10
,
property
=
20
,
self
=
30
,
cls
=
40
,
tuple
=
50
)
self
.
assertEqual
(
newt
,
(
10
,
20
,
30
,
40
,
50
))
self
.
assertEqual
(
newt
,
(
10
,
20
,
30
,
40
,
50
))
# Broader test of all interesting names in a template
with
support
.
captured_stdout
()
as
template
:
T
=
namedtuple
(
'T'
,
'x'
,
verbose
=
True
)
words
=
set
(
re
.
findall
(
'[A-Za-z]+'
,
template
.
getvalue
()))
words
-=
set
(
keyword
.
kwlist
)
T
=
namedtuple
(
'T'
,
words
)
# test __new__
values
=
tuple
(
range
(
len
(
words
)))
t
=
T
(
*
values
)
self
.
assertEqual
(
t
,
values
)
t
=
T
(
**
dict
(
zip
(
T
.
_fields
,
values
)))
self
.
assertEqual
(
t
,
values
)
# test _make
t
=
T
.
_make
(
values
)
self
.
assertEqual
(
t
,
values
)
# exercise __repr__
repr
(
t
)
# test _asdict
self
.
assertEqual
(
t
.
_asdict
(),
dict
(
zip
(
T
.
_fields
,
values
)))
# test _replace
t
=
T
.
_make
(
values
)
newvalues
=
tuple
(
v
*
10
for
v
in
values
)
newt
=
t
.
_replace
(
**
dict
(
zip
(
T
.
_fields
,
newvalues
)))
self
.
assertEqual
(
newt
,
newvalues
)
# test _fields
self
.
assertEqual
(
T
.
_fields
,
tuple
(
words
))
# test __getnewargs__
self
.
assertEqual
(
t
.
__getnewargs__
(),
values
)
class
ABCTestCase
(
unittest
.
TestCase
):
class
ABCTestCase
(
unittest
.
TestCase
):
def
validate_abstract_methods
(
self
,
abc
,
*
names
):
def
validate_abstract_methods
(
self
,
abc
,
*
names
):
...
...
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