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
a5ac2ce9
Kaydet (Commit)
a5ac2ce9
authored
May 02, 2011
tarafından
Raymond Hettinger
Dosyalara gözat
Seçenekler
Dosyalara Gözat
İndir
Eposta Yamaları
Sade Fark
Backport 3.3 fixes and cleans ups.
üst
81b96569
Hide whitespace changes
Inline
Side-by-side
Showing
2 changed files
with
22 additions
and
11 deletions
+22
-11
collections.py
Lib/collections.py
+3
-0
test_collections.py
Lib/test/test_collections.py
+19
-11
No files found.
Lib/collections.py
Dosyayı görüntüle @
a5ac2ce9
...
@@ -716,6 +716,9 @@ class _ChainMap(MutableMapping):
...
@@ -716,6 +716,9 @@ class _ChainMap(MutableMapping):
def
__contains__
(
self
,
key
):
def
__contains__
(
self
,
key
):
return
any
(
key
in
m
for
m
in
self
.
maps
)
return
any
(
key
in
m
for
m
in
self
.
maps
)
def
__bool__
(
self
):
return
any
(
self
.
maps
)
@_recursive_repr
()
@_recursive_repr
()
def
__repr__
(
self
):
def
__repr__
(
self
):
return
'{0.__class__.__name__}({1})'
.
format
(
return
'{0.__class__.__name__}({1})'
.
format
(
...
...
Lib/test/test_collections.py
Dosyayı görüntüle @
a5ac2ce9
...
@@ -23,10 +23,12 @@ from collections import ByteString
...
@@ -23,10 +23,12 @@ from collections import ByteString
### _ChainMap (helper class for configparser)
### _ChainMap (helper class for configparser)
################################################################################
################################################################################
ChainMap
=
_ChainMap
# rename to keep test code in sync with 3.3 version
class
TestChainMap
(
unittest
.
TestCase
):
class
TestChainMap
(
unittest
.
TestCase
):
def
test_basics
(
self
):
def
test_basics
(
self
):
c
=
_
ChainMap
()
c
=
ChainMap
()
c
[
'a'
]
=
1
c
[
'a'
]
=
1
c
[
'b'
]
=
2
c
[
'b'
]
=
2
d
=
c
.
new_child
()
d
=
c
.
new_child
()
...
@@ -71,19 +73,25 @@ class TestChainMap(unittest.TestCase):
...
@@ -71,19 +73,25 @@ class TestChainMap(unittest.TestCase):
for
m1
,
m2
in
zip
(
d
.
maps
,
e
.
maps
):
for
m1
,
m2
in
zip
(
d
.
maps
,
e
.
maps
):
self
.
assertIsNot
(
m1
,
m2
,
e
)
self
.
assertIsNot
(
m1
,
m2
,
e
)
d
=
d
.
new_child
()
f
=
d
.
new_child
()
d
[
'b'
]
=
5
f
[
'b'
]
=
5
self
.
assertEqual
(
d
.
maps
,
[{
'b'
:
5
},
{
'c'
:
30
},
{
'a'
:
1
,
'b'
:
2
}])
self
.
assertEqual
(
f
.
maps
,
[{
'b'
:
5
},
{
'c'
:
30
},
{
'a'
:
1
,
'b'
:
2
}])
self
.
assertEqual
(
d
.
parents
.
maps
,
[{
'c'
:
30
},
{
'a'
:
1
,
'b'
:
2
}])
# check parents
self
.
assertEqual
(
f
.
parents
.
maps
,
[{
'c'
:
30
},
{
'a'
:
1
,
'b'
:
2
}])
# check parents
self
.
assertEqual
(
d
[
'b'
],
5
)
# find first in chain
self
.
assertEqual
(
f
[
'b'
],
5
)
# find first in chain
self
.
assertEqual
(
d
.
parents
[
'b'
],
2
)
# look beyond maps[0]
self
.
assertEqual
(
f
.
parents
[
'b'
],
2
)
# look beyond maps[0]
def
test_contructor
(
self
):
def
test_contructor
(
self
):
self
.
assertEqual
(
_ChainMap
()
.
maps
,
[{}])
# no-args --> one new dict
self
.
assertEqual
(
ChainMap
()
.
maps
,
[{}])
# no-args --> one new dict
self
.
assertEqual
(
_ChainMap
({
1
:
2
})
.
maps
,
[{
1
:
2
}])
# 1 arg --> list
self
.
assertEqual
(
ChainMap
({
1
:
2
})
.
maps
,
[{
1
:
2
}])
# 1 arg --> list
def
test_bool
(
self
):
self
.
assertFalse
(
ChainMap
())
self
.
assertFalse
(
ChainMap
({},
{}))
self
.
assertTrue
(
ChainMap
({
1
:
2
},
{}))
self
.
assertTrue
(
ChainMap
({},
{
1
:
2
}))
def
test_missing
(
self
):
def
test_missing
(
self
):
class
DefaultChainMap
(
_
ChainMap
):
class
DefaultChainMap
(
ChainMap
):
def
__missing__
(
self
,
key
):
def
__missing__
(
self
,
key
):
return
999
return
999
d
=
DefaultChainMap
(
dict
(
a
=
1
,
b
=
2
),
dict
(
b
=
20
,
c
=
30
))
d
=
DefaultChainMap
(
dict
(
a
=
1
,
b
=
2
),
dict
(
b
=
20
,
c
=
30
))
...
@@ -100,7 +108,7 @@ class TestChainMap(unittest.TestCase):
...
@@ -100,7 +108,7 @@ class TestChainMap(unittest.TestCase):
d
.
popitem
()
d
.
popitem
()
def
test_dict_coercion
(
self
):
def
test_dict_coercion
(
self
):
d
=
_
ChainMap
(
dict
(
a
=
1
,
b
=
2
),
dict
(
b
=
20
,
c
=
30
))
d
=
ChainMap
(
dict
(
a
=
1
,
b
=
2
),
dict
(
b
=
20
,
c
=
30
))
self
.
assertEqual
(
dict
(
d
),
dict
(
a
=
1
,
b
=
2
,
c
=
30
))
self
.
assertEqual
(
dict
(
d
),
dict
(
a
=
1
,
b
=
2
,
c
=
30
))
self
.
assertEqual
(
dict
(
d
.
items
()),
dict
(
a
=
1
,
b
=
2
,
c
=
30
))
self
.
assertEqual
(
dict
(
d
.
items
()),
dict
(
a
=
1
,
b
=
2
,
c
=
30
))
...
...
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