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
d619ff4b
Commit
d619ff4b
authored
May 17, 2016
by
Terry Jan Reedy
Browse files
Options
Browse Files
Download
Plain Diff
Merge with 3.5
parents
36c18956
092473ee
Changes
3
Show whitespace changes
Inline
Side-by-side
Showing
3 changed files
with
145 additions
and
26 deletions
+145
-26
Lib/idlelib/Percolator.py
Lib/idlelib/Percolator.py
+25
-24
Lib/idlelib/idle_test/test_parenmatch.py
Lib/idlelib/idle_test/test_parenmatch.py
+2
-2
Lib/idlelib/idle_test/test_percolator.py
Lib/idlelib/idle_test/test_percolator.py
+118
-0
No files found.
Lib/idlelib/Percolator.py
View file @
d619ff4b
from
idlelib.WidgetRedirector
import
WidgetRedirector
from
idlelib.WidgetRedirector
import
WidgetRedirector
from
idlelib.Delegator
import
Delegator
from
idlelib.Delegator
import
Delegator
class
Percolator
:
class
Percolator
:
def
__init__
(
self
,
text
):
def
__init__
(
self
,
text
):
...
@@ -16,8 +17,10 @@ class Percolator:
...
@@ -16,8 +17,10 @@ class Percolator:
while
self
.
top
is
not
self
.
bottom
:
while
self
.
top
is
not
self
.
bottom
:
self
.
removefilter
(
self
.
top
)
self
.
removefilter
(
self
.
top
)
self
.
top
=
None
self
.
top
=
None
self
.
bottom
.
setdelegate
(
None
);
self
.
bottom
=
None
self
.
bottom
.
setdelegate
(
None
)
self
.
redir
.
close
();
self
.
redir
=
None
self
.
bottom
=
None
self
.
redir
.
close
()
self
.
redir
=
None
self
.
text
=
None
self
.
text
=
None
def
insert
(
self
,
index
,
chars
,
tags
=
None
):
def
insert
(
self
,
index
,
chars
,
tags
=
None
):
...
@@ -51,54 +54,52 @@ class Percolator:
...
@@ -51,54 +54,52 @@ class Percolator:
f
.
setdelegate
(
filter
.
delegate
)
f
.
setdelegate
(
filter
.
delegate
)
filter
.
setdelegate
(
None
)
filter
.
setdelegate
(
None
)
def
_percolator
(
parent
):
def
_percolator
(
parent
):
# htest #
import
tkinter
as
tk
import
tkinter
as
tk
import
re
import
re
class
Tracer
(
Delegator
):
class
Tracer
(
Delegator
):
def
__init__
(
self
,
name
):
def
__init__
(
self
,
name
):
self
.
name
=
name
self
.
name
=
name
Delegator
.
__init__
(
self
,
None
)
Delegator
.
__init__
(
self
,
None
)
def
insert
(
self
,
*
args
):
def
insert
(
self
,
*
args
):
print
(
self
.
name
,
": insert"
,
args
)
print
(
self
.
name
,
": insert"
,
args
)
self
.
delegate
.
insert
(
*
args
)
self
.
delegate
.
insert
(
*
args
)
def
delete
(
self
,
*
args
):
def
delete
(
self
,
*
args
):
print
(
self
.
name
,
": delete"
,
args
)
print
(
self
.
name
,
": delete"
,
args
)
self
.
delegate
.
delete
(
*
args
)
self
.
delegate
.
delete
(
*
args
)
root
=
tk
.
Tk
()
root
.
title
(
"Test Percolator"
)
box
=
tk
.
Toplevel
(
parent
)
box
.
title
(
"Test Percolator"
)
width
,
height
,
x
,
y
=
list
(
map
(
int
,
re
.
split
(
'[x+]'
,
parent
.
geometry
())))
width
,
height
,
x
,
y
=
list
(
map
(
int
,
re
.
split
(
'[x+]'
,
parent
.
geometry
())))
root
.
geometry
(
"+%d+%d"
%
(
x
,
y
+
150
))
box
.
geometry
(
"+%d+%d"
%
(
x
,
y
+
150
))
text
=
tk
.
Text
(
root
)
text
=
tk
.
Text
(
box
)
p
=
Percolator
(
text
)
p
=
Percolator
(
text
)
pin
=
p
.
insertfilter
pout
=
p
.
removefilter
t1
=
Tracer
(
"t1"
)
t1
=
Tracer
(
"t1"
)
t2
=
Tracer
(
"t2"
)
t2
=
Tracer
(
"t2"
)
def
toggle1
():
def
toggle1
():
if
var1
.
get
()
==
0
:
(
pin
if
var1
.
get
()
else
pout
)(
t1
)
var1
.
set
(
1
)
p
.
insertfilter
(
t1
)
elif
var1
.
get
()
==
1
:
var1
.
set
(
0
)
p
.
removefilter
(
t1
)
def
toggle2
():
def
toggle2
():
if
var2
.
get
()
==
0
:
(
pin
if
var2
.
get
()
else
pout
)(
t2
)
var2
.
set
(
1
)
p
.
insertfilter
(
t2
)
elif
var2
.
get
()
==
1
:
var2
.
set
(
0
)
p
.
removefilter
(
t2
)
text
.
pack
()
text
.
pack
()
var1
=
tk
.
IntVar
()
var1
=
tk
.
IntVar
()
cb1
=
tk
.
Checkbutton
(
root
,
text
=
"Tracer1"
,
command
=
toggle1
,
variable
=
var1
)
cb1
=
tk
.
Checkbutton
(
box
,
text
=
"Tracer1"
,
command
=
toggle1
,
variable
=
var1
)
cb1
.
pack
()
cb1
.
pack
()
var2
=
tk
.
IntVar
()
var2
=
tk
.
IntVar
()
cb2
=
tk
.
Checkbutton
(
root
,
text
=
"Tracer2"
,
command
=
toggle2
,
variable
=
var2
)
cb2
=
tk
.
Checkbutton
(
box
,
text
=
"Tracer2"
,
command
=
toggle2
,
variable
=
var2
)
cb2
.
pack
()
cb2
.
pack
()
root
.
mainloop
()
if
__name__
==
"__main__"
:
if
__name__
==
"__main__"
:
import
unittest
unittest
.
main
(
'idlelib.idle_test.test_percolator'
,
verbosity
=
2
,
exit
=
False
)
from
idlelib.idle_test.htest
import
run
from
idlelib.idle_test.htest
import
run
run
(
_percolator
)
run
(
_percolator
)
Lib/idlelib/idle_test/test_parenmatch.py
View file @
d619ff4b
"""Test idlelib.ParenMatch."""
"""Test idlelib.ParenMatch."""
# This must currently be a gui test because ParenMatch methods use
# This must currently be a gui test because ParenMatch methods use
# several text methods not defined on idlelib.idle_test.mock_tk.Text.
# several text methods not defined on idlelib.idle_test.mock_tk.Text.
from
test.support
import
requires
requires
(
'gui'
)
import
unittest
import
unittest
from
unittest.mock
import
Mock
from
unittest.mock
import
Mock
from
test.support
import
requires
from
tkinter
import
Tk
,
Text
from
tkinter
import
Tk
,
Text
from
idlelib.ParenMatch
import
ParenMatch
from
idlelib.ParenMatch
import
ParenMatch
...
@@ -20,7 +21,6 @@ class ParenMatchTest(unittest.TestCase):
...
@@ -20,7 +21,6 @@ class ParenMatchTest(unittest.TestCase):
@
classmethod
@
classmethod
def
setUpClass
(
cls
):
def
setUpClass
(
cls
):
requires
(
'gui'
)
cls
.
root
=
Tk
()
cls
.
root
=
Tk
()
cls
.
text
=
Text
(
cls
.
root
)
cls
.
text
=
Text
(
cls
.
root
)
cls
.
editwin
=
DummyEditwin
(
cls
.
text
)
cls
.
editwin
=
DummyEditwin
(
cls
.
text
)
...
...
Lib/idlelib/idle_test/test_percolator.py
0 → 100644
View file @
d619ff4b
'''Test Percolator'''
from
test.support
import
requires
requires
(
'gui'
)
import
unittest
from
tkinter
import
Text
,
Tk
,
END
from
idlelib.Percolator
import
Percolator
,
Delegator
class
MyFilter
(
Delegator
):
def
__init__
(
self
):
Delegator
.
__init__
(
self
,
None
)
def
insert
(
self
,
*
args
):
self
.
insert_called_with
=
args
self
.
delegate
.
insert
(
*
args
)
def
delete
(
self
,
*
args
):
self
.
delete_called_with
=
args
self
.
delegate
.
delete
(
*
args
)
def
uppercase_insert
(
self
,
index
,
chars
,
tags
=
None
):
chars
=
chars
.
upper
()
self
.
delegate
.
insert
(
index
,
chars
)
def
lowercase_insert
(
self
,
index
,
chars
,
tags
=
None
):
chars
=
chars
.
lower
()
self
.
delegate
.
insert
(
index
,
chars
)
def
dont_insert
(
self
,
index
,
chars
,
tags
=
None
):
pass
class
PercolatorTest
(
unittest
.
TestCase
):
@
classmethod
def
setUpClass
(
cls
):
cls
.
root
=
Tk
()
cls
.
text
=
Text
(
cls
.
root
)
@
classmethod
def
tearDownClass
(
cls
):
cls
.
text
.
destroy
()
cls
.
root
.
destroy
()
del
cls
.
text
,
cls
.
root
def
setUp
(
self
):
self
.
percolator
=
Percolator
(
self
.
text
)
self
.
filter_one
=
MyFilter
()
self
.
filter_two
=
MyFilter
()
self
.
percolator
.
insertfilter
(
self
.
filter_one
)
self
.
percolator
.
insertfilter
(
self
.
filter_two
)
def
tearDown
(
self
):
self
.
percolator
.
close
()
self
.
text
.
delete
(
'1.0'
,
END
)
def
test_insertfilter
(
self
):
self
.
assertIsNotNone
(
self
.
filter_one
.
delegate
)
self
.
assertEqual
(
self
.
percolator
.
top
,
self
.
filter_two
)
self
.
assertEqual
(
self
.
filter_two
.
delegate
,
self
.
filter_one
)
self
.
assertEqual
(
self
.
filter_one
.
delegate
,
self
.
percolator
.
bottom
)
def
test_removefilter
(
self
):
filter_three
=
MyFilter
()
self
.
percolator
.
removefilter
(
self
.
filter_two
)
self
.
assertEqual
(
self
.
percolator
.
top
,
self
.
filter_one
)
self
.
assertIsNone
(
self
.
filter_two
.
delegate
)
filter_three
=
MyFilter
()
self
.
percolator
.
insertfilter
(
self
.
filter_two
)
self
.
percolator
.
insertfilter
(
filter_three
)
self
.
percolator
.
removefilter
(
self
.
filter_one
)
self
.
assertEqual
(
self
.
percolator
.
top
,
filter_three
)
self
.
assertEqual
(
filter_three
.
delegate
,
self
.
filter_two
)
self
.
assertEqual
(
self
.
filter_two
.
delegate
,
self
.
percolator
.
bottom
)
self
.
assertIsNone
(
self
.
filter_one
.
delegate
)
def
test_insert
(
self
):
self
.
text
.
insert
(
'insert'
,
'foo'
)
self
.
assertEqual
(
self
.
text
.
get
(
'1.0'
,
END
),
'foo
\
n
'
)
self
.
assertTupleEqual
(
self
.
filter_one
.
insert_called_with
,
(
'insert'
,
'foo'
,
None
))
def
test_modify_insert
(
self
):
self
.
filter_one
.
insert
=
self
.
filter_one
.
uppercase_insert
self
.
text
.
insert
(
'insert'
,
'bAr'
)
self
.
assertEqual
(
self
.
text
.
get
(
'1.0'
,
END
),
'BAR
\
n
'
)
def
test_modify_chain_insert
(
self
):
filter_three
=
MyFilter
()
self
.
percolator
.
insertfilter
(
filter_three
)
self
.
filter_two
.
insert
=
self
.
filter_two
.
uppercase_insert
self
.
filter_one
.
insert
=
self
.
filter_one
.
lowercase_insert
self
.
text
.
insert
(
'insert'
,
'BaR'
)
self
.
assertEqual
(
self
.
text
.
get
(
'1.0'
,
END
),
'bar
\
n
'
)
def
test_dont_insert
(
self
):
self
.
filter_one
.
insert
=
self
.
filter_one
.
dont_insert
self
.
text
.
insert
(
'insert'
,
'foo bar'
)
self
.
assertEqual
(
self
.
text
.
get
(
'1.0'
,
END
),
'
\
n
'
)
self
.
filter_one
.
insert
=
self
.
filter_one
.
dont_insert
self
.
text
.
insert
(
'insert'
,
'foo bar'
)
self
.
assertEqual
(
self
.
text
.
get
(
'1.0'
,
END
),
'
\
n
'
)
def
test_without_filter
(
self
):
self
.
text
.
insert
(
'insert'
,
'hello'
)
self
.
assertEqual
(
self
.
text
.
get
(
'1.0'
,
'end'
),
'hello
\
n
'
)
def
test_delete
(
self
):
self
.
text
.
insert
(
'insert'
,
'foo'
)
self
.
text
.
delete
(
'1.0'
,
'1.2'
)
self
.
assertEqual
(
self
.
text
.
get
(
'1.0'
,
END
),
'o
\
n
'
)
self
.
assertTupleEqual
(
self
.
filter_one
.
delete_called_with
,
(
'1.0'
,
'1.2'
))
if
__name__
==
'__main__'
:
unittest
.
main
(
verbosity
=
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