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
d1caae86
Commit
d1caae86
authored
Jun 30, 2013
by
Terry Jan Reedy
Browse files
Options
Browse Files
Download
Email Patches
Plain Diff
Issue #18189: add test_delegator for Idle Delegator class.
Also change private dict used as a set to a set.
parent
7ab0c310
Changes
2
Show whitespace changes
Inline
Side-by-side
Showing
2 changed files
with
40 additions
and
3 deletions
+40
-3
Lib/idlelib/Delegator.py
Lib/idlelib/Delegator.py
+3
-3
Lib/idlelib/idle_test/test_delegator.py
Lib/idlelib/idle_test/test_delegator.py
+37
-0
No files found.
Lib/idlelib/Delegator.py
View file @
d1caae86
...
...
@@ -4,16 +4,16 @@ 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
):
for
key
in
self
.
__cache
.
keys
()
:
for
key
in
self
.
__cache
:
try
:
delattr
(
self
,
key
)
except
AttributeError
:
...
...
Lib/idlelib/idle_test/test_delegator.py
0 → 100644
View file @
d1caae86
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