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
b6ff188d
Commit
b6ff188d
authored
Apr 28, 2017
by
Paul McCarthy
Browse files
Unit tests for bitmaptoggle module, and another atc test
parent
cdc31116
Changes
5
Hide whitespace changes
Inline
Side-by-side
tests/__init__.py
View file @
b6ff188d
...
...
@@ -7,13 +7,9 @@
from
__future__
import
print_function
import
numpy
as
np
import
logging
logging
.
getLogger
(
'PIL'
).
setLevel
(
logging
.
INFO
)
import
wx
def
compare_images
(
img1
,
img2
,
threshold
):
"""Compares two images using the euclidean distance in RGB space
...
...
@@ -54,8 +50,6 @@ def run_with_wx(func, *args, **kwargs):
finishingDelay
=
kwargs
.
pop
(
'finishingDelay'
,
500
)
callAfterApp
=
kwargs
.
pop
(
'callAfterApp'
,
None
)
import
wx
result
=
[
None
]
raised
=
[
None
]
...
...
@@ -91,3 +85,13 @@ def run_with_wx(func, *args, **kwargs):
raise
raised
[
0
]
return
result
[
0
]
def
simclick
(
sim
,
target
,
btn
=
wx
.
MOUSE_BTN_LEFT
,
double
=
False
):
x
,
y
=
target
.
GetScreenPosition
()
sim
.
MouseMove
(
x
+
10
,
y
+
10
)
wx
.
Yield
()
if
double
:
sim
.
MouseDblClick
(
btn
)
else
:
sim
.
MouseClick
(
btn
)
wx
.
Yield
()
tests/test_autotextctrl.py
View file @
b6ff188d
...
...
@@ -6,7 +6,7 @@
#
from
.
import
run_with_wx
from
.
import
run_with_wx
,
simclick
import
wx
import
fsleyes_widgets.autotextctrl
as
autott
...
...
@@ -22,9 +22,9 @@ def sendEvent(target, evType, source=None):
# Simple test - programmatically
# set, then retrieve the value
def
test_
AutoTextCtrl_
getSet
():
run_with_wx
(
_test_
AutoTextCtrl_
getSet
)
def
_test_
AutoTextCtrl_
getSet
():
def
test_getSet
():
run_with_wx
(
_test_getSet
)
def
_test_getSet
():
parent
=
wx
.
GetApp
().
GetTopWindow
()
atc
=
autott
.
AutoTextCtrl
(
parent
)
...
...
@@ -36,9 +36,9 @@ def _test_AutoTextCtrl_getSet():
assert
atc
.
GetValue
()
==
'b'
def
test_
AutoTextCtrl_
event
():
run_with_wx
(
_test_
AutoTextCtrl_
event
)
def
_test_
AutoTextCtrl_
event
():
def
test_event
():
run_with_wx
(
_test_event
)
def
_test_event
():
called
=
[
None
]
...
...
@@ -63,9 +63,9 @@ def _test_AutoTextCtrl_event():
# 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
():
def
test_onFocus
():
run_with_wx
(
_test_onFocus
)
def
_test_onFocus
():
parent
=
wx
.
GetApp
().
GetTopWindow
()
atc
=
autott
.
AutoTextCtrl
(
parent
)
...
...
@@ -84,9 +84,9 @@ def _test_AutoTextCtrl_onFocus():
# 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
():
def
test_popup_select1
():
run_with_wx
(
_test_popup_select1
)
def
_test_popup_select1
():
sim
=
wx
.
UIActionSimulator
()
...
...
@@ -105,9 +105,9 @@ def _test_AutoTextCtrl_popup_select1():
assert
atc
.
GetValue
()
==
'aab'
def
test_
AutoTextCtrl_
popup_select2
():
run_with_wx
(
_test_
AutoTextCtrl_
popup_select2
)
def
_test_
AutoTextCtrl_
popup_select2
():
def
test_popup_select2
():
run_with_wx
(
_test_popup_select2
)
def
_test_popup_select2
():
sim
=
wx
.
UIActionSimulator
()
...
...
@@ -125,9 +125,9 @@ def _test_AutoTextCtrl_popup_select2():
assert
atc
.
GetValue
()
==
'bcc'
def
test_
AutoTextCtrl_
popup_select3
():
run_with_wx
(
_test_
AutoTextCtrl_
popup_select3
)
def
_test_
AutoTextCtrl_
popup_select3
():
def
test_popup_select3
():
run_with_wx
(
_test_popup_select3
)
def
_test_popup_select3
():
sim
=
wx
.
UIActionSimulator
()
...
...
@@ -146,9 +146,9 @@ def _test_AutoTextCtrl_popup_select3():
assert
atc
.
GetValue
()
==
'aba'
def
test_
AutoTextCtrl_
popup_cancel
():
run_with_wx
(
_test_
AutoTextCtrl_
popup_cancel
)
def
_test_
AutoTextCtrl_
popup_cancel
():
def
test_popup_cancel
():
run_with_wx
(
_test_popup_cancel
)
def
_test_popup_cancel
():
sim
=
wx
.
UIActionSimulator
()
...
...
@@ -166,9 +166,9 @@ def _test_AutoTextCtrl_popup_cancel():
assert
atc
.
GetValue
()
==
''
def
test_
AutoTextCtrl_
popup_focusback
():
run_with_wx
(
_test_
AutoTextCtrl_
popup_focusback
)
def
_test_
AutoTextCtrl_
popup_focusback
():
def
test_popup_focusback
():
run_with_wx
(
_test_popup_focusback
)
def
_test_popup_focusback
():
sim
=
wx
.
UIActionSimulator
()
...
...
@@ -187,3 +187,33 @@ def _test_AutoTextCtrl_popup_focusback():
wx
.
Yield
()
assert
atc
.
GetValue
()
==
'abc'
def
test_popup_dblclick
():
run_with_wx
(
_test_popup_dblclick
)
def
_test_popup_dblclick
():
sim
=
wx
.
UIActionSimulator
()
parent
=
wx
.
GetApp
().
GetTopWindow
()
atc
=
autott
.
AutoTextCtrl
(
parent
)
atc
.
AutoComplete
([
'aaa'
,
'aab'
,
'aba'
,
'bcc'
])
atc
.
SetFocus
()
sim
.
KeyDown
(
wx
.
WXK_RETURN
)
# Sneakily get a ref to the listbox
# in the AutoCompletePopup
wx
.
Yield
()
listbox
=
None
for
c
in
atc
.
GetChildren
():
if
isinstance
(
c
,
autott
.
AutoCompletePopup
):
for
pc
in
c
.
GetChildren
():
if
isinstance
(
pc
,
wx
.
ListBox
):
listbox
=
pc
break
simclick
(
sim
,
listbox
,
double
=
True
)
wx
.
Yield
()
assert
atc
.
GetValue
()
==
'aaa'
tests/test_bitmaptoggle.py
0 → 100644
View file @
b6ff188d
#!/usr/bin/env python
#
# test_bitmaptoggle.py -
#
# Author: Paul McCarthy <pauldmccarthy@gmail.com>
#
import
os.path
as
op
import
wx
import
fsleyes_widgets.bitmaptoggle
as
bmptoggle
from
.
import
run_with_wx
,
simclick
datadir
=
op
.
join
(
op
.
dirname
(
__file__
),
'testdata'
,
'bitmapbuttons'
)
def
test_Create
():
run_with_wx
(
_test_Create
)
def
_test_Create
():
frame
=
wx
.
GetApp
().
GetTopWindow
()
falseicon
=
op
.
join
(
datadir
,
'false.png'
)
trueicon
=
op
.
join
(
datadir
,
'true.png'
)
falseicon
=
wx
.
Bitmap
(
falseicon
,
wx
.
BITMAP_TYPE_PNG
)
trueicon
=
wx
.
Bitmap
(
trueicon
,
wx
.
BITMAP_TYPE_PNG
)
btn
=
bmptoggle
.
BitmapToggleButton
(
frame
)
btn
=
bmptoggle
.
BitmapToggleButton
(
frame
,
trueBmp
=
trueicon
)
btn
=
bmptoggle
.
BitmapToggleButton
(
frame
,
trueBmp
=
trueicon
,
falseBmp
=
falseicon
)
btn
=
bmptoggle
.
BitmapToggleButton
(
frame
)
btn
.
SetBitmap
(
trueicon
)
btn
.
SetBitmap
(
trueicon
,
falseicon
)
def
test_SetGet
():
run_with_wx
(
_test_SetGet
)
def
_test_SetGet
():
frame
=
wx
.
GetApp
().
GetTopWindow
()
btn
=
bmptoggle
.
BitmapToggleButton
(
frame
)
btn
.
SetValue
(
True
)
assert
btn
.
GetValue
()
btn
.
SetValue
(
False
)
assert
not
btn
.
GetValue
()
def
test_Toggle
():
run_with_wx
(
_test_Toggle
)
def
_test_Toggle
():
falseicon
=
op
.
join
(
datadir
,
'false.png'
)
trueicon
=
op
.
join
(
datadir
,
'true.png'
)
falseicon
=
wx
.
Bitmap
(
falseicon
,
wx
.
BITMAP_TYPE_PNG
)
trueicon
=
wx
.
Bitmap
(
trueicon
,
wx
.
BITMAP_TYPE_PNG
)
sim
=
wx
.
UIActionSimulator
()
frame
=
wx
.
GetApp
().
GetTopWindow
()
btn
=
bmptoggle
.
BitmapToggleButton
(
frame
)
btn
.
SetBitmap
(
trueicon
,
falseicon
)
assert
not
btn
.
GetValue
()
simclick
(
sim
,
btn
)
assert
btn
.
GetValue
()
def
test_Event
():
run_with_wx
(
_test_Event
)
def
_test_Event
():
trueicon
=
op
.
join
(
datadir
,
'true.png'
)
trueicon
=
wx
.
Bitmap
(
trueicon
,
wx
.
BITMAP_TYPE_PNG
)
sim
=
wx
.
UIActionSimulator
()
frame
=
wx
.
GetApp
().
GetTopWindow
()
btn
=
bmptoggle
.
BitmapToggleButton
(
frame
)
btn
.
SetBitmap
(
trueicon
)
result
=
[
None
]
def
handler
(
ev
):
result
[
0
]
=
ev
.
value
btn
.
Bind
(
bmptoggle
.
EVT_BITMAP_TOGGLE
,
handler
)
simclick
(
sim
,
btn
)
assert
result
[
0
]
simclick
(
sim
,
btn
)
assert
not
result
[
0
]
tests/testdata/bitmapbuttons/false.png
0 → 100644
View file @
b6ff188d
1.26 KB
tests/testdata/bitmapbuttons/true.png
0 → 100644
View file @
b6ff188d
3.52 KB
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