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
acd5f811
Kaydet (Commit)
acd5f811
authored
Haz 30, 2013
tarafından
Terry Jan Reedy
Dosyalara gözat
Seçenekler
Dosyalara Gözat
İndir
Eposta Yamaları
Sade Fark
Issue #18189: add test_delegator for Idle Delegator class.
Also change private dict used as a set to a set.
üst
ef1f777e
Hide whitespace changes
Inline
Side-by-side
Showing
2 changed files
with
39 additions
and
2 deletions
+39
-2
Delegator.py
Lib/idlelib/Delegator.py
+2
-2
test_delegator.py
Lib/idlelib/idle_test/test_delegator.py
+37
-0
No files found.
Lib/idlelib/Delegator.py
Dosyayı görüntüle @
acd5f811
...
...
@@ -4,12 +4,12 @@ class Delegator:
def
__init__
(
self
,
delegate
=
None
):
self
.
delegate
=
delegate
self
.
__cache
=
{}
self
.
__cache
=
set
()
def
__getattr__
(
self
,
name
):
attr
=
getattr
(
self
.
delegate
,
name
)
# May raise AttributeError
setattr
(
self
,
name
,
attr
)
self
.
__cache
[
name
]
=
attr
self
.
__cache
.
add
(
name
)
return
attr
def
resetcache
(
self
):
...
...
Lib/idlelib/idle_test/test_delegator.py
0 → 100644
Dosyayı görüntüle @
acd5f811
import
unittest
from
idlelib.Delegator
import
Delegator
class
DelegatorTest
(
unittest
.
TestCase
):
def
test_mydel
(
self
):
# test a simple use scenario
# initialize
mydel
=
Delegator
(
int
)
self
.
assertIs
(
mydel
.
delegate
,
int
)
self
.
assertEqual
(
mydel
.
_Delegator__cache
,
set
())
# add an attribute:
self
.
assertRaises
(
AttributeError
,
mydel
.
__getattr__
,
'xyz'
)
bl
=
mydel
.
bit_length
self
.
assertIs
(
bl
,
int
.
bit_length
)
self
.
assertIs
(
mydel
.
__dict__
[
'bit_length'
],
int
.
bit_length
)
self
.
assertEqual
(
mydel
.
_Delegator__cache
,
{
'bit_length'
})
# add a second attribute
mydel
.
numerator
self
.
assertEqual
(
mydel
.
_Delegator__cache
,
{
'bit_length'
,
'numerator'
})
# delete the second (which, however, leaves it in the name cache)
del
mydel
.
numerator
self
.
assertNotIn
(
'numerator'
,
mydel
.
__dict__
)
self
.
assertIn
(
'numerator'
,
mydel
.
_Delegator__cache
)
# reset by calling .setdelegate, which calls .resetcache
mydel
.
setdelegate
(
float
)
self
.
assertIs
(
mydel
.
delegate
,
float
)
self
.
assertNotIn
(
'bit_length'
,
mydel
.
__dict__
)
self
.
assertEqual
(
mydel
.
_Delegator__cache
,
set
())
if
__name__
==
'__main__'
:
unittest
.
main
(
verbosity
=
2
,
exit
=
2
)
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