Commit 84864fcb authored by Paul McCarthy's avatar Paul McCarthy
Browse files

More sleep should make tests pass

parent d3fdd4f4
......@@ -7,6 +7,8 @@
from __future__ import print_function
import time
import numpy as np
import wx
......@@ -87,6 +89,14 @@ def run_with_wx(func, *args, **kwargs):
return result[0]
# Under GTK, a single call to
# yield just doesn't cut it
def realYield():
for i in range(10):
wx.Yield()
time.sleep(0.01)
# stype:
# 0 for single click
# 1 for double click
......@@ -109,18 +119,18 @@ def simclick(sim, target, btn=wx.MOUSE_BTN_LEFT, pos=None, stype=0):
else:
sim.MouseDown(btn)
sim.MouseUp(btn)
wx.Yield()
realYield()
def simtext(sim, target, text, enter=True):
target.SetFocus()
target.SetValue(text)
if enter: sim.KeyDown(wx.WXK_RETURN)
wx.Yield()
realYield()
def simkey(sim, target, key, down=True, up=False):
if target is not None: target.SetFocus()
if down: sim.KeyDown(key)
if up: sim.KeyUp(key)
wx.Yield()
realYield()
......@@ -6,7 +6,7 @@
#
from . import run_with_wx, simclick
from . import run_with_wx, simclick, realYield
import wx
import fsleyes_widgets.autotextctrl as autott
......@@ -51,11 +51,12 @@ def _test_event():
atc.Bind(autott.EVT_ATC_TEXT_ENTER, handler)
atc.SetFocus()
realYield()
sim.Char(ord('a'))
sim.Char(ord('b'))
sim.Char(ord('c'))
sim.KeyDown(wx.WXK_RETURN)
wx.Yield()
realYield()
assert atc.GetValue() == 'abc'
assert called[0] == 'abc'
......@@ -94,13 +95,13 @@ def _test_popup_select1():
atc = autott.AutoTextCtrl(parent)
atc.AutoComplete(['aaa', 'aab', 'aba', 'bcc'])
atc.SetFocus()
sim.KeyDown(wx.WXK_RETURN)
realYield()
sim.KeyDown(wx.WXK_DOWN)
sim.KeyDown(wx.WXK_DOWN)
sim.KeyDown(wx.WXK_RETURN)
wx.Yield()
realYield()
assert atc.GetValue() == 'aab'
......@@ -118,9 +119,10 @@ def _test_popup_select2():
atc.SetFocus()
sim.Char(ord('b'))
realYield()
sim.KeyDown(wx.WXK_DOWN)
sim.KeyDown(wx.WXK_RETURN)
wx.Yield()
realYield()
assert atc.GetValue() == 'bcc'
......@@ -139,9 +141,10 @@ def _test_popup_select3():
atc.SetFocus()
sim.Char(ord('a'))
sim.Char(ord('b'))
realYield()
sim.KeyDown(wx.WXK_DOWN)
sim.KeyDown(wx.WXK_RETURN)
wx.Yield()
realYield()
assert atc.GetValue() == 'aba'
......@@ -159,9 +162,10 @@ def _test_popup_cancel():
atc.SetFocus()
sim.KeyDown(wx.WXK_RETURN)
realYield()
sim.KeyDown(wx.WXK_DOWN)
sim.KeyDown(wx.WXK_ESCAPE)
wx.Yield()
realYield()
assert atc.GetValue() == ''
......@@ -179,12 +183,14 @@ def _test_popup_focusback():
atc.SetFocus()
sim.KeyDown(wx.WXK_RETURN)
realYield()
sim.KeyDown(wx.WXK_DOWN)
sim.KeyDown(wx.WXK_UP)
realYield()
sim.Text('abc')
sim.KeyDown(wx.WXK_RETURN)
wx.Yield()
realYield()
assert atc.GetValue() == 'abc'
......@@ -200,10 +206,11 @@ def _test_popup_dblclick():
atc.SetFocus()
sim.KeyDown(wx.WXK_RETURN)
realYield()
# Sneakily get a ref to the listbox
# in the AutoCompletePopup
wx.Yield()
realYield()
listbox = None
for c in atc.GetChildren():
if isinstance(c, autott.AutoCompletePopup):
......@@ -214,6 +221,6 @@ def _test_popup_dblclick():
break
simclick(sim, listbox, stype=1, pos=[0.5, 0.05])
wx.Yield()
realYield()
assert atc.GetValue() == 'aaa'
......@@ -12,7 +12,7 @@ import wx
import mock
import pytest
from . import run_with_wx, simclick, simkey
from . import run_with_wx, simclick, simkey, realYield
import fsleyes_widgets.floatslider as floatslider
......@@ -345,6 +345,7 @@ def _test_SliderSpinPanel_events():
panel.SetRange(0, 100)
realYield()
simclick(sim, panel.slider, pos=[0.5, 0.5])
assert abs(panel.spinCtrl.GetValue() - 50) < 5
......
......@@ -16,7 +16,7 @@ from .test_floatslider import (_test_widget_logic,
_test_widget_logic_integer,
_test_widget_changeRange)
from . import run_with_wx, simclick, simtext
from . import run_with_wx, simclick, simtext, realYield
def test_FloatSpinCtrl_logic():
......@@ -188,6 +188,8 @@ def _test_FloatSpinCtrl_text():
( '25.42', 25.42),
]
realYield()
for text, expected in testcases:
oldValue = spin.GetValue()
......@@ -238,12 +240,14 @@ def _test_FloatSpinCtrl_KeyDownUp():
spin.textCtrl.SetFocus()
realYield()
for value, key, expected in testcases:
result[0] = None
spin.SetValue(value)
sim.KeyDown(key)
wx.Yield()
realYield()
assert spin.GetValue() == expected
......
......@@ -10,7 +10,7 @@ import wx
import fsleyes_widgets.numberdialog as numdlg
from . import run_with_wx, simclick, simtext, simkey
from . import run_with_wx, simclick, simtext, simkey, realYield
def test_NumberDialog_create():
......@@ -39,7 +39,7 @@ def _test_NumberDialog_create():
else: target = dlg.cancelButton
dlg.Show()
realYield()
simclick(sim, target)
assert dlg.GetValue() == expected
......@@ -92,13 +92,9 @@ def _test_NumberDialog_limit():
dlg.floatSpinCtrl.SetFocus()
dlg.floatSpinCtrl.textCtrl.ChangeValue(text)
realYield()
simkey(sim, dlg.floatSpinCtrl, wx.WXK_RETURN)
if needClick:
assert dlg.GetValue() is None
simclick(sim, dlg.okButton)
for i in range(5):
import time
time.sleep(0.02)
wx.Yield()
assert dlg.GetValue() == expected
......@@ -14,7 +14,7 @@ import pytest
import fsleyes_widgets.rangeslider as rangeslider
from . import run_with_wx, simclick, simtext, simkey
from . import run_with_wx, simclick, simtext, simkey, realYield
def _test_RangePanel_logic(panel):
......@@ -197,6 +197,8 @@ def _test_RangePanel_events_spin():
panel.SetRange(0, 100)
panel.SetDistance(5)
realYield()
panel.lowWidget.textCtrl.ChangeValue('25')
simkey(sim, panel.lowWidget, wx.WXK_RETURN)
assert np.all(np.isclose(panel.GetRange(), (25, 100)))
......@@ -266,6 +268,8 @@ def _test_RangeSliderSpinPanel_onchange():
panel.SetRange(0, 100)
panel.SetDistance(5)
realYield()
panel.lowSpin.textCtrl.ChangeValue('75')
simkey(sim, panel.lowSpin.textCtrl, wx.WXK_RETURN)
assert np.all(np.isclose(panel.GetRange(), (75, 100)))
......
......@@ -41,7 +41,7 @@ def _gen_dummy_script():
def test_ProcessManager_run():
path, expected = _gen_dummy_script()
cmd = ['sh', path]
cmd = ['bash', path]
result = [None]
finishArgs = [None]
......@@ -62,8 +62,9 @@ def test_ProcessManager_run():
os.remove(path)
assert finishArgs[0][1] == 0
assert expected in result[0]
assert finishArgs[0][1] == 0
def test_ProcessManager_termProc():
......@@ -99,7 +100,7 @@ def test_run():
import wx
path, expected = _gen_dummy_script()
cmd = ['sh', path]
cmd = ['bash', path]
finishArgs = [None]
def runTest():
......
......@@ -7,10 +7,11 @@
import wx
from . import run_with_wx, simclick, simtext, simkey
from . import run_with_wx, simclick, simtext, simkey, realYield
import fsleyes_widgets.texttag as tt
def test_StaticTextTag():
run_with_wx(_test_StaticTextTag)
def _test_StaticTextTag():
......@@ -23,13 +24,13 @@ def _test_StaticTextTag():
frame.SetSizer(sizer)
frame.Layout()
wx.Yield()
realYield()
assert tag.GetText() == ''
tag.SetText('TagText')
tag.SetBackgroundColour('#bb3333')
tag.SetBorderColour( '#3333bb')
wx.Yield()
realYield()
assert tag.GetText() == 'TagText'
dummy.SetFocus()
......@@ -157,6 +158,7 @@ def _test_TextTagPanel_nostyle():
panel.SetOptions(tags)
# Add an existing tag
realYield()
simtext(sim, panel.newTagCtrl, tags[0])
assert panel.GetTags() == [tags[0]]
assert result[0] == tags[0]
......@@ -227,6 +229,7 @@ def _test_TextTagPanel_allow_new_tags():
frame.SetSizer(sizer)
frame.Layout()
realYield()
simtext(sim, panel.newTagCtrl, 'MyNewTag')
assert panel.GetTags() == ['MyNewTag']
......@@ -246,6 +249,7 @@ def _test_TextTagPanel_add_new_tags():
frame.SetSizer(sizer)
frame.Layout()
realYield()
simtext(sim, panel.newTagCtrl, 'MyNewTag')
assert panel.GetTags() == ['MyNewTag']
......@@ -266,6 +270,7 @@ def _test_TextTagPanel_no_duplicates():
tags = ['Tag1', 'Tag2']
panel.SetOptions(tags)
realYield()
simtext(sim, panel.newTagCtrl, tags[0])
assert panel.GetTags() == [tags[0]]
......@@ -295,6 +300,7 @@ def _test_TextTagPanel_case_sensitive():
panel.SetOptions(tags)
assert panel.GetOptions() == tags
realYield()
for i in range(len(tags)):
simtext(sim, panel.newTagCtrl, tags[i])
assert panel.GetTags() == tags[:i + 1]
......@@ -331,7 +337,7 @@ def _test_TextTagPanel_mouse_focus():
panel.SetOptions(['tag1', 'tag2'])
panel.AddTag('tag1')
wx.Yield()
realYield()
simclick(sim, panel.tags[0].text)
assert result[0] == 'tag1'
......@@ -361,10 +367,12 @@ def _test_TextTagPanel_keyboard_nav():
panel.SetOptions(tags)
for t in tags:
panel.AddTag(t)
wx.Yield()
realYield()
panel.FocusNewTagCtrl()
realYield()
simkey(sim, panel.newTagCtrl, wx.WXK_LEFT)
assert result[0] is None
simkey(sim, panel.newTagCtrl, wx.WXK_RIGHT)
......@@ -412,7 +420,7 @@ def _test_TextTagPanel_keyboard_close():
panel.SetOptions(tags)
for t in tags:
panel.AddTag(t)
wx.Yield()
realYield()
# Give a tag focus
simclick(sim, panel.tags[0], stype=2)
......
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