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
c64d942e
Commit
c64d942e
authored
May 15, 2016
by
Terry Jan Reedy
Browse files
Options
Browse Files
Download
Email Patches
Plain Diff
Issue #20640: Add tests for idlelib.configHelpSourceEdit.
Patch by Saimadhav Heblikar.
parent
507898d3
Changes
3
Hide whitespace changes
Inline
Side-by-side
Showing
3 changed files
with
136 additions
and
21 deletions
+136
-21
Lib/idlelib/configHelpSourceEdit.py
Lib/idlelib/configHelpSourceEdit.py
+25
-21
Lib/idlelib/idle_test/mock_tk.py
Lib/idlelib/idle_test/mock_tk.py
+5
-0
Lib/idlelib/idle_test/test_config_help.py
Lib/idlelib/idle_test/test_config_help.py
+106
-0
No files found.
Lib/idlelib/configHelpSourceEdit.py
View file @
c64d942e
...
...
@@ -23,10 +23,10 @@ class GetHelpSourceDialog(Toplevel):
self
.
title
(
title
)
self
.
transient
(
parent
)
self
.
grab_set
()
self
.
protocol
(
"WM_DELETE_WINDOW"
,
self
.
C
ancel
)
self
.
protocol
(
"WM_DELETE_WINDOW"
,
self
.
c
ancel
)
self
.
parent
=
parent
self
.
result
=
None
self
.
CreateW
idgets
()
self
.
create_w
idgets
()
self
.
menu
.
set
(
menuItem
)
self
.
path
.
set
(
filePath
)
self
.
withdraw
()
#hide while setting geometry
...
...
@@ -41,10 +41,10 @@ class GetHelpSourceDialog(Toplevel):
((
parent
.
winfo_height
()
/
2
-
self
.
winfo_reqheight
()
/
2
)
if
not
_htest
else
150
)))
self
.
deiconify
()
#geometry set, unhide
self
.
bind
(
'<Return>'
,
self
.
O
k
)
self
.
bind
(
'<Return>'
,
self
.
o
k
)
self
.
wait_window
()
def
CreateW
idgets
(
self
):
def
create_w
idgets
(
self
):
self
.
menu
=
StringVar
(
self
)
self
.
path
=
StringVar
(
self
)
self
.
fontSize
=
StringVar
(
self
)
...
...
@@ -65,18 +65,18 @@ class GetHelpSourceDialog(Toplevel):
labelPath
.
pack
(
anchor
=
W
,
padx
=
5
,
pady
=
3
)
self
.
entryPath
.
pack
(
anchor
=
W
,
padx
=
5
,
pady
=
3
)
browseButton
=
Button
(
self
.
frameMain
,
text
=
'Browse'
,
width
=
8
,
command
=
self
.
browse
F
ile
)
command
=
self
.
browse
_f
ile
)
browseButton
.
pack
(
pady
=
3
)
frameButtons
=
Frame
(
self
)
frameButtons
.
pack
(
side
=
BOTTOM
,
fill
=
X
)
self
.
buttonOk
=
Button
(
frameButtons
,
text
=
'OK'
,
width
=
8
,
default
=
ACTIVE
,
command
=
self
.
O
k
)
width
=
8
,
default
=
ACTIVE
,
command
=
self
.
o
k
)
self
.
buttonOk
.
grid
(
row
=
0
,
column
=
0
,
padx
=
5
,
pady
=
5
)
self
.
buttonCancel
=
Button
(
frameButtons
,
text
=
'Cancel'
,
width
=
8
,
command
=
self
.
C
ancel
)
width
=
8
,
command
=
self
.
c
ancel
)
self
.
buttonCancel
.
grid
(
row
=
0
,
column
=
1
,
padx
=
5
,
pady
=
5
)
def
browse
F
ile
(
self
):
def
browse
_f
ile
(
self
):
filetypes
=
[
(
"HTML Files"
,
"*.htm *.html"
,
"TEXT"
),
(
"PDF Files"
,
"*.pdf"
,
"TEXT"
),
...
...
@@ -99,9 +99,9 @@ class GetHelpSourceDialog(Toplevel):
if
file
:
self
.
path
.
set
(
file
)
def
MenuO
k
(
self
):
def
menu_o
k
(
self
):
"Simple validity check for a sensible menu item name"
menu
O
k
=
True
menu
_o
k
=
True
menu
=
self
.
menu
.
get
()
menu
.
strip
()
if
not
menu
:
...
...
@@ -109,19 +109,19 @@ class GetHelpSourceDialog(Toplevel):
message
=
'No menu item specified'
,
parent
=
self
)
self
.
entryMenu
.
focus_set
()
menu
O
k
=
False
menu
_o
k
=
False
elif
len
(
menu
)
>
30
:
tkMessageBox
.
showerror
(
title
=
'Menu Item Error'
,
message
=
'Menu item too long:'
'
\
n
Limit 30 characters.'
,
parent
=
self
)
self
.
entryMenu
.
focus_set
()
menu
O
k
=
False
return
menu
O
k
menu
_o
k
=
False
return
menu
_o
k
def
PathO
k
(
self
):
def
path_o
k
(
self
):
"Simple validity check for menu file path"
path
O
k
=
True
path
_o
k
=
True
path
=
self
.
path
.
get
()
path
.
strip
()
if
not
path
:
#no path specified
...
...
@@ -129,7 +129,7 @@ class GetHelpSourceDialog(Toplevel):
message
=
'No help file path specified.'
,
parent
=
self
)
self
.
entryPath
.
focus_set
()
path
O
k
=
False
path
_o
k
=
False
elif
path
.
startswith
((
'www.'
,
'http'
)):
pass
else
:
...
...
@@ -140,11 +140,11 @@ class GetHelpSourceDialog(Toplevel):
message
=
'Help file path does not exist.'
,
parent
=
self
)
self
.
entryPath
.
focus_set
()
path
O
k
=
False
return
path
O
k
path
_o
k
=
False
return
path
_o
k
def
O
k
(
self
,
event
=
None
):
if
self
.
MenuOk
()
and
self
.
PathO
k
():
def
o
k
(
self
,
event
=
None
):
if
self
.
menu_ok
()
and
self
.
path_o
k
():
self
.
result
=
(
self
.
menu
.
get
().
strip
(),
self
.
path
.
get
().
strip
())
if
sys
.
platform
==
'darwin'
:
...
...
@@ -157,10 +157,14 @@ class GetHelpSourceDialog(Toplevel):
self
.
result
[
1
]
=
"file://"
+
path
self
.
destroy
()
def
C
ancel
(
self
,
event
=
None
):
def
c
ancel
(
self
,
event
=
None
):
self
.
result
=
None
self
.
destroy
()
if
__name__
==
'__main__'
:
import
unittest
unittest
.
main
(
'idlelib.idle_test.test_config_help'
,
verbosity
=
2
,
exit
=
False
)
from
idlelib.idle_test.htest
import
run
run
(
GetHelpSourceDialog
)
Lib/idlelib/idle_test/mock_tk.py
View file @
c64d942e
...
...
@@ -296,3 +296,8 @@ class Text:
def
bind
(
sequence
=
None
,
func
=
None
,
add
=
None
):
"Bind to this widget at event sequence a call to function func."
pass
class
Entry
:
"Mock for tkinter.Entry."
def
focus_set
(
self
):
pass
Lib/idlelib/idle_test/test_config_help.py
0 → 100644
View file @
c64d942e
"""Unittests for idlelib.configHelpSourceEdit"""
import
unittest
from
idlelib.idle_test.mock_tk
import
Var
,
Mbox
,
Entry
from
idlelib
import
configHelpSourceEdit
as
help_dialog_module
help_dialog
=
help_dialog_module
.
GetHelpSourceDialog
class
Dummy_help_dialog
:
# Mock for testing the following methods of help_dialog
menu_ok
=
help_dialog
.
menu_ok
path_ok
=
help_dialog
.
path_ok
ok
=
help_dialog
.
ok
cancel
=
help_dialog
.
cancel
# Attributes, constant or variable, needed for tests
menu
=
Var
()
entryMenu
=
Entry
()
path
=
Var
()
entryPath
=
Entry
()
result
=
None
destroyed
=
False
def
destroy
(
self
):
self
.
destroyed
=
True
# menu_ok and path_ok call Mbox.showerror if menu and path are not ok.
orig_mbox
=
help_dialog_module
.
tkMessageBox
showerror
=
Mbox
.
showerror
class
ConfigHelpTest
(
unittest
.
TestCase
):
dialog
=
Dummy_help_dialog
()
@
classmethod
def
setUpClass
(
cls
):
help_dialog_module
.
tkMessageBox
=
Mbox
@
classmethod
def
tearDownClass
(
cls
):
help_dialog_module
.
tkMessageBox
=
orig_mbox
def
test_blank_menu
(
self
):
self
.
dialog
.
menu
.
set
(
''
)
self
.
assertFalse
(
self
.
dialog
.
menu_ok
())
self
.
assertEqual
(
showerror
.
title
,
'Menu Item Error'
)
self
.
assertIn
(
'No'
,
showerror
.
message
)
def
test_long_menu
(
self
):
self
.
dialog
.
menu
.
set
(
'hello'
*
10
)
self
.
assertFalse
(
self
.
dialog
.
menu_ok
())
self
.
assertEqual
(
showerror
.
title
,
'Menu Item Error'
)
self
.
assertIn
(
'long'
,
showerror
.
message
)
def
test_good_menu
(
self
):
self
.
dialog
.
menu
.
set
(
'help'
)
showerror
.
title
=
'No Error'
# should not be called
self
.
assertTrue
(
self
.
dialog
.
menu_ok
())
self
.
assertEqual
(
showerror
.
title
,
'No Error'
)
def
test_blank_path
(
self
):
self
.
dialog
.
path
.
set
(
''
)
self
.
assertFalse
(
self
.
dialog
.
path_ok
())
self
.
assertEqual
(
showerror
.
title
,
'File Path Error'
)
self
.
assertIn
(
'No'
,
showerror
.
message
)
def
test_invalid_file_path
(
self
):
self
.
dialog
.
path
.
set
(
'foobar'
*
100
)
self
.
assertFalse
(
self
.
dialog
.
path_ok
())
self
.
assertEqual
(
showerror
.
title
,
'File Path Error'
)
self
.
assertIn
(
'not exist'
,
showerror
.
message
)
def
test_invalid_url_path
(
self
):
self
.
dialog
.
path
.
set
(
'ww.foobar.com'
)
self
.
assertFalse
(
self
.
dialog
.
path_ok
())
self
.
assertEqual
(
showerror
.
title
,
'File Path Error'
)
self
.
assertIn
(
'not exist'
,
showerror
.
message
)
self
.
dialog
.
path
.
set
(
'htt.foobar.com'
)
self
.
assertFalse
(
self
.
dialog
.
path_ok
())
self
.
assertEqual
(
showerror
.
title
,
'File Path Error'
)
self
.
assertIn
(
'not exist'
,
showerror
.
message
)
def
test_good_path
(
self
):
self
.
dialog
.
path
.
set
(
'https://docs.python.org'
)
showerror
.
title
=
'No Error'
# should not be called
self
.
assertTrue
(
self
.
dialog
.
path_ok
())
self
.
assertEqual
(
showerror
.
title
,
'No Error'
)
def
test_ok
(
self
):
self
.
dialog
.
destroyed
=
False
self
.
dialog
.
menu
.
set
(
'help'
)
self
.
dialog
.
path
.
set
(
'https://docs.python.org'
)
self
.
dialog
.
ok
()
self
.
assertEqual
(
self
.
dialog
.
result
,
(
'help'
,
'https://docs.python.org'
))
self
.
assertTrue
(
self
.
dialog
.
destroyed
)
def
test_cancel
(
self
):
self
.
dialog
.
destroyed
=
False
self
.
dialog
.
cancel
()
self
.
assertEqual
(
self
.
dialog
.
result
,
None
)
self
.
assertTrue
(
self
.
dialog
.
destroyed
)
if
__name__
==
'__main__'
:
unittest
.
main
(
verbosity
=
2
,
exit
=
False
)
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