Commit 28eccd95 authored by Paul McCarthy's avatar Paul McCarthy 🚵
Browse files

TEST: can't trust uiactionsim

parent 7ae05772
...@@ -112,6 +112,27 @@ def simclick(sim, target, btn=wx.MOUSE_BTN_LEFT, pos=None, stype=0): ...@@ -112,6 +112,27 @@ def simclick(sim, target, btn=wx.MOUSE_BTN_LEFT, pos=None, stype=0):
realYield() 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): def simtext(sim, target, text, enter=True):
target.SetFocus() target.SetFocus()
......
...@@ -8,7 +8,7 @@ ...@@ -8,7 +8,7 @@
import wx import wx
import numpy as np 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_props as props
import fsleyes_widgets.floatspin as floatspin import fsleyes_widgets.floatspin as floatspin
...@@ -31,8 +31,6 @@ class MyObj(props.HasProperties): ...@@ -31,8 +31,6 @@ class MyObj(props.HasProperties):
def test_widget_number(): run_with_wx(_test_widget_number) def test_widget_number(): run_with_wx(_test_widget_number)
def _test_widget_number(parent): def _test_widget_number(parent):
sim = wx.UIActionSimulator()
obj = MyObj() obj = MyObj()
myinto = props.makeWidget(parent, obj, 'myinto') myinto = props.makeWidget(parent, obj, 'myinto')
...@@ -57,10 +55,21 @@ def _test_widget_number(parent): ...@@ -57,10 +55,21 @@ def _test_widget_number(parent):
assert myintc .GetValue() == 25 assert myintc .GetValue() == 25
assert np.isclose(myrealc.GetValue(), 0.5) assert np.isclose(myrealc.GetValue(), 0.5)
simtext( sim, myinto .textCtrl, '10') # I used to use wx.UIActionSimulator, but
simtext( sim, myrealo.textCtrl, '243.56') # it is too flaky. So am now simulating
simtext( sim, myintc.spinCtrl.textCtrl, '99') # user events by directly calling value
simclick(sim, myrealc, pos=(0.75, 0.5)) # 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 obj.myinto == 10
assert np.isclose(obj.myrealo, 243.56) assert np.isclose(obj.myrealo, 243.56)
......
...@@ -12,7 +12,7 @@ import fsleyes_props as props ...@@ -12,7 +12,7 @@ import fsleyes_props as props
import fsleyes_widgets.floatslider as floatslider 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(): def setup_module():
...@@ -72,6 +72,9 @@ def _test_widget_point(parent): ...@@ -72,6 +72,9 @@ def _test_widget_point(parent):
val = np.random.randint(0, 100) 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 assert abs(getattr(getattr(obj, prop), att) - val) < 10
Supports Markdown
0% or .
You are about to add 0 people to the discussion. Proceed with caution.
Finish editing this message first!
Please register or to comment