Skip to content
GitLab
Menu
Projects
Groups
Snippets
Help
Help
Support
Community forum
Keyboard shortcuts
?
Submit feedback
Contribute to GitLab
Sign in
Toggle navigation
Menu
Open sidebar
FSL
fsleyes
fsleyes-widgets
Commits
ca6b60fb
Commit
ca6b60fb
authored
Apr 28, 2017
by
Paul McCarthy
Browse files
Unit tests for autotextctrl module
parent
0cdbf68c
Changes
2
Hide whitespace changes
Inline
Side-by-side
tests/__init__.py
View file @
ca6b60fb
...
...
@@ -45,3 +45,49 @@ def compare_images(img1, img2, threshold):
passed
=
ttlDiff
<=
threshold
return
passed
,
ttlDiff
def
run_with_wx
(
func
,
*
args
,
**
kwargs
):
propagateRaise
=
kwargs
.
pop
(
'propagateRaise'
,
True
)
startingDelay
=
kwargs
.
pop
(
'startingDelay'
,
500
)
finishingDelay
=
kwargs
.
pop
(
'finishingDelay'
,
500
)
callAfterApp
=
kwargs
.
pop
(
'callAfterApp'
,
None
)
import
wx
result
=
[
None
]
raised
=
[
None
]
app
=
wx
.
App
()
frame
=
wx
.
Frame
(
None
)
if
callAfterApp
is
not
None
:
callAfterApp
()
def
wrap
():
try
:
if
func
is
not
None
:
result
[
0
]
=
func
(
*
args
,
**
kwargs
)
except
Exception
as
e
:
print
(
e
)
raised
[
0
]
=
e
finally
:
def
finish
():
frame
.
Destroy
()
app
.
ExitMainLoop
()
wx
.
CallLater
(
finishingDelay
,
finish
)
frame
.
Show
()
wx
.
CallLater
(
startingDelay
,
wrap
)
app
.
MainLoop
()
if
raised
[
0
]
and
propagateRaise
:
raise
raised
[
0
]
return
result
[
0
]
tests/test_autotextctrl.py
0 → 100644
View file @
ca6b60fb
#!/usr/bin/env python
#
# test_autotextctrl.py -
#
# Author: Paul McCarthy <pauldmccarthy@gmail.com>
#
from
.
import
run_with_wx
import
wx
import
fsleyes_widgets.autotextctrl
as
autott
def
sendEvent
(
target
,
evType
,
source
=
None
):
if
source
is
None
:
source
=
target
target
.
ProcessEvent
(
wx
.
CommandEvent
(
evType
,
source
.
GetId
()))
wx
.
Yield
()
# Simple test - programmatically
# set, then retrieve the value
def
test_AutoTextCtrl_getSet
():
run_with_wx
(
_test_AutoTextCtrl_getSet
)
def
_test_AutoTextCtrl_getSet
():
parent
=
wx
.
GetApp
().
GetTopWindow
()
atc
=
autott
.
AutoTextCtrl
(
parent
)
atc
.
ChangeValue
(
'a'
)
assert
atc
.
GetValue
()
==
'a'
atc
.
SetValue
(
'b'
)
assert
atc
.
GetValue
()
==
'b'
# Make sure that when the cotrol receives
# focus, its insertion point is at the end
def
test_AutoTextCtrl_onFocus
():
run_with_wx
(
_test_AutoTextCtrl_onFocus
)
def
_test_AutoTextCtrl_onFocus
():
parent
=
wx
.
GetApp
().
GetTopWindow
()
atc
=
autott
.
AutoTextCtrl
(
parent
)
atc
.
AutoComplete
([
'aaa'
,
'aab'
,
'aba'
,
'bcc'
])
atc
.
ChangeValue
(
'a'
)
atc
.
SetInsertionPoint
(
0
)
sendEvent
(
atc
,
wx
.
wxEVT_KILL_FOCUS
)
assert
atc
.
GetInsertionPoint
()
==
0
sendEvent
(
atc
,
wx
.
wxEVT_SET_FOCUS
)
assert
atc
.
GetInsertionPoint
()
==
1
# Test showing the popup and selecting a value
def
test_AutoTextCtrl_popup_select1
():
run_with_wx
(
_test_AutoTextCtrl_popup_select1
)
def
_test_AutoTextCtrl_popup_select1
():
sim
=
wx
.
UIActionSimulator
()
parent
=
wx
.
GetApp
().
GetTopWindow
()
atc
=
autott
.
AutoTextCtrl
(
parent
)
atc
.
AutoComplete
([
'aaa'
,
'aab'
,
'aba'
,
'bcc'
])
atc
.
SetFocus
()
sim
.
KeyDown
(
wx
.
WXK_RETURN
)
sim
.
KeyDown
(
wx
.
WXK_DOWN
)
sim
.
KeyDown
(
wx
.
WXK_DOWN
)
sim
.
KeyDown
(
wx
.
WXK_RETURN
)
wx
.
Yield
()
assert
atc
.
GetValue
()
==
'aab'
def
test_AutoTextCtrl_popup_select2
():
run_with_wx
(
_test_AutoTextCtrl_popup_select2
)
def
_test_AutoTextCtrl_popup_select2
():
sim
=
wx
.
UIActionSimulator
()
parent
=
wx
.
GetApp
().
GetTopWindow
()
atc
=
autott
.
AutoTextCtrl
(
parent
)
atc
.
AutoComplete
([
'aaa'
,
'aab'
,
'aba'
,
'bcc'
])
atc
.
SetFocus
()
sim
.
Char
(
ord
(
'b'
))
sim
.
KeyDown
(
wx
.
WXK_DOWN
)
sim
.
KeyDown
(
wx
.
WXK_RETURN
)
wx
.
Yield
()
assert
atc
.
GetValue
()
==
'bcc'
def
test_AutoTextCtrl_popup_select3
():
run_with_wx
(
_test_AutoTextCtrl_popup_select3
)
def
_test_AutoTextCtrl_popup_select3
():
sim
=
wx
.
UIActionSimulator
()
parent
=
wx
.
GetApp
().
GetTopWindow
()
atc
=
autott
.
AutoTextCtrl
(
parent
)
atc
.
AutoComplete
([
'aaa'
,
'aab'
,
'aba'
,
'bcc'
])
atc
.
SetFocus
()
sim
.
Char
(
ord
(
'a'
))
sim
.
Char
(
ord
(
'b'
))
sim
.
KeyDown
(
wx
.
WXK_DOWN
)
sim
.
KeyDown
(
wx
.
WXK_RETURN
)
wx
.
Yield
()
assert
atc
.
GetValue
()
==
'aba'
def
test_AutoTextCtrl_popup_cancel
():
run_with_wx
(
_test_AutoTextCtrl_popup_cancel
)
def
_test_AutoTextCtrl_popup_cancel
():
sim
=
wx
.
UIActionSimulator
()
parent
=
wx
.
GetApp
().
GetTopWindow
()
atc
=
autott
.
AutoTextCtrl
(
parent
)
atc
.
AutoComplete
([
'aaa'
,
'aab'
,
'aba'
,
'bcc'
])
atc
.
SetFocus
()
sim
.
KeyDown
(
wx
.
WXK_RETURN
)
sim
.
KeyDown
(
wx
.
WXK_DOWN
)
sim
.
KeyDown
(
wx
.
WXK_ESCAPE
)
wx
.
Yield
()
assert
atc
.
GetValue
()
==
''
def
test_AutoTextCtrl_popup_focusback
():
run_with_wx
(
_test_AutoTextCtrl_popup_focusback
)
def
_test_AutoTextCtrl_popup_focusback
():
sim
=
wx
.
UIActionSimulator
()
parent
=
wx
.
GetApp
().
GetTopWindow
()
atc
=
autott
.
AutoTextCtrl
(
parent
)
atc
.
AutoComplete
([
'aaa'
,
'aab'
,
'aba'
,
'bcc'
])
atc
.
SetFocus
()
sim
.
KeyDown
(
wx
.
WXK_RETURN
)
sim
.
KeyDown
(
wx
.
WXK_DOWN
)
sim
.
KeyDown
(
wx
.
WXK_UP
)
sim
.
Text
(
'abc'
)
sim
.
KeyDown
(
wx
.
WXK_RETURN
)
wx
.
Yield
()
assert
atc
.
GetValue
()
==
'abc'
Write
Preview
Supports
Markdown
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