Commit b6ff188d authored by Paul McCarthy's avatar Paul McCarthy
Browse files

Unit tests for bitmaptoggle module, and another atc test

parent cdc31116
......@@ -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()
......@@ -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'
#!/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]
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