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
95cf9862
Commit
95cf9862
authored
Aug 21, 2014
by
Serhiy Storchaka
Browse files
Options
Browse Files
Download
Email Patches
Plain Diff
Import Tkinter as tkinter to help merging and avoid backporting errors.
parent
c208fe67
Changes
9
Show whitespace changes
Inline
Side-by-side
Showing
9 changed files
with
214 additions
and
214 deletions
+214
-214
Lib/lib-tk/test/test_tkinter/test_font.py
Lib/lib-tk/test/test_tkinter/test_font.py
+2
-2
Lib/lib-tk/test/test_tkinter/test_geometry_managers.py
Lib/lib-tk/test/test_tkinter/test_geometry_managers.py
+45
-45
Lib/lib-tk/test/test_tkinter/test_text.py
Lib/lib-tk/test/test_tkinter/test_text.py
+6
-6
Lib/lib-tk/test/test_tkinter/test_widgets.py
Lib/lib-tk/test/test_tkinter/test_widgets.py
+38
-38
Lib/lib-tk/test/test_ttk/support.py
Lib/lib-tk/test/test_ttk/support.py
+6
-6
Lib/lib-tk/test/test_ttk/test_extensions.py
Lib/lib-tk/test/test_ttk/test_extensions.py
+15
-15
Lib/lib-tk/test/test_ttk/test_style.py
Lib/lib-tk/test/test_ttk/test_style.py
+4
-4
Lib/lib-tk/test/test_ttk/test_widgets.py
Lib/lib-tk/test/test_ttk/test_widgets.py
+90
-90
Lib/lib-tk/test/widget_tests.py
Lib/lib-tk/test/widget_tests.py
+8
-8
No files found.
Lib/lib-tk/test/test_tkinter/test_font.py
View file @
95cf9862
import
unittest
import
Tkinter
import
Tkinter
as
tkinter
#from Tkinter
import
tkFont
as
font
from
test.test_support
import
requires
,
run_unittest
...
...
@@ -19,7 +19,7 @@ class FontTest(unittest.TestCase):
fontname
=
"TkDefaultFont"
try
:
f
=
font
.
Font
(
name
=
fontname
,
exists
=
True
)
except
T
kinter
.
_tkinter
.
TclError
:
except
t
kinter
.
_tkinter
.
TclError
:
f
=
font
.
Font
(
name
=
fontname
,
exists
=
False
)
font1
=
font
.
nametofont
(
fontname
)
font2
=
font
.
nametofont
(
fontname
)
...
...
Lib/lib-tk/test/test_tkinter/test_geometry_managers.py
View file @
95cf9862
import
unittest
import
re
import
Tkinter
import
Tkinter
as
tkinter
from
Tkinter
import
TclError
from
test.test_support
import
requires
,
run_unittest
...
...
@@ -13,13 +13,13 @@ requires('gui')
class
PackTest
(
AbstractWidgetTest
,
unittest
.
TestCase
):
def
create2
(
self
):
pack
=
T
kinter
.
Toplevel
(
self
.
root
,
name
=
'pack'
)
pack
=
t
kinter
.
Toplevel
(
self
.
root
,
name
=
'pack'
)
pack
.
wm_geometry
(
'300x200+0+0'
)
pack
.
wm_minsize
(
1
,
1
)
a
=
T
kinter
.
Frame
(
pack
,
name
=
'a'
,
width
=
20
,
height
=
40
,
bg
=
'red'
)
b
=
T
kinter
.
Frame
(
pack
,
name
=
'b'
,
width
=
50
,
height
=
30
,
bg
=
'blue'
)
c
=
T
kinter
.
Frame
(
pack
,
name
=
'c'
,
width
=
80
,
height
=
80
,
bg
=
'green'
)
d
=
T
kinter
.
Frame
(
pack
,
name
=
'd'
,
width
=
40
,
height
=
30
,
bg
=
'yellow'
)
a
=
t
kinter
.
Frame
(
pack
,
name
=
'a'
,
width
=
20
,
height
=
40
,
bg
=
'red'
)
b
=
t
kinter
.
Frame
(
pack
,
name
=
'b'
,
width
=
50
,
height
=
30
,
bg
=
'blue'
)
c
=
t
kinter
.
Frame
(
pack
,
name
=
'c'
,
width
=
80
,
height
=
80
,
bg
=
'green'
)
d
=
t
kinter
.
Frame
(
pack
,
name
=
'd'
,
width
=
40
,
height
=
30
,
bg
=
'yellow'
)
return
pack
,
a
,
b
,
c
,
d
def
test_pack_configure_after
(
self
):
...
...
@@ -277,11 +277,11 @@ class PackTest(AbstractWidgetTest, unittest.TestCase):
class
PlaceTest
(
AbstractWidgetTest
,
unittest
.
TestCase
):
def
create2
(
self
):
t
=
T
kinter
.
Toplevel
(
self
.
root
,
width
=
300
,
height
=
200
,
bd
=
0
)
t
=
t
kinter
.
Toplevel
(
self
.
root
,
width
=
300
,
height
=
200
,
bd
=
0
)
t
.
wm_geometry
(
'+0+0'
)
f
=
T
kinter
.
Frame
(
t
,
width
=
154
,
height
=
84
,
bd
=
2
,
relief
=
'raised'
)
f
=
t
kinter
.
Frame
(
t
,
width
=
154
,
height
=
84
,
bd
=
2
,
relief
=
'raised'
)
f
.
place_configure
(
x
=
48
,
y
=
38
)
f2
=
T
kinter
.
Frame
(
t
,
width
=
30
,
height
=
60
,
bd
=
2
,
relief
=
'raised'
)
f2
=
t
kinter
.
Frame
(
t
,
width
=
30
,
height
=
60
,
bd
=
2
,
relief
=
'raised'
)
self
.
root
.
update
()
return
t
,
f
,
f2
...
...
@@ -369,7 +369,7 @@ class PlaceTest(AbstractWidgetTest, unittest.TestCase):
f2
.
place_configure
(
in_
=
f
,
rely
=
'spam'
)
def
test_place_configure_anchor
(
self
):
f
=
T
kinter
.
Frame
(
self
.
root
)
f
=
t
kinter
.
Frame
(
self
.
root
)
with
self
.
assertRaisesRegexp
(
TclError
,
'bad anchor "j"'
):
f
.
place_configure
(
anchor
=
'j'
)
with
self
.
assertRaisesRegexp
(
TclError
,
'ambiguous anchor ""'
):
...
...
@@ -425,7 +425,7 @@ class PlaceTest(AbstractWidgetTest, unittest.TestCase):
f2
.
place_configure
(
relheight
=
'abcd'
)
def
test_place_configure_bordermode
(
self
):
f
=
T
kinter
.
Frame
(
self
.
root
)
f
=
t
kinter
.
Frame
(
self
.
root
)
with
self
.
assertRaisesRegexp
(
TclError
,
'bad bordermode "j"'
):
f
.
place_configure
(
bordermode
=
'j'
)
with
self
.
assertRaisesRegexp
(
TclError
,
'ambiguous bordermode ""'
):
...
...
@@ -435,7 +435,7 @@ class PlaceTest(AbstractWidgetTest, unittest.TestCase):
self
.
assertEqual
(
f
.
place_info
()[
'bordermode'
],
value
)
def
test_place_forget
(
self
):
foo
=
T
kinter
.
Frame
(
self
.
root
)
foo
=
t
kinter
.
Frame
(
self
.
root
)
foo
.
place_configure
(
width
=
50
,
height
=
50
)
self
.
root
.
update
()
foo
.
place_forget
()
...
...
@@ -467,8 +467,8 @@ class PlaceTest(AbstractWidgetTest, unittest.TestCase):
f2
.
place_info
(
0
)
def
test_place_slaves
(
self
):
foo
=
T
kinter
.
Frame
(
self
.
root
)
bar
=
T
kinter
.
Frame
(
self
.
root
)
foo
=
t
kinter
.
Frame
(
self
.
root
)
bar
=
t
kinter
.
Frame
(
self
.
root
)
self
.
assertEqual
(
foo
.
place_slaves
(),
[])
bar
.
place_configure
(
in_
=
foo
)
self
.
assertEqual
(
foo
.
place_slaves
(),
[
bar
])
...
...
@@ -488,7 +488,7 @@ class GridTest(AbstractWidgetTest, unittest.TestCase):
self
.
root
.
grid_propagate
(
1
)
def
test_grid_configure
(
self
):
b
=
T
kinter
.
Button
(
self
.
root
)
b
=
t
kinter
.
Button
(
self
.
root
)
self
.
addCleanup
(
b
.
destroy
)
self
.
assertEqual
(
b
.
grid_info
(),
{})
b
.
grid_configure
()
...
...
@@ -500,7 +500,7 @@ class GridTest(AbstractWidgetTest, unittest.TestCase):
self
.
assertEqual
(
b
.
grid_info
()[
'row'
],
self
.
_str
(
2
))
def
test_grid_configure_column
(
self
):
b
=
T
kinter
.
Button
(
self
.
root
)
b
=
t
kinter
.
Button
(
self
.
root
)
with
self
.
assertRaisesRegexp
(
TclError
,
'bad column value "-1": '
'must be a non-negative integer'
):
b
.
grid_configure
(
column
=-
1
)
...
...
@@ -508,7 +508,7 @@ class GridTest(AbstractWidgetTest, unittest.TestCase):
self
.
assertEqual
(
b
.
grid_info
()[
'column'
],
self
.
_str
(
2
))
def
test_grid_configure_columnspan
(
self
):
b
=
T
kinter
.
Button
(
self
.
root
)
b
=
t
kinter
.
Button
(
self
.
root
)
with
self
.
assertRaisesRegexp
(
TclError
,
'bad columnspan value "0": '
'must be a positive integer'
):
b
.
grid_configure
(
columnspan
=
0
)
...
...
@@ -516,8 +516,8 @@ class GridTest(AbstractWidgetTest, unittest.TestCase):
self
.
assertEqual
(
b
.
grid_info
()[
'columnspan'
],
self
.
_str
(
2
))
def
test_grid_configure_in
(
self
):
f
=
T
kinter
.
Frame
(
self
.
root
)
b
=
T
kinter
.
Button
(
self
.
root
)
f
=
t
kinter
.
Frame
(
self
.
root
)
b
=
t
kinter
.
Button
(
self
.
root
)
self
.
assertEqual
(
b
.
grid_info
(),
{})
b
.
grid_configure
()
self
.
assertEqual
(
b
.
grid_info
()[
'in'
],
self
.
root
)
...
...
@@ -527,7 +527,7 @@ class GridTest(AbstractWidgetTest, unittest.TestCase):
self
.
assertEqual
(
b
.
grid_info
()[
'in'
],
self
.
root
)
def
test_grid_configure_ipadx
(
self
):
b
=
T
kinter
.
Button
(
self
.
root
)
b
=
t
kinter
.
Button
(
self
.
root
)
with
self
.
assertRaisesRegexp
(
TclError
,
'bad ipadx value "-1": '
'must be positive screen distance'
):
b
.
grid_configure
(
ipadx
=-
1
)
...
...
@@ -538,7 +538,7 @@ class GridTest(AbstractWidgetTest, unittest.TestCase):
self
.
_str
(
int_round
(
pixels_conv
(
'.5c'
)
*
self
.
scaling
)))
def
test_grid_configure_ipady
(
self
):
b
=
T
kinter
.
Button
(
self
.
root
)
b
=
t
kinter
.
Button
(
self
.
root
)
with
self
.
assertRaisesRegexp
(
TclError
,
'bad ipady value "-1": '
'must be positive screen distance'
):
b
.
grid_configure
(
ipady
=-
1
)
...
...
@@ -549,7 +549,7 @@ class GridTest(AbstractWidgetTest, unittest.TestCase):
self
.
_str
(
int_round
(
pixels_conv
(
'.5c'
)
*
self
.
scaling
)))
def
test_grid_configure_padx
(
self
):
b
=
T
kinter
.
Button
(
self
.
root
)
b
=
t
kinter
.
Button
(
self
.
root
)
with
self
.
assertRaisesRegexp
(
TclError
,
'bad pad value "-1": '
'must be positive screen distance'
):
b
.
grid_configure
(
padx
=-
1
)
...
...
@@ -562,7 +562,7 @@ class GridTest(AbstractWidgetTest, unittest.TestCase):
self
.
_str
(
int_round
(
pixels_conv
(
'.5c'
)
*
self
.
scaling
)))
def
test_grid_configure_pady
(
self
):
b
=
T
kinter
.
Button
(
self
.
root
)
b
=
t
kinter
.
Button
(
self
.
root
)
with
self
.
assertRaisesRegexp
(
TclError
,
'bad pad value "-1": '
'must be positive screen distance'
):
b
.
grid_configure
(
pady
=-
1
)
...
...
@@ -575,7 +575,7 @@ class GridTest(AbstractWidgetTest, unittest.TestCase):
self
.
_str
(
int_round
(
pixels_conv
(
'.5c'
)
*
self
.
scaling
)))
def
test_grid_configure_row
(
self
):
b
=
T
kinter
.
Button
(
self
.
root
)
b
=
t
kinter
.
Button
(
self
.
root
)
self
.
addCleanup
(
b
.
destroy
)
with
self
.
assertRaisesRegexp
(
TclError
,
'bad (row|grid) value "-1": '
'must be a non-negative integer'
):
...
...
@@ -584,7 +584,7 @@ class GridTest(AbstractWidgetTest, unittest.TestCase):
self
.
assertEqual
(
b
.
grid_info
()[
'row'
],
self
.
_str
(
2
))
def
test_grid_configure_rownspan
(
self
):
b
=
T
kinter
.
Button
(
self
.
root
)
b
=
t
kinter
.
Button
(
self
.
root
)
with
self
.
assertRaisesRegexp
(
TclError
,
'bad rowspan value "0": '
'must be a positive integer'
):
b
.
grid_configure
(
rowspan
=
0
)
...
...
@@ -592,7 +592,7 @@ class GridTest(AbstractWidgetTest, unittest.TestCase):
self
.
assertEqual
(
b
.
grid_info
()[
'rowspan'
],
self
.
_str
(
2
))
def
test_grid_configure_sticky
(
self
):
f
=
T
kinter
.
Frame
(
self
.
root
,
bg
=
'red'
)
f
=
t
kinter
.
Frame
(
self
.
root
,
bg
=
'red'
)
with
self
.
assertRaisesRegexp
(
TclError
,
'bad stickyness value "glue"'
):
f
.
grid_configure
(
sticky
=
'glue'
)
f
.
grid_configure
(
sticky
=
'ne'
)
...
...
@@ -611,7 +611,7 @@ class GridTest(AbstractWidgetTest, unittest.TestCase):
with
self
.
assertRaisesRegexp
(
TclError
,
'must specify a single element on retrieval'
):
self
.
root
.
grid_columnconfigure
((
0
,
3
))
b
=
T
kinter
.
Button
(
self
.
root
)
b
=
t
kinter
.
Button
(
self
.
root
)
b
.
grid_configure
(
column
=
0
,
row
=
0
)
if
tcl_version
>=
(
8
,
5
):
self
.
root
.
grid_columnconfigure
(
'all'
,
weight
=
3
)
...
...
@@ -667,7 +667,7 @@ class GridTest(AbstractWidgetTest, unittest.TestCase):
with
self
.
assertRaisesRegexp
(
TclError
,
'must specify a single element on retrieval'
):
self
.
root
.
grid_rowconfigure
((
0
,
3
))
b
=
T
kinter
.
Button
(
self
.
root
)
b
=
t
kinter
.
Button
(
self
.
root
)
b
.
grid_configure
(
column
=
0
,
row
=
0
)
if
tcl_version
>=
(
8
,
5
):
self
.
root
.
grid_rowconfigure
(
'all'
,
weight
=
3
)
...
...
@@ -713,8 +713,8 @@ class GridTest(AbstractWidgetTest, unittest.TestCase):
self
.
assertEqual
(
self
.
root
.
grid_rowconfigure
(
0
)[
'uniform'
],
'foo'
)
def
test_grid_forget
(
self
):
b
=
T
kinter
.
Button
(
self
.
root
)
c
=
T
kinter
.
Button
(
self
.
root
)
b
=
t
kinter
.
Button
(
self
.
root
)
c
=
t
kinter
.
Button
(
self
.
root
)
b
.
grid_configure
(
row
=
2
,
column
=
2
,
rowspan
=
2
,
columnspan
=
2
,
padx
=
3
,
pady
=
4
,
sticky
=
'ns'
)
self
.
assertEqual
(
self
.
root
.
grid_slaves
(),
[
b
])
...
...
@@ -733,8 +733,8 @@ class GridTest(AbstractWidgetTest, unittest.TestCase):
self
.
assertEqual
(
info
[
'sticky'
],
''
)
def
test_grid_remove
(
self
):
b
=
T
kinter
.
Button
(
self
.
root
)
c
=
T
kinter
.
Button
(
self
.
root
)
b
=
t
kinter
.
Button
(
self
.
root
)
c
=
t
kinter
.
Button
(
self
.
root
)
b
.
grid_configure
(
row
=
2
,
column
=
2
,
rowspan
=
2
,
columnspan
=
2
,
padx
=
3
,
pady
=
4
,
sticky
=
'ns'
)
self
.
assertEqual
(
self
.
root
.
grid_slaves
(),
[
b
])
...
...
@@ -753,7 +753,7 @@ class GridTest(AbstractWidgetTest, unittest.TestCase):
self
.
assertEqual
(
info
[
'sticky'
],
'ns'
)
def
test_grid_info
(
self
):
b
=
T
kinter
.
Button
(
self
.
root
)
b
=
t
kinter
.
Button
(
self
.
root
)
self
.
assertEqual
(
b
.
grid_info
(),
{})
b
.
grid_configure
(
row
=
2
,
column
=
2
,
rowspan
=
2
,
columnspan
=
2
,
padx
=
3
,
pady
=
4
,
sticky
=
'ns'
)
...
...
@@ -782,12 +782,12 @@ class GridTest(AbstractWidgetTest, unittest.TestCase):
self
.
root
.
grid_bbox
(
0
,
0
,
0
,
'x'
)
with
self
.
assertRaises
(
TypeError
):
self
.
root
.
grid_bbox
(
0
,
0
,
0
,
0
,
0
)
t
=
T
kinter
.
Toplevel
(
self
.
root
)
t
=
t
kinter
.
Toplevel
(
self
.
root
)
# de-maximize
t
.
wm_geometry
(
'1x1+0+0'
)
t
.
wm_geometry
(
''
)
f1
=
T
kinter
.
Frame
(
t
,
width
=
75
,
height
=
75
,
bg
=
'red'
)
f2
=
T
kinter
.
Frame
(
t
,
width
=
90
,
height
=
90
,
bg
=
'blue'
)
f1
=
t
kinter
.
Frame
(
t
,
width
=
75
,
height
=
75
,
bg
=
'red'
)
f2
=
t
kinter
.
Frame
(
t
,
width
=
90
,
height
=
90
,
bg
=
'blue'
)
f1
.
grid_configure
(
row
=
0
,
column
=
0
)
f2
.
grid_configure
(
row
=
1
,
column
=
1
)
self
.
root
.
update
()
...
...
@@ -810,11 +810,11 @@ class GridTest(AbstractWidgetTest, unittest.TestCase):
self
.
root
.
grid_location
(
'x'
,
'y'
)
with
self
.
assertRaisesRegexp
(
TclError
,
'bad screen distance "y"'
):
self
.
root
.
grid_location
(
'1c'
,
'y'
)
t
=
T
kinter
.
Toplevel
(
self
.
root
)
t
=
t
kinter
.
Toplevel
(
self
.
root
)
# de-maximize
t
.
wm_geometry
(
'1x1+0+0'
)
t
.
wm_geometry
(
''
)
f
=
T
kinter
.
Frame
(
t
,
width
=
200
,
height
=
100
,
f
=
t
kinter
.
Frame
(
t
,
width
=
200
,
height
=
100
,
highlightthickness
=
0
,
bg
=
'red'
)
self
.
assertEqual
(
f
.
grid_location
(
10
,
10
),
(
-
1
,
-
1
))
f
.
grid_configure
()
...
...
@@ -837,13 +837,13 @@ class GridTest(AbstractWidgetTest, unittest.TestCase):
self
.
root
.
grid_propagate
(
False
,
False
)
self
.
root
.
grid_propagate
(
False
)
self
.
assertFalse
(
self
.
root
.
grid_propagate
())
f
=
T
kinter
.
Frame
(
self
.
root
,
width
=
100
,
height
=
100
,
bg
=
'red'
)
f
=
t
kinter
.
Frame
(
self
.
root
,
width
=
100
,
height
=
100
,
bg
=
'red'
)
f
.
grid_configure
(
row
=
0
,
column
=
0
)
self
.
root
.
update
()
self
.
assertEqual
(
f
.
winfo_width
(),
100
)
self
.
assertEqual
(
f
.
winfo_height
(),
100
)
f
.
grid_propagate
(
False
)
g
=
T
kinter
.
Frame
(
self
.
root
,
width
=
75
,
height
=
85
,
bg
=
'green'
)
g
=
t
kinter
.
Frame
(
self
.
root
,
width
=
75
,
height
=
85
,
bg
=
'green'
)
g
.
grid_configure
(
in_
=
f
,
row
=
0
,
column
=
0
)
self
.
root
.
update
()
self
.
assertEqual
(
f
.
winfo_width
(),
100
)
...
...
@@ -857,7 +857,7 @@ class GridTest(AbstractWidgetTest, unittest.TestCase):
with
self
.
assertRaises
(
TypeError
):
self
.
root
.
grid_size
(
0
)
self
.
assertEqual
(
self
.
root
.
grid_size
(),
(
0
,
0
))
f
=
T
kinter
.
Scale
(
self
.
root
)
f
=
t
kinter
.
Scale
(
self
.
root
)
f
.
grid_configure
(
row
=
0
,
column
=
0
)
self
.
assertEqual
(
self
.
root
.
grid_size
(),
(
1
,
1
))
f
.
grid_configure
(
row
=
4
,
column
=
5
)
...
...
@@ -865,13 +865,13 @@ class GridTest(AbstractWidgetTest, unittest.TestCase):
def
test_grid_slaves
(
self
):
self
.
assertEqual
(
self
.
root
.
grid_slaves
(),
[])
a
=
T
kinter
.
Label
(
self
.
root
)
a
=
t
kinter
.
Label
(
self
.
root
)
a
.
grid_configure
(
row
=
0
,
column
=
1
)
b
=
T
kinter
.
Label
(
self
.
root
)
b
=
t
kinter
.
Label
(
self
.
root
)
b
.
grid_configure
(
row
=
1
,
column
=
0
)
c
=
T
kinter
.
Label
(
self
.
root
)
c
=
t
kinter
.
Label
(
self
.
root
)
c
.
grid_configure
(
row
=
1
,
column
=
1
)
d
=
T
kinter
.
Label
(
self
.
root
)
d
=
t
kinter
.
Label
(
self
.
root
)
d
.
grid_configure
(
row
=
1
,
column
=
1
)
self
.
assertEqual
(
self
.
root
.
grid_slaves
(),
[
d
,
c
,
b
,
a
])
self
.
assertEqual
(
self
.
root
.
grid_slaves
(
row
=
0
),
[
a
])
...
...
Lib/lib-tk/test/test_tkinter/test_text.py
View file @
95cf9862
import
unittest
import
Tkinter
import
Tkinter
as
tkinter
from
test.test_support
import
requires
,
run_unittest
from
ttk
import
setup_master
...
...
@@ -9,7 +9,7 @@ class TextTest(unittest.TestCase):
def
setUp
(
self
):
self
.
root
=
setup_master
()
self
.
text
=
T
kinter
.
Text
(
self
.
root
)
self
.
text
=
t
kinter
.
Text
(
self
.
root
)
def
tearDown
(
self
):
self
.
text
.
destroy
()
...
...
@@ -30,12 +30,12 @@ class TextTest(unittest.TestCase):
text
=
self
.
text
# pattern and index are obligatory arguments.
self
.
assertRaises
(
T
kinter
.
TclError
,
text
.
search
,
None
,
'1.0'
)
self
.
assertRaises
(
T
kinter
.
TclError
,
text
.
search
,
'a'
,
None
)
self
.
assertRaises
(
T
kinter
.
TclError
,
text
.
search
,
None
,
None
)
self
.
assertRaises
(
t
kinter
.
TclError
,
text
.
search
,
None
,
'1.0'
)
self
.
assertRaises
(
t
kinter
.
TclError
,
text
.
search
,
'a'
,
None
)
self
.
assertRaises
(
t
kinter
.
TclError
,
text
.
search
,
None
,
None
)
# Invalid text index.
self
.
assertRaises
(
T
kinter
.
TclError
,
text
.
search
,
''
,
0
)
self
.
assertRaises
(
t
kinter
.
TclError
,
text
.
search
,
''
,
0
)
# Check if we are getting the indices as strings -- you are likely
# to get Tcl_Obj under Tk 8.5 if Tkinter doesn't convert it.
...
...
Lib/lib-tk/test/test_tkinter/test_widgets.py
View file @
95cf9862
import
unittest
import
Tkinter
import
Tkinter
as
tkinter
from
Tkinter
import
TclError
import
os
import
sys
...
...
@@ -64,11 +64,11 @@ class ToplevelTest(AbstractToplevelTest, unittest.TestCase):
)
def
_create
(
self
,
**
kwargs
):
return
T
kinter
.
Toplevel
(
self
.
root
,
**
kwargs
)
return
t
kinter
.
Toplevel
(
self
.
root
,
**
kwargs
)
def
test_menu
(
self
):
widget
=
self
.
create
()
menu
=
T
kinter
.
Menu
(
self
.
root
)
menu
=
t
kinter
.
Menu
(
self
.
root
)
self
.
checkParam
(
widget
,
'menu'
,
menu
,
eq
=
widget_eq
)
self
.
checkParam
(
widget
,
'menu'
,
''
)
...
...
@@ -103,7 +103,7 @@ class FrameTest(AbstractToplevelTest, unittest.TestCase):
)
def
_create
(
self
,
**
kwargs
):
return
T
kinter
.
Frame
(
self
.
root
,
**
kwargs
)
return
t
kinter
.
Frame
(
self
.
root
,
**
kwargs
)
@
add_standard_options
(
StandardOptionsTests
)
...
...
@@ -118,7 +118,7 @@ class LabelFrameTest(AbstractToplevelTest, unittest.TestCase):
)
def
_create
(
self
,
**
kwargs
):
return
T
kinter
.
LabelFrame
(
self
.
root
,
**
kwargs
)
return
t
kinter
.
LabelFrame
(
self
.
root
,
**
kwargs
)
def
test_labelanchor
(
self
):
widget
=
self
.
create
()
...
...
@@ -129,7 +129,7 @@ class LabelFrameTest(AbstractToplevelTest, unittest.TestCase):
def
test_labelwidget
(
self
):
widget
=
self
.
create
()
label
=
T
kinter
.
Label
(
self
.
root
,
text
=
'Mupp'
,
name
=
'foo'
)
label
=
t
kinter
.
Label
(
self
.
root
,
text
=
'Mupp'
,
name
=
'foo'
)
self
.
checkParam
(
widget
,
'labelwidget'
,
label
,
expected
=
'.foo'
)
label
.
destroy
()
...
...
@@ -156,7 +156,7 @@ class LabelTest(AbstractLabelTest, unittest.TestCase):
)
def
_create
(
self
,
**
kwargs
):
return
T
kinter
.
Label
(
self
.
root
,
**
kwargs
)
return
t
kinter
.
Label
(
self
.
root
,
**
kwargs
)
@
add_standard_options
(
StandardOptionsTests
)
...
...
@@ -173,7 +173,7 @@ class ButtonTest(AbstractLabelTest, unittest.TestCase):
'underline'
,
'width'
,
'wraplength'
)
def
_create
(
self
,
**
kwargs
):
return
T
kinter
.
Button
(
self
.
root
,
**
kwargs
)
return
t
kinter
.
Button
(
self
.
root
,
**
kwargs
)
def
test_default
(
self
):
widget
=
self
.
create
()
...
...
@@ -197,7 +197,7 @@ class CheckbuttonTest(AbstractLabelTest, unittest.TestCase):
)
def
_create
(
self
,
**
kwargs
):
return
T
kinter
.
Checkbutton
(
self
.
root
,
**
kwargs
)
return
t
kinter
.
Checkbutton
(
self
.
root
,
**
kwargs
)
def
test_offvalue
(
self
):
...
...
@@ -225,7 +225,7 @@ class RadiobuttonTest(AbstractLabelTest, unittest.TestCase):
)
def
_create
(
self
,
**
kwargs
):
return
T
kinter
.
Radiobutton
(
self
.
root
,
**
kwargs
)
return
t
kinter
.
Radiobutton
(
self
.
root
,
**
kwargs
)
def
test_value
(
self
):
widget
=
self
.
create
()
...
...
@@ -248,7 +248,7 @@ class MenubuttonTest(AbstractLabelTest, unittest.TestCase):
_conv_pixels
=
staticmethod
(
pixels_round
)
def
_create
(
self
,
**
kwargs
):
return
T
kinter
.
Menubutton
(
self
.
root
,
**
kwargs
)
return
t
kinter
.
Menubutton
(
self
.
root
,
**
kwargs
)
def
test_direction
(
self
):
widget
=
self
.
create
()
...
...
@@ -265,21 +265,21 @@ class MenubuttonTest(AbstractLabelTest, unittest.TestCase):
'crashes with Cocoa Tk (issue19733)'
)
def
test_image
(
self
):
widget
=
self
.
create
()
image
=
T
kinter
.
PhotoImage
(
'image1'
)
image
=
t
kinter
.
PhotoImage
(
'image1'
)
self
.
checkParam
(
widget
,
'image'
,
image
,
conv
=
str
)
errmsg
=
'image "spam" doesn
\
'
t exist'
with
self
.
assertRaises
(
T
kinter
.
TclError
)
as
cm
:
with
self
.
assertRaises
(
t
kinter
.
TclError
)
as
cm
:
widget
[
'image'
]
=
'spam'
if
errmsg
is
not
None
:
self
.
assertEqual
(
str
(
cm
.
exception
),
errmsg
)
with
self
.
assertRaises
(
T
kinter
.
TclError
)
as
cm
:
with
self
.
assertRaises
(
t
kinter
.
TclError
)
as
cm
:
widget
.
configure
({
'image'
:
'spam'
})
if
errmsg
is
not
None
:
self
.
assertEqual
(
str
(
cm
.
exception
),
errmsg
)
def
test_menu
(
self
):
widget
=
self
.
create
()
menu
=
T
kinter
.
Menu
(
widget
,
name
=
'menu'
)
menu
=
t
kinter
.
Menu
(
widget
,
name
=
'menu'
)
self
.
checkParam
(
widget
,
'menu'
,
menu
,
eq
=
widget_eq
)
menu
.
destroy
()
...
...
@@ -301,7 +301,7 @@ class MenubuttonTest(AbstractLabelTest, unittest.TestCase):
class
OptionMenuTest
(
MenubuttonTest
,
unittest
.
TestCase
):
def
_create
(
self
,
default
=
'b'
,
values
=
(
'a'
,
'b'
,
'c'
),
**
kwargs
):
return
T
kinter
.
OptionMenu
(
self
.
root
,
None
,
default
,
*
values
,
**
kwargs
)
return
t
kinter
.
OptionMenu
(
self
.
root
,
None
,
default
,
*
values
,
**
kwargs
)
@
add_standard_options
(
IntegerSizeTests
,
StandardOptionsTests
)
...
...
@@ -320,7 +320,7 @@ class EntryTest(AbstractWidgetTest, unittest.TestCase):
)
def
_create
(
self
,
**
kwargs
):
return
T
kinter
.
Entry
(
self
.
root
,
**
kwargs
)
return
t
kinter
.
Entry
(
self
.
root
,
**
kwargs
)
def
test_disabledbackground
(
self
):
widget
=
self
.
create
()
...
...
@@ -394,7 +394,7 @@ class SpinboxTest(EntryTest, unittest.TestCase):
)
def
_create
(
self
,
**
kwargs
):
return
T
kinter
.
Spinbox
(
self
.
root
,
**
kwargs
)
return
t
kinter
.
Spinbox
(
self
.
root
,
**
kwargs
)
test_show
=
None
...
...
@@ -465,8 +465,8 @@ class SpinboxTest(EntryTest, unittest.TestCase):
def
test_bbox
(
self
):
widget
=
self
.
create
()
self
.
assertIsBoundingBox
(
widget
.
bbox
(
0
))
self
.
assertRaises
(
T
kinter
.
TclError
,
widget
.
bbox
,
'noindex'
)
self
.
assertRaises
(
T
kinter
.
TclError
,
widget
.
bbox
,
None
)
self
.
assertRaises
(
t
kinter
.
TclError
,
widget
.
bbox
,
'noindex'
)
self
.
assertRaises
(
t
kinter
.
TclError
,
widget
.
bbox
,
None
)
self
.
assertRaises
(
TypeError
,
widget
.
bbox
)
self
.
assertRaises
(
TypeError
,
widget
.
bbox
,
0
,
1
)
...
...
@@ -490,7 +490,7 @@ class TextTest(AbstractWidgetTest, unittest.TestCase):
wantobjects
=
False
def
_create
(
self
,
**
kwargs
):
return
T
kinter
.
Text
(
self
.
root
,
**
kwargs
)
return
t
kinter
.
Text
(
self
.
root
,
**
kwargs
)
def
test_autoseparators
(
self
):
widget
=
self
.
create
()
...
...
@@ -619,10 +619,10 @@ class TextTest(AbstractWidgetTest, unittest.TestCase):
widget
=
self
.
create
()
self
.
assertIsBoundingBox
(
widget
.
bbox
(
'1.1'
))
self
.
assertIsNone
(
widget
.
bbox
(
'end'
))
self
.
assertRaises
(
T
kinter
.
TclError
,
widget
.
bbox
,
'noindex'
)
self
.
assertRaises
(
T
kinter
.
TclError
,
widget
.
bbox
,
None
)
self
.
assertRaises
(
T
kinter
.
TclError
,
widget
.
bbox
)
self
.
assertRaises
(
T
kinter
.
TclError
,
widget
.
bbox
,
'1.1'
,
'end'
)
self
.
assertRaises
(
t
kinter
.
TclError
,
widget
.
bbox
,
'noindex'
)
self
.
assertRaises
(
t
kinter
.
TclError
,
widget
.
bbox
,
None
)
self
.
assertRaises
(
t
kinter
.
TclError
,
widget
.
bbox
)
self
.
assertRaises
(
t
kinter
.
TclError
,
widget
.
bbox
,
'1.1'
,
'end'
)
@
add_standard_options
(
PixelSizeTests
,
StandardOptionsTests
)
...
...
@@ -644,7 +644,7 @@ class CanvasTest(AbstractWidgetTest, unittest.TestCase):
wantobjects
=
False
def
_create
(
self
,
**
kwargs
):
return
T
kinter
.
Canvas
(
self
.
root
,
**
kwargs
)
return
t
kinter
.
Canvas
(
self
.
root
,
**
kwargs
)
def
test_closeenough
(
self
):
widget
=
self
.
create
()
...
...
@@ -697,7 +697,7 @@ class ListboxTest(AbstractWidgetTest, unittest.TestCase):
)
def
_create
(
self
,
**
kwargs
):
return
T
kinter
.
Listbox
(
self
.
root
,
**
kwargs
)
return
t
kinter
.
Listbox
(
self
.
root
,
**
kwargs
)
def
test_activestyle
(
self
):
widget
=
self
.
create
()
...
...
@@ -706,7 +706,7 @@ class ListboxTest(AbstractWidgetTest, unittest.TestCase):
def
test_listvariable
(
self
):
widget
=
self
.
create
()
var
=
T
kinter
.
DoubleVar
()
var
=
t
kinter
.
DoubleVar
()
self
.
checkVariableParam
(
widget
,
'listvariable'
,
var
)
def
test_selectmode
(
self
):
...
...
@@ -789,7 +789,7 @@ class ListboxTest(AbstractWidgetTest, unittest.TestCase):
def
test_curselection
(
self
):
lb
=
self
.
create
()
lb
.
insert
(
0
,
*
(
'el%d'
%
i
for
i
in
range
(
8
)))
lb
.
selection_clear
(
0
,
T
kinter
.
END
)
lb
.
selection_clear
(
0
,
t
kinter
.
END
)
lb
.
selection_set
(
2
,
4
)
lb
.
selection_set
(
6
)
self
.
assertEqual
(
lb
.
curselection
(),
(
2
,
3
,
4
,
6
))
...
...
@@ -829,7 +829,7 @@ class ScaleTest(AbstractWidgetTest, unittest.TestCase):
default_orient
=
'vertical'
def
_create
(
self
,
**
kwargs
):
return
T
kinter
.
Scale
(
self
.
root
,
**
kwargs
)
return
t
kinter
.
Scale
(
self
.
root
,
**
kwargs
)
def
test_bigincrement
(
self
):
widget
=
self
.
create
()
...
...
@@ -898,7 +898,7 @@ class ScrollbarTest(AbstractWidgetTest, unittest.TestCase):
default_orient
=
'vertical'
def
_create
(
self
,
**
kwargs
):
return
T
kinter
.
Scrollbar
(
self
.
root
,
**
kwargs
)
return
t
kinter
.
Scrollbar
(
self
.
root
,
**
kwargs
)
def
test_activerelief
(
self
):
widget
=
self
.
create
()
...
...
@@ -944,7 +944,7 @@ class PanedWindowTest(AbstractWidgetTest, unittest.TestCase):
default_orient
=
'horizontal'
def
_create
(
self
,
**
kwargs
):
return
T
kinter
.
PanedWindow
(
self
.
root
,
**
kwargs
)
return
t
kinter
.
PanedWindow
(
self
.
root
,
**
kwargs
)
def
test_handlepad
(
self
):
widget
=
self
.
create
()
...
...
@@ -992,8 +992,8 @@ class PanedWindowTest(AbstractWidgetTest, unittest.TestCase):
def
create2
(
self
):
p
=
self
.
create
()
b
=
T
kinter
.
Button
(
p
)
c
=
T
kinter
.
Button
(
p
)
b
=
t
kinter
.
Button
(
p
)
c
=
t
kinter
.
Button
(
p
)
p
.
add
(
b
)
p
.
add
(
c
)
return
p
,
b
,
c
...
...
@@ -1102,7 +1102,7 @@ class MenuTest(AbstractWidgetTest, unittest.TestCase):
_conv_pixels
=
noconv_meth
def
_create
(
self
,
**
kwargs
):
return
T
kinter
.
Menu
(
self
.
root
,
**
kwargs
)
return
t
kinter
.
Menu
(
self
.
root
,
**
kwargs
)
def
test_postcommand
(
self
):
widget
=
self
.
create
()
...
...
@@ -1150,8 +1150,8 @@ class MenuTest(AbstractWidgetTest, unittest.TestCase):
def
test_entryconfigure_variable
(
self
):
m1
=
self
.
create
()
v1
=
T
kinter
.
BooleanVar
(
self
.
root
)
v2
=
T
kinter
.
BooleanVar
(
self
.
root
)
v1
=
t
kinter
.
BooleanVar
(
self
.
root
)
v2
=
t
kinter
.
BooleanVar
(
self
.
root
)
m1
.
add_checkbutton
(
variable
=
v1
,
onvalue
=
True
,
offvalue
=
False
,
label
=
'Nonsense'
)
self
.
assertEqual
(
str
(
m1
.
entrycget
(
1
,
'variable'
)),
str
(
v1
))
...
...
@@ -1171,7 +1171,7 @@ class MessageTest(AbstractWidgetTest, unittest.TestCase):
_conv_pad_pixels
=
noconv_meth
def
_create
(
self
,
**
kwargs
):
return
T
kinter
.
Message
(
self
.
root
,
**
kwargs
)
return
t
kinter
.
Message
(
self
.
root
,
**
kwargs
)
def
test_aspect
(
self
):
widget
=
self
.
create
()
...
...
Lib/lib-tk/test/test_ttk/support.py
View file @
95cf9862
import
unittest
import
Tkinter
import
Tkinter
as
tkinter
def
get_tk_root
():
try
:
root
=
T
kinter
.
_default_root
root
=
t
kinter
.
_default_root
except
AttributeError
:
# it is possible to disable default root in Tkinter, although
# I haven't seen people doing it (but apparently someone did it
...
...
@@ -12,7 +12,7 @@ def get_tk_root():
if
root
is
None
:
# create a new master only if there isn't one already
root
=
T
kinter
.
Tk
()
root
=
t
kinter
.
Tk
()
return
root
...
...
@@ -45,7 +45,7 @@ _tk_patchlevel = None
def
get_tk_patchlevel
():
global
_tk_patchlevel
if
_tk_patchlevel
is
None
:
tcl
=
T
kinter
.
Tcl
()
tcl
=
t
kinter
.
Tcl
()
patchlevel
=
[]
for
x
in
tcl
.
call
(
'info'
,
'patchlevel'
).
split
(
'.'
):
try
:
...
...
@@ -82,7 +82,7 @@ def tcl_obj_eq(actual, expected):
def
widget_eq
(
actual
,
expected
):
if
actual
==
expected
:
return
True
if
isinstance
(
actual
,
(
str
,
T
kinter
.
Widget
)):
if
isinstance
(
expected
,
(
str
,
T
kinter
.
Widget
)):
if
isinstance
(
actual
,
(
str
,
t
kinter
.
Widget
)):
if
isinstance
(
expected
,
(
str
,
t
kinter
.
Widget
)):
return
str
(
actual
)
==
str
(
expected
)
return
False
Lib/lib-tk/test/test_ttk/test_extensions.py
View file @
95cf9862
import
sys
import
unittest
import
Tkinter
import
Tkinter
as
tkinter
import
ttk
from
test.test_support
import
requires
,
run_unittest
...
...
@@ -22,10 +22,10 @@ class LabeledScaleTest(unittest.TestCase):
x
=
ttk
.
LabeledScale
()
var
=
x
.
_variable
.
_name
x
.
destroy
()
self
.
assertRaises
(
T
kinter
.
TclError
,
x
.
tk
.
globalgetvar
,
var
)
self
.
assertRaises
(
t
kinter
.
TclError
,
x
.
tk
.
globalgetvar
,
var
)
# manually created variable
myvar
=
T
kinter
.
DoubleVar
()
myvar
=
t
kinter
.
DoubleVar
()
name
=
myvar
.
_name
x
=
ttk
.
LabeledScale
(
variable
=
myvar
)
x
.
destroy
()
...
...
@@ -34,10 +34,10 @@ class LabeledScaleTest(unittest.TestCase):
else
:
self
.
assertEqual
(
float
(
x
.
tk
.
globalgetvar
(
name
)),
myvar
.
get
())
del
myvar
self
.
assertRaises
(
T
kinter
.
TclError
,
x
.
tk
.
globalgetvar
,
name
)
self
.
assertRaises
(
t
kinter
.
TclError
,
x
.
tk
.
globalgetvar
,
name
)
# checking that the tracing callback is properly removed
myvar
=
T
kinter
.
IntVar
()
myvar
=
t
kinter
.
IntVar
()
# LabeledScale will start tracing myvar
x
=
ttk
.
LabeledScale
(
variable
=
myvar
)
x
.
destroy
()
...
...
@@ -48,15 +48,15 @@ class LabeledScaleTest(unittest.TestCase):
# it tries calling instance attributes not yet defined.
ttk
.
LabeledScale
(
variable
=
myvar
)
if
hasattr
(
sys
,
'last_type'
):
self
.
assertNotEqual
(
sys
.
last_type
,
T
kinter
.
TclError
)
self
.
assertNotEqual
(
sys
.
last_type
,
t
kinter
.
TclError
)
def
test_initialization
(
self
):
# master passing
x
=
ttk
.
LabeledScale
()
self
.
assertEqual
(
x
.
master
,
T
kinter
.
_default_root
)
self
.
assertEqual
(
x
.
master
,
t
kinter
.
_default_root
)
x
.
destroy
()
master
=
T
kinter
.
Frame
()
master
=
t
kinter
.
Frame
()
x
=
ttk
.
LabeledScale
(
master
)
self
.
assertEqual
(
x
.
master
,
master
)
x
.
destroy
()
...
...
@@ -77,7 +77,7 @@ class LabeledScaleTest(unittest.TestCase):
self
.
assertRaises
(
ValueError
,
x
.
_variable
.
get
)
x
.
destroy
()
# variable should have its default value set to the from_ value
myvar
=
T
kinter
.
DoubleVar
(
value
=
20
)
myvar
=
t
kinter
.
DoubleVar
(
value
=
20
)
x
=
ttk
.
LabeledScale
(
variable
=
myvar
)
self
.
assertEqual
(
x
.
value
,
0
)
x
.
destroy
()
...
...
@@ -105,7 +105,7 @@ class LabeledScaleTest(unittest.TestCase):
x
.
destroy
()
# extra, and invalid, kwargs
self
.
assertRaises
(
T
kinter
.
TclError
,
ttk
.
LabeledScale
,
a
=
'b'
)
self
.
assertRaises
(
t
kinter
.
TclError
,
ttk
.
LabeledScale
,
a
=
'b'
)
def
test_horizontal_range
(
self
):
...
...
@@ -194,7 +194,7 @@ class OptionMenuTest(unittest.TestCase):
def
setUp
(
self
):
support
.
root_deiconify
()
self
.
textvar
=
T
kinter
.
StringVar
()
self
.
textvar
=
t
kinter
.
StringVar
()
def
tearDown
(
self
):
del
self
.
textvar
...
...
@@ -202,18 +202,18 @@ class OptionMenuTest(unittest.TestCase):
def
test_widget_destroy
(
self
):
var
=
T
kinter
.
StringVar
()
var
=
t
kinter
.
StringVar
()
optmenu
=
ttk
.
OptionMenu
(
None
,
var
)
name
=
var
.
_name
optmenu
.
update_idletasks
()
optmenu
.
destroy
()
self
.
assertEqual
(
optmenu
.
tk
.
globalgetvar
(
name
),
var
.
get
())
del
var
self
.
assertRaises
(
T
kinter
.
TclError
,
optmenu
.
tk
.
globalgetvar
,
name
)
self
.
assertRaises
(
t
kinter
.
TclError
,
optmenu
.
tk
.
globalgetvar
,
name
)
def
test_initialization
(
self
):
self
.
assertRaises
(
T
kinter
.
TclError
,
self
.
assertRaises
(
t
kinter
.
TclError
,
ttk
.
OptionMenu
,
None
,
self
.
textvar
,
invalid
=
'thing'
)
optmenu
=
ttk
.
OptionMenu
(
None
,
self
.
textvar
,
'b'
,
'a'
,
'b'
)
...
...
@@ -259,7 +259,7 @@ class OptionMenuTest(unittest.TestCase):
self
.
assertEqual
(
optmenu
.
_variable
.
get
(),
items
[
0
])
# changing to an invalid index shouldn't change the variable
self
.
assertRaises
(
T
kinter
.
TclError
,
optmenu
[
'menu'
].
invoke
,
-
1
)
self
.
assertRaises
(
t
kinter
.
TclError
,
optmenu
[
'menu'
].
invoke
,
-
1
)
self
.
assertEqual
(
optmenu
.
_variable
.
get
(),
items
[
0
])
optmenu
.
destroy
()
...
...
Lib/lib-tk/test/test_ttk/test_style.py
View file @
95cf9862
import
unittest
import
Tkinter
import
Tkinter
as
tkinter
import
ttk
from
test.test_support
import
requires
,
run_unittest
...
...
@@ -44,7 +44,7 @@ class StyleTest(unittest.TestCase):
def
test_layout
(
self
):
style
=
self
.
style
self
.
assertRaises
(
T
kinter
.
TclError
,
style
.
layout
,
'NotALayout'
)
self
.
assertRaises
(
t
kinter
.
TclError
,
style
.
layout
,
'NotALayout'
)
tv_style
=
style
.
layout
(
'Treeview'
)
# "erase" Treeview layout
...
...
@@ -61,12 +61,12 @@ class StyleTest(unittest.TestCase):
self
.
assertIsInstance
(
style
.
layout
(
'TButton'
),
list
)
# correct layout, but "option" doesn't exist as option
self
.
assertRaises
(
T
kinter
.
TclError
,
style
.
layout
,
'Treeview'
,
self
.
assertRaises
(
t
kinter
.
TclError
,
style
.
layout
,
'Treeview'
,
[(
'name'
,
{
'option'
:
'inexistent'
})])
def
test_theme_use
(
self
):
self
.
assertRaises
(
T
kinter
.
TclError
,
self
.
style
.
theme_use
,
self
.
assertRaises
(
t
kinter
.
TclError
,
self
.
style
.
theme_use
,
'nonexistingname'
)
curr_theme
=
self
.
style
.
theme_use
()
...
...
Lib/lib-tk/test/test_ttk/test_widgets.py
View file @
95cf9862
import
unittest
import
Tkinter
import
Tkinter
as
tkinter
import
ttk
from
test.test_support
import
requires
,
run_unittest
import
sys
...
...
@@ -76,9 +76,9 @@ class WidgetTest(unittest.TestCase):
),
"label"
)
self
.
assertEqual
(
self
.
widget
.
identify
(
-
1
,
-
1
),
""
)
self
.
assertRaises
(
T
kinter
.
TclError
,
self
.
widget
.
identify
,
None
,
5
)
self
.
assertRaises
(
T
kinter
.
TclError
,
self
.
widget
.
identify
,
5
,
None
)
self
.
assertRaises
(
T
kinter
.
TclError
,
self
.
widget
.
identify
,
5
,
''
)
self
.
assertRaises
(
t
kinter
.
TclError
,
self
.
widget
.
identify
,
None
,
5
)
self
.
assertRaises
(
t
kinter
.
TclError
,
self
.
widget
.
identify
,
5
,
None
)
self
.
assertRaises
(
t
kinter
.
TclError
,
self
.
widget
.
identify
,
5
,
''
)
def
test_widget_state
(
self
):
...
...
@@ -105,9 +105,9 @@ class WidgetTest(unittest.TestCase):
# attempt to set invalid statespec
currstate
=
self
.
widget
.
state
()
self
.
assertRaises
(
T
kinter
.
TclError
,
self
.
widget
.
instate
,
self
.
assertRaises
(
t
kinter
.
TclError
,
self
.
widget
.
instate
,
[
'badstate'
])
self
.
assertRaises
(
T
kinter
.
TclError
,
self
.
widget
.
instate
,
self
.
assertRaises
(
t
kinter
.
TclError
,
self
.
widget
.
instate
,
[
'disabled'
,
'badstate'
])
# verify that widget didn't change its state
self
.
assertEqual
(
currstate
,
self
.
widget
.
state
())
...
...
@@ -162,8 +162,8 @@ class LabelFrameTest(AbstractToplevelTest, unittest.TestCase):
class
AbstractLabelTest
(
AbstractWidgetTest
):
def
checkImageParam
(
self
,
widget
,
name
):
image
=
T
kinter
.
PhotoImage
(
'image1'
)
image2
=
T
kinter
.
PhotoImage
(
'image2'
)
image
=
t
kinter
.
PhotoImage
(
'image1'
)
image2
=
t
kinter
.
PhotoImage
(
'image2'
)
self
.
checkParam
(
widget
,
name
,
image
,
expected
=
(
'image1'
,))
self
.
checkParam
(
widget
,
name
,
'image1'
,
expected
=
(
'image1'
,))
self
.
checkParam
(
widget
,
name
,
(
image
,),
expected
=
(
'image1'
,))
...
...
@@ -263,7 +263,7 @@ class CheckbuttonTest(AbstractLabelTest, unittest.TestCase):
# the variable automatically created by ttk.Checkbutton is actually
# undefined till we invoke the Checkbutton
self
.
assertEqual
(
cbtn
.
state
(),
(
'alternate'
,
))
self
.
assertRaises
(
T
kinter
.
TclError
,
cbtn
.
tk
.
globalgetvar
,
self
.
assertRaises
(
t
kinter
.
TclError
,
cbtn
.
tk
.
globalgetvar
,
cbtn
[
'variable'
])
res
=
cbtn
.
invoke
()
...
...
@@ -400,10 +400,10 @@ class ComboboxTest(AbstractWidgetTest, unittest.TestCase):
r'a\\tb {"a"} \
}
\ \
{
')
# out of range
self.assertRaises(
T
kinter.TclError, self.combo.current,
self.assertRaises(
t
kinter.TclError, self.combo.current,
len(self.combo['
values
']))
# it expects an integer (or something that can be converted to int)
self.assertRaises(
T
kinter.TclError, self.combo.current, '')
self.assertRaises(
t
kinter.TclError, self.combo.current, '')
# testing creating combobox with empty string in values
combo2 = ttk.Combobox(values=[1, 2, ''])
...
...
@@ -462,8 +462,8 @@ class EntryTest(AbstractWidgetTest, unittest.TestCase):
def test_bbox(self):
self.assertIsBoundingBox(self.entry.bbox(0))
self.assertRaises(
T
kinter.TclError, self.entry.bbox, '
noindex
')
self.assertRaises(
T
kinter.TclError, self.entry.bbox, None)
self.assertRaises(
t
kinter.TclError, self.entry.bbox, '
noindex
')
self.assertRaises(
t
kinter.TclError, self.entry.bbox, None)
def test_identify(self):
...
...
@@ -474,9 +474,9 @@ class EntryTest(AbstractWidgetTest, unittest.TestCase):
self.assertEqual(self.entry.identify(5, 5), "textarea")
self.assertEqual(self.entry.identify(-1, -1), "")
self.assertRaises(
T
kinter.TclError, self.entry.identify, None, 5)
self.assertRaises(
T
kinter.TclError, self.entry.identify, 5, None)
self.assertRaises(
T
kinter.TclError, self.entry.identify, 5, '')
self.assertRaises(
t
kinter.TclError, self.entry.identify, None, 5)
self.assertRaises(
t
kinter.TclError, self.entry.identify, 5, None)
self.assertRaises(
t
kinter.TclError, self.entry.identify, 5, '')
def test_validation_options(self):
...
...
@@ -504,7 +504,7 @@ class EntryTest(AbstractWidgetTest, unittest.TestCase):
self.assertEqual(len(success), 1)
self.entry['
validatecommand
'] = True
self.assertRaises(
T
kinter.TclError, self.entry.validate)
self.assertRaises(
t
kinter.TclError, self.entry.validate)
def test_validation(self):
...
...
@@ -585,49 +585,49 @@ class PanedWindowTest(AbstractWidgetTest, unittest.TestCase):
# attempt to add a child that is not a direct child of the paned window
label = ttk.Label(self.paned)
child = ttk.Label(label)
self.assertRaises(
T
kinter.TclError, self.paned.add, child)
self.assertRaises(
t
kinter.TclError, self.paned.add, child)
label.destroy()
child.destroy()
# another attempt
label = ttk.Label()
child = ttk.Label(label)
self.assertRaises(
T
kinter.TclError, self.paned.add, child)
self.assertRaises(
t
kinter.TclError, self.paned.add, child)
child.destroy()
label.destroy()
good_child = ttk.Label()
self.paned.add(good_child)
# re-adding a child is not accepted
self.assertRaises(
T
kinter.TclError, self.paned.add, good_child)
self.assertRaises(
t
kinter.TclError, self.paned.add, good_child)
other_child = ttk.Label(self.paned)
self.paned.add(other_child)
self.assertEqual(self.paned.pane(0), self.paned.pane(1))
self.assertRaises(
T
kinter.TclError, self.paned.pane, 2)
self.assertRaises(
t
kinter.TclError, self.paned.pane, 2)
good_child.destroy()
other_child.destroy()
self.assertRaises(
T
kinter.TclError, self.paned.pane, 0)
self.assertRaises(
t
kinter.TclError, self.paned.pane, 0)
def test_forget(self):
self.assertRaises(
T
kinter.TclError, self.paned.forget, None)
self.assertRaises(
T
kinter.TclError, self.paned.forget, 0)
self.assertRaises(
t
kinter.TclError, self.paned.forget, None)
self.assertRaises(
t
kinter.TclError, self.paned.forget, 0)
self.paned.add(ttk.Label())
self.paned.forget(0)
self.assertRaises(
T
kinter.TclError, self.paned.forget, 0)
self.assertRaises(
t
kinter.TclError, self.paned.forget, 0)
def test_insert(self):
self.assertRaises(
T
kinter.TclError, self.paned.insert, None, 0)
self.assertRaises(
T
kinter.TclError, self.paned.insert, 0, None)
self.assertRaises(
T
kinter.TclError, self.paned.insert, 0, 0)
self.assertRaises(
t
kinter.TclError, self.paned.insert, None, 0)
self.assertRaises(
t
kinter.TclError, self.paned.insert, 0, None)
self.assertRaises(
t
kinter.TclError, self.paned.insert, 0, 0)
child = ttk.Label()
child2 = ttk.Label()
child3 = ttk.Label()
self.assertRaises(
T
kinter.TclError, self.paned.insert, 0, child)
self.assertRaises(
t
kinter.TclError, self.paned.insert, 0, child)
self.paned.insert('
end
', child2)
self.paned.insert(0, child)
...
...
@@ -654,7 +654,7 @@ class PanedWindowTest(AbstractWidgetTest, unittest.TestCase):
def test_pane(self):
self.assertRaises(
T
kinter.TclError, self.paned.pane, 0)
self.assertRaises(
t
kinter.TclError, self.paned.pane, 0)
child = ttk.Label()
self.paned.add(child)
...
...
@@ -666,21 +666,21 @@ class PanedWindowTest(AbstractWidgetTest, unittest.TestCase):
0 if self.wantobjects else '
0
')
self.assertEqual(self.paned.pane(0), self.paned.pane(str(child)))
self.assertRaises(
T
kinter.TclError, self.paned.pane, 0,
self.assertRaises(
t
kinter.TclError, self.paned.pane, 0,
badoption='
somevalue
')
def test_sashpos(self):
self.assertRaises(
T
kinter.TclError, self.paned.sashpos, None)
self.assertRaises(
T
kinter.TclError, self.paned.sashpos, '')
self.assertRaises(
T
kinter.TclError, self.paned.sashpos, 0)
self.assertRaises(
t
kinter.TclError, self.paned.sashpos, None)
self.assertRaises(
t
kinter.TclError, self.paned.sashpos, '')
self.assertRaises(
t
kinter.TclError, self.paned.sashpos, 0)
child = ttk.Label(self.paned, text='
a
')
self.paned.add(child, weight=1)
self.assertRaises(
T
kinter.TclError, self.paned.sashpos, 0)
self.assertRaises(
t
kinter.TclError, self.paned.sashpos, 0)
child2 = ttk.Label(self.paned, text='b')
self.paned.add(child2)
self.assertRaises(
T
kinter.TclError, self.paned.sashpos, 1)
self.assertRaises(
t
kinter.TclError, self.paned.sashpos, 1)
self.paned.pack(expand=True, fill='
both
')
self.paned.wait_visibility()
...
...
@@ -714,7 +714,7 @@ class RadiobuttonTest(AbstractLabelTest, unittest.TestCase):
success.append(1)
return "cb test called"
myvar =
T
kinter.IntVar()
myvar =
t
kinter.IntVar()
cbtn = ttk.Radiobutton(command=cb_test, variable=myvar, value=0)
cbtn2 = ttk.Radiobutton(command=cb_test, variable=myvar, value=1)
...
...
@@ -759,7 +759,7 @@ class MenubuttonTest(AbstractLabelTest, unittest.TestCase):
def test_menu(self):
widget = self.create()
menu =
T
kinter.Menu(widget, name='
menu
')
menu =
t
kinter.Menu(widget, name='
menu
')
self.checkParam(widget, '
menu
', menu, conv=str)
menu.destroy()
...
...
@@ -837,8 +837,8 @@ class ScaleTest(AbstractWidgetTest, unittest.TestCase):
self.scale['
value
'] = 30
self.assertEqual(self.scale.get(), self.scale['
value
'])
self.assertRaises(
T
kinter.TclError, self.scale.get, '', 0)
self.assertRaises(
T
kinter.TclError, self.scale.get, 0, '')
self.assertRaises(
t
kinter.TclError, self.scale.get, '', 0)
self.assertRaises(
t
kinter.TclError, self.scale.get, 0, '')
def test_set(self):
...
...
@@ -857,7 +857,7 @@ class ScaleTest(AbstractWidgetTest, unittest.TestCase):
self.assertEqual(conv(self.scale.get()), min)
# changing directly the variable doesn'
t
impose
this
limitation
tho
var
=
T
kinter
.
DoubleVar
()
var
=
t
kinter
.
DoubleVar
()
self
.
scale
[
'variable'
]
=
var
var
.
set
(
max
+
5
)
self
.
assertEqual
(
conv
(
self
.
scale
.
get
()),
var
.
get
())
...
...
@@ -874,7 +874,7 @@ class ScaleTest(AbstractWidgetTest, unittest.TestCase):
self
.
assertEqual
(
conv
(
self
.
scale
.
get
(
0
,
0
)),
min
)
self
.
assertEqual
(
conv
(
self
.
scale
.
get
(
self
.
scale
.
winfo_width
(),
0
)),
max
)
self
.
assertRaises
(
T
kinter
.
TclError
,
self
.
scale
.
set
,
None
)
self
.
assertRaises
(
t
kinter
.
TclError
,
self
.
scale
.
set
,
None
)
@
add_standard_options
(
StandardTtkOptionsTests
)
...
...
@@ -953,7 +953,7 @@ class NotebookTest(AbstractWidgetTest, unittest.TestCase):
def
test_tab_identifiers
(
self
):
self
.
nb
.
forget
(
0
)
self
.
nb
.
hide
(
self
.
child2
)
self
.
assertRaises
(
T
kinter
.
TclError
,
self
.
nb
.
tab
,
self
.
child1
)
self
.
assertRaises
(
t
kinter
.
TclError
,
self
.
nb
.
tab
,
self
.
child1
)
self
.
assertEqual
(
self
.
nb
.
index
(
'end'
),
1
)
self
.
nb
.
add
(
self
.
child2
)
self
.
assertEqual
(
self
.
nb
.
index
(
'end'
),
1
)
...
...
@@ -974,7 +974,7 @@ class NotebookTest(AbstractWidgetTest, unittest.TestCase):
try
:
if
self
.
nb
.
tab
(
'@%d, 5'
%
i
,
text
=
None
)
==
'a'
:
break
except
T
kinter
.
TclError
:
except
t
kinter
.
TclError
:
pass
else
:
...
...
@@ -982,11 +982,11 @@ class NotebookTest(AbstractWidgetTest, unittest.TestCase):
def
test_add_and_hidden
(
self
):
self
.
assertRaises
(
T
kinter
.
TclError
,
self
.
nb
.
hide
,
-
1
)
self
.
assertRaises
(
T
kinter
.
TclError
,
self
.
nb
.
hide
,
'hi'
)
self
.
assertRaises
(
T
kinter
.
TclError
,
self
.
nb
.
hide
,
None
)
self
.
assertRaises
(
T
kinter
.
TclError
,
self
.
nb
.
add
,
None
)
self
.
assertRaises
(
T
kinter
.
TclError
,
self
.
nb
.
add
,
ttk
.
Label
(),
self
.
assertRaises
(
t
kinter
.
TclError
,
self
.
nb
.
hide
,
-
1
)
self
.
assertRaises
(
t
kinter
.
TclError
,
self
.
nb
.
hide
,
'hi'
)
self
.
assertRaises
(
t
kinter
.
TclError
,
self
.
nb
.
hide
,
None
)
self
.
assertRaises
(
t
kinter
.
TclError
,
self
.
nb
.
add
,
None
)
self
.
assertRaises
(
t
kinter
.
TclError
,
self
.
nb
.
add
,
ttk
.
Label
(),
unknown
=
'option'
)
tabs
=
self
.
nb
.
tabs
()
...
...
@@ -1011,9 +1011,9 @@ class NotebookTest(AbstractWidgetTest, unittest.TestCase):
def
test_forget
(
self
):
self
.
assertRaises
(
T
kinter
.
TclError
,
self
.
nb
.
forget
,
-
1
)
self
.
assertRaises
(
T
kinter
.
TclError
,
self
.
nb
.
forget
,
'hi'
)
self
.
assertRaises
(
T
kinter
.
TclError
,
self
.
nb
.
forget
,
None
)
self
.
assertRaises
(
t
kinter
.
TclError
,
self
.
nb
.
forget
,
-
1
)
self
.
assertRaises
(
t
kinter
.
TclError
,
self
.
nb
.
forget
,
'hi'
)
self
.
assertRaises
(
t
kinter
.
TclError
,
self
.
nb
.
forget
,
None
)
tabs
=
self
.
nb
.
tabs
()
child1_index
=
self
.
nb
.
index
(
self
.
child1
)
...
...
@@ -1027,8 +1027,8 @@ class NotebookTest(AbstractWidgetTest, unittest.TestCase):
def
test_index
(
self
):
self
.
assertRaises
(
T
kinter
.
TclError
,
self
.
nb
.
index
,
-
1
)
self
.
assertRaises
(
T
kinter
.
TclError
,
self
.
nb
.
index
,
None
)
self
.
assertRaises
(
t
kinter
.
TclError
,
self
.
nb
.
index
,
-
1
)
self
.
assertRaises
(
t
kinter
.
TclError
,
self
.
nb
.
index
,
None
)
self
.
assertIsInstance
(
self
.
nb
.
index
(
'end'
),
int
)
self
.
assertEqual
(
self
.
nb
.
index
(
self
.
child1
),
0
)
...
...
@@ -1048,8 +1048,8 @@ class NotebookTest(AbstractWidgetTest, unittest.TestCase):
self
.
nb
.
insert
(
'end'
,
0
)
self
.
assertEqual
(
self
.
nb
.
tabs
(),
tabs
)
# bad moves
self
.
assertRaises
(
T
kinter
.
TclError
,
self
.
nb
.
insert
,
2
,
tabs
[
0
])
self
.
assertRaises
(
T
kinter
.
TclError
,
self
.
nb
.
insert
,
-
1
,
tabs
[
0
])
self
.
assertRaises
(
t
kinter
.
TclError
,
self
.
nb
.
insert
,
2
,
tabs
[
0
])
self
.
assertRaises
(
t
kinter
.
TclError
,
self
.
nb
.
insert
,
-
1
,
tabs
[
0
])
# new tab
child3
=
ttk
.
Label
()
...
...
@@ -1060,13 +1060,13 @@ class NotebookTest(AbstractWidgetTest, unittest.TestCase):
self
.
nb
.
insert
(
self
.
child1
,
child3
)
self
.
assertEqual
(
self
.
nb
.
tabs
(),
(
str
(
child3
),
)
+
tabs
)
self
.
nb
.
forget
(
child3
)
self
.
assertRaises
(
T
kinter
.
TclError
,
self
.
nb
.
insert
,
2
,
child3
)
self
.
assertRaises
(
T
kinter
.
TclError
,
self
.
nb
.
insert
,
-
1
,
child3
)
self
.
assertRaises
(
t
kinter
.
TclError
,
self
.
nb
.
insert
,
2
,
child3
)
self
.
assertRaises
(
t
kinter
.
TclError
,
self
.
nb
.
insert
,
-
1
,
child3
)
# bad inserts
self
.
assertRaises
(
T
kinter
.
TclError
,
self
.
nb
.
insert
,
'end'
,
None
)
self
.
assertRaises
(
T
kinter
.
TclError
,
self
.
nb
.
insert
,
None
,
0
)
self
.
assertRaises
(
T
kinter
.
TclError
,
self
.
nb
.
insert
,
None
,
None
)
self
.
assertRaises
(
t
kinter
.
TclError
,
self
.
nb
.
insert
,
'end'
,
None
)
self
.
assertRaises
(
t
kinter
.
TclError
,
self
.
nb
.
insert
,
None
,
0
)
self
.
assertRaises
(
t
kinter
.
TclError
,
self
.
nb
.
insert
,
None
,
None
)
def
test_select
(
self
):
...
...
@@ -1090,9 +1090,9 @@ class NotebookTest(AbstractWidgetTest, unittest.TestCase):
def
test_tab
(
self
):
self
.
assertRaises
(
T
kinter
.
TclError
,
self
.
nb
.
tab
,
-
1
)
self
.
assertRaises
(
T
kinter
.
TclError
,
self
.
nb
.
tab
,
'notab'
)
self
.
assertRaises
(
T
kinter
.
TclError
,
self
.
nb
.
tab
,
None
)
self
.
assertRaises
(
t
kinter
.
TclError
,
self
.
nb
.
tab
,
-
1
)
self
.
assertRaises
(
t
kinter
.
TclError
,
self
.
nb
.
tab
,
'notab'
)
self
.
assertRaises
(
t
kinter
.
TclError
,
self
.
nb
.
tab
,
None
)
self
.
assertIsInstance
(
self
.
nb
.
tab
(
self
.
child1
),
dict
)
self
.
assertEqual
(
self
.
nb
.
tab
(
self
.
child1
,
text
=
None
),
'a'
)
...
...
@@ -1246,7 +1246,7 @@ class TreeviewTest(AbstractWidgetTest, unittest.TestCase):
# child3 has child2 as parent, thus trying to set child2 as a children
# of child3 should result in an error
self
.
assertRaises
(
T
kinter
.
TclError
,
self
.
assertRaises
(
t
kinter
.
TclError
,
self
.
tv
.
set_children
,
child3
,
child2
)
# remove child2 children
...
...
@@ -1272,20 +1272,20 @@ class TreeviewTest(AbstractWidgetTest, unittest.TestCase):
self
.
assertEqual
(
self
.
tv
.
column
(
'#0'
,
width
=
None
),
10
if
self
.
wantobjects
else
'10'
)
# check read-only option
self
.
assertRaises
(
T
kinter
.
TclError
,
self
.
tv
.
column
,
'#0'
,
id
=
'X'
)
self
.
assertRaises
(
t
kinter
.
TclError
,
self
.
tv
.
column
,
'#0'
,
id
=
'X'
)
self
.
assertRaises
(
T
kinter
.
TclError
,
self
.
tv
.
column
,
'invalid'
)
self
.
assertRaises
(
t
kinter
.
TclError
,
self
.
tv
.
column
,
'invalid'
)
invalid_kws
=
[
{
'unknown_option'
:
'some value'
},
{
'stretch'
:
'wrong'
},
{
'anchor'
:
'wrong'
},
{
'width'
:
'wrong'
},
{
'minwidth'
:
'wrong'
}
]
for
kw
in
invalid_kws
:
self
.
assertRaises
(
T
kinter
.
TclError
,
self
.
tv
.
column
,
'#0'
,
self
.
assertRaises
(
t
kinter
.
TclError
,
self
.
tv
.
column
,
'#0'
,
**
kw
)
def
test_delete
(
self
):
self
.
assertRaises
(
T
kinter
.
TclError
,
self
.
tv
.
delete
,
'#0'
)
self
.
assertRaises
(
t
kinter
.
TclError
,
self
.
tv
.
delete
,
'#0'
)
item_id
=
self
.
tv
.
insert
(
''
,
'end'
)
item2
=
self
.
tv
.
insert
(
item_id
,
'end'
)
...
...
@@ -1296,7 +1296,7 @@ class TreeviewTest(AbstractWidgetTest, unittest.TestCase):
self
.
assertFalse
(
self
.
tv
.
get_children
())
# reattach should fail
self
.
assertRaises
(
T
kinter
.
TclError
,
self
.
assertRaises
(
t
kinter
.
TclError
,
self
.
tv
.
reattach
,
item_id
,
''
,
'end'
)
# test multiple item delete
...
...
@@ -1335,13 +1335,13 @@ class TreeviewTest(AbstractWidgetTest, unittest.TestCase):
self
.
assertEqual
(
self
.
tv
.
get_children
(
item_id
),
())
# bad values
self
.
assertRaises
(
T
kinter
.
TclError
,
self
.
assertRaises
(
t
kinter
.
TclError
,
self
.
tv
.
reattach
,
'nonexistent'
,
''
,
'end'
)
self
.
assertRaises
(
T
kinter
.
TclError
,
self
.
assertRaises
(
t
kinter
.
TclError
,
self
.
tv
.
detach
,
'nonexistent'
)
self
.
assertRaises
(
T
kinter
.
TclError
,
self
.
assertRaises
(
t
kinter
.
TclError
,
self
.
tv
.
reattach
,
item2
,
'otherparent'
,
'end'
)
self
.
assertRaises
(
T
kinter
.
TclError
,
self
.
assertRaises
(
t
kinter
.
TclError
,
self
.
tv
.
reattach
,
item2
,
''
,
'invalid'
)
# multiple detach
...
...
@@ -1358,7 +1358,7 @@ class TreeviewTest(AbstractWidgetTest, unittest.TestCase):
# the following will make a tk.call equivalent to
# tk.call(treeview, "exists") which should result in an error
# in the tcl interpreter since tk requires an item.
self
.
assertRaises
(
T
kinter
.
TclError
,
self
.
tv
.
exists
,
None
)
self
.
assertRaises
(
t
kinter
.
TclError
,
self
.
tv
.
exists
,
None
)
def
test_focus
(
self
):
...
...
@@ -1373,7 +1373,7 @@ class TreeviewTest(AbstractWidgetTest, unittest.TestCase):
self
.
assertEqual
(
self
.
tv
.
focus
(),
''
)
# try focusing inexistent item
self
.
assertRaises
(
T
kinter
.
TclError
,
self
.
tv
.
focus
,
'hi'
)
self
.
assertRaises
(
t
kinter
.
TclError
,
self
.
tv
.
focus
,
'hi'
)
def
test_heading
(
self
):
...
...
@@ -1386,10 +1386,10 @@ class TreeviewTest(AbstractWidgetTest, unittest.TestCase):
self
.
assertEqual
(
self
.
tv
.
heading
(
'#0'
,
text
=
None
),
'hi'
)
# invalid option
self
.
assertRaises
(
T
kinter
.
TclError
,
self
.
tv
.
heading
,
'#0'
,
self
.
assertRaises
(
t
kinter
.
TclError
,
self
.
tv
.
heading
,
'#0'
,
background
=
None
)
# invalid value
self
.
assertRaises
(
T
kinter
.
TclError
,
self
.
tv
.
heading
,
'#0'
,
self
.
assertRaises
(
t
kinter
.
TclError
,
self
.
tv
.
heading
,
'#0'
,
anchor
=
1
)
def
test_heading_callback
(
self
):
...
...
@@ -1428,7 +1428,7 @@ class TreeviewTest(AbstractWidgetTest, unittest.TestCase):
def
test_index
(
self
):
# item 'what' doesn't exist
self
.
assertRaises
(
T
kinter
.
TclError
,
self
.
tv
.
index
,
'what'
)
self
.
assertRaises
(
t
kinter
.
TclError
,
self
.
tv
.
index
,
'what'
)
self
.
assertEqual
(
self
.
tv
.
index
(
''
),
0
)
...
...
@@ -1454,30 +1454,30 @@ class TreeviewTest(AbstractWidgetTest, unittest.TestCase):
# but it fails after item has been deleted
self
.
tv
.
delete
(
item1
)
self
.
assertRaises
(
T
kinter
.
TclError
,
self
.
tv
.
index
,
c2
)
self
.
assertRaises
(
t
kinter
.
TclError
,
self
.
tv
.
index
,
c2
)
def
test_insert_item
(
self
):
# parent 'none' doesn't exist
self
.
assertRaises
(
T
kinter
.
TclError
,
self
.
tv
.
insert
,
'none'
,
'end'
)
self
.
assertRaises
(
t
kinter
.
TclError
,
self
.
tv
.
insert
,
'none'
,
'end'
)
# open values
self
.
assertRaises
(
T
kinter
.
TclError
,
self
.
tv
.
insert
,
''
,
'end'
,
self
.
assertRaises
(
t
kinter
.
TclError
,
self
.
tv
.
insert
,
''
,
'end'
,
open
=
''
)
self
.
assertRaises
(
T
kinter
.
TclError
,
self
.
tv
.
insert
,
''
,
'end'
,
self
.
assertRaises
(
t
kinter
.
TclError
,
self
.
tv
.
insert
,
''
,
'end'
,
open
=
'please'
)
self
.
assertFalse
(
self
.
tv
.
delete
(
self
.
tv
.
insert
(
''
,
'end'
,
open
=
True
)))
self
.
assertFalse
(
self
.
tv
.
delete
(
self
.
tv
.
insert
(
''
,
'end'
,
open
=
False
)))
# invalid index
self
.
assertRaises
(
T
kinter
.
TclError
,
self
.
tv
.
insert
,
''
,
'middle'
)
self
.
assertRaises
(
t
kinter
.
TclError
,
self
.
tv
.
insert
,
''
,
'middle'
)
# trying to duplicate item id is invalid
itemid
=
self
.
tv
.
insert
(
''
,
'end'
,
'first-item'
)
self
.
assertEqual
(
itemid
,
'first-item'
)
self
.
assertRaises
(
T
kinter
.
TclError
,
self
.
tv
.
insert
,
''
,
'end'
,
self
.
assertRaises
(
t
kinter
.
TclError
,
self
.
tv
.
insert
,
''
,
'end'
,
'first-item'
)
self
.
assertRaises
(
T
kinter
.
TclError
,
self
.
tv
.
insert
,
''
,
'end'
,
self
.
assertRaises
(
t
kinter
.
TclError
,
self
.
tv
.
insert
,
''
,
'end'
,
MockTclObj
(
'first-item'
))
# unicode values
...
...
@@ -1551,11 +1551,11 @@ class TreeviewTest(AbstractWidgetTest, unittest.TestCase):
{
'B'
:
123
}
if
self
.
wantobjects
else
{
'B'
:
'123'
})
# inexistent column
self
.
assertRaises
(
T
kinter
.
TclError
,
self
.
tv
.
set
,
item
,
'A'
)
self
.
assertRaises
(
T
kinter
.
TclError
,
self
.
tv
.
set
,
item
,
'A'
,
'b'
)
self
.
assertRaises
(
t
kinter
.
TclError
,
self
.
tv
.
set
,
item
,
'A'
)
self
.
assertRaises
(
t
kinter
.
TclError
,
self
.
tv
.
set
,
item
,
'A'
,
'b'
)
# inexistent item
self
.
assertRaises
(
T
kinter
.
TclError
,
self
.
tv
.
set
,
'notme'
)
self
.
assertRaises
(
t
kinter
.
TclError
,
self
.
tv
.
set
,
'notme'
)
def
test_tag_bind
(
self
):
...
...
@@ -1595,7 +1595,7 @@ class TreeviewTest(AbstractWidgetTest, unittest.TestCase):
def
test_tag_configure
(
self
):
# Just testing parameter passing for now
self
.
assertRaises
(
TypeError
,
self
.
tv
.
tag_configure
)
self
.
assertRaises
(
T
kinter
.
TclError
,
self
.
tv
.
tag_configure
,
self
.
assertRaises
(
t
kinter
.
TclError
,
self
.
tv
.
tag_configure
,
'test'
,
sky
=
'blue'
)
self
.
tv
.
tag_configure
(
'test'
,
foreground
=
'blue'
)
self
.
assertEqual
(
str
(
self
.
tv
.
tag_configure
(
'test'
,
'foreground'
)),
...
...
Lib/lib-tk/test/widget_tests.py
View file @
95cf9862
...
...
@@ -2,7 +2,7 @@
import
unittest
import
sys
import
Tkinter
import
Tkinter
as
tkinter
from
ttk
import
setup_master
,
Scale
from
test_ttk.support
import
(
tcl_version
,
requires_tcl
,
get_tk_patchlevel
,
pixels_conv
,
tcl_obj_eq
)
...
...
@@ -67,7 +67,7 @@ class AbstractWidgetTest(object):
expected
=
conv
(
expected
)
if
not
self
.
wantobjects
:
if
isinstance
(
expected
,
tuple
):
expected
=
T
kinter
.
_join
(
expected
)
expected
=
t
kinter
.
_join
(
expected
)
else
:
expected
=
str
(
expected
)
if
eq
is
None
:
...
...
@@ -85,7 +85,7 @@ class AbstractWidgetTest(object):
orig
=
widget
[
name
]
if
errmsg
is
not
None
:
errmsg
=
errmsg
.
format
(
value
)
with
self
.
assertRaises
(
T
kinter
.
TclError
)
as
cm
:
with
self
.
assertRaises
(
t
kinter
.
TclError
)
as
cm
:
widget
[
name
]
=
value
if
errmsg
is
not
None
:
self
.
assertEqual
(
str
(
cm
.
exception
),
errmsg
)
...
...
@@ -93,7 +93,7 @@ class AbstractWidgetTest(object):
self
.
assertEqual
(
widget
[
name
],
orig
)
else
:
widget
[
name
]
=
orig
with
self
.
assertRaises
(
T
kinter
.
TclError
)
as
cm
:
with
self
.
assertRaises
(
t
kinter
.
TclError
)
as
cm
:
widget
.
configure
({
name
:
value
})
if
errmsg
is
not
None
:
self
.
assertEqual
(
str
(
cm
.
exception
),
errmsg
)
...
...
@@ -212,7 +212,7 @@ class AbstractWidgetTest(object):
errmsg
=
errmsg
)
def
checkImageParam
(
self
,
widget
,
name
):
image
=
T
kinter
.
PhotoImage
(
'image1'
)
image
=
t
kinter
.
PhotoImage
(
'image1'
)
self
.
checkParam
(
widget
,
name
,
image
,
conv
=
str
)
self
.
checkInvalidParam
(
widget
,
name
,
'spam'
,
errmsg
=
'image "spam" doesn
\
'
t exist'
)
...
...
@@ -433,7 +433,7 @@ class StandardOptionsTests(object):
def
test_textvariable
(
self
):
widget
=
self
.
create
()
var
=
T
kinter
.
StringVar
()
var
=
t
kinter
.
StringVar
()
self
.
checkVariableParam
(
widget
,
'textvariable'
,
var
)
def
test_troughcolor
(
self
):
...
...
@@ -494,7 +494,7 @@ class StandardOptionsTests(object):
def
test_variable
(
self
):
widget
=
self
.
create
()
var
=
T
kinter
.
DoubleVar
()
var
=
t
kinter
.
DoubleVar
()
self
.
checkVariableParam
(
widget
,
'variable'
,
var
)
...
...
@@ -543,5 +543,5 @@ def add_standard_options(*source_classes):
def
setUpModule
():
if
test
.
test_support
.
verbose
:
tcl
=
T
kinter
.
Tcl
()
tcl
=
t
kinter
.
Tcl
()
print
'patchlevel ='
,
tcl
.
call
(
'info'
,
'patchlevel'
)
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