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-props
Commits
28eccd95
Commit
28eccd95
authored
May 22, 2020
by
Paul McCarthy
🚵
Browse files
TEST: can't trust uiactionsim
parent
7ae05772
Changes
3
Hide whitespace changes
Inline
Side-by-side
tests/__init__.py
View file @
28eccd95
...
...
@@ -112,6 +112,27 @@ def simclick(sim, target, btn=wx.MOUSE_BTN_LEFT, pos=None, stype=0):
realYield
()
class
MockMouseEvent
:
def
__init__
(
self
,
target
,
pos
=
None
):
w
,
h
=
target
.
GetClientSize
().
Get
()
if
pos
is
None
:
pos
=
[
0.5
,
0.5
]
self
.
x
=
w
*
pos
[
0
]
self
.
y
=
h
*
pos
[
1
]
def
GetX
(
self
):
return
self
.
x
def
GetY
(
self
):
return
self
.
y
def
simtext
(
sim
,
target
,
text
,
enter
=
True
):
target
.
SetFocus
()
...
...
tests/test_widget_number.py
View file @
28eccd95
...
...
@@ -8,7 +8,7 @@
import
wx
import
numpy
as
np
from
.
import
(
run_with_wx
,
simtext
,
simclick
,
addall
)
from
.
import
(
run_with_wx
,
addall
,
MockMouseEvent
,
realYield
)
import
fsleyes_props
as
props
import
fsleyes_widgets.floatspin
as
floatspin
...
...
@@ -31,8 +31,6 @@ class MyObj(props.HasProperties):
def
test_widget_number
():
run_with_wx
(
_test_widget_number
)
def
_test_widget_number
(
parent
):
sim
=
wx
.
UIActionSimulator
()
obj
=
MyObj
()
myinto
=
props
.
makeWidget
(
parent
,
obj
,
'myinto'
)
...
...
@@ -57,10 +55,21 @@ def _test_widget_number(parent):
assert
myintc
.
GetValue
()
==
25
assert
np
.
isclose
(
myrealc
.
GetValue
(),
0.5
)
simtext
(
sim
,
myinto
.
textCtrl
,
'10'
)
simtext
(
sim
,
myrealo
.
textCtrl
,
'243.56'
)
simtext
(
sim
,
myintc
.
spinCtrl
.
textCtrl
,
'99'
)
simclick
(
sim
,
myrealc
,
pos
=
(
0.75
,
0.5
))
# I used to use wx.UIActionSimulator, but
# it is too flaky. So am now simulating
# user events by directly calling value
# setters/event handlers
myinto
.
textCtrl
.
SetValue
(
'10'
)
myinto
.
_FloatSpinCtrl__onText
(
None
)
myrealo
.
textCtrl
.
SetValue
(
'243.56'
)
myrealo
.
_FloatSpinCtrl__onText
(
None
)
myintc
.
spinCtrl
.
textCtrl
.
SetValue
(
'99'
)
myintc
.
spinCtrl
.
_FloatSpinCtrl__onText
(
None
)
ev
=
MockMouseEvent
(
myrealc
,
(
0.75
,
0.5
))
myrealc
.
_FloatSlider__onMouseDown
(
ev
)
myrealc
.
_FloatSlider__onMouseUp
(
ev
)
realYield
()
assert
obj
.
myinto
==
10
assert
np
.
isclose
(
obj
.
myrealo
,
243.56
)
...
...
tests/test_widget_point.py
View file @
28eccd95
...
...
@@ -12,7 +12,7 @@ import fsleyes_props as props
import
fsleyes_widgets.floatslider
as
floatslider
from
.
import
(
run_with_wx
,
simtext
,
simclick
,
addall
,
realYield
)
from
.
import
(
run_with_wx
,
MockMouseEvent
,
addall
,
realYield
)
def
setup_module
():
...
...
@@ -72,6 +72,9 @@ def _test_widget_point(parent):
val
=
np
.
random
.
randint
(
0
,
100
)
simclick
(
sim
,
widget
.
slider
,
pos
=
(
val
/
100.0
,
0.5
))
ev
=
MockMouseEvent
(
widget
.
slider
,
(
val
/
100.0
,
0.5
))
widget
.
slider
.
_FloatSlider__onMouseDown
(
ev
)
widget
.
slider
.
_FloatSlider__onMouseUp
(
ev
)
realYield
()
assert
abs
(
getattr
(
getattr
(
obj
,
prop
),
att
)
-
val
)
<
10
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