Files
scikit-image/skimage/viewer/tests/test_tools.py
T
Jonathan Helmus 78a0eb6b98 Implement appveyor builds
Implement Appveyor builds

initial test

Updated appveyor.yml

New nosetest call

With conda update conda

with pillow

without pillow

TST: Change case sensitivive JPG extension

Revert "TST: Change case sensitivive JPG extension"

This reverts commit 2deed7cc63736f7c6f0387bd37df4c6643c32847.

Trying with Python 2.7

Trying with version env

Trying again with variables

Testing on all Python versions

don't allow failures

Allow failure

Do not actually use tests

Ignore failing tests

Removed Python 2.6 test

Testing only Python 2.6

Testing out more sklearn like AppVeyor CI

Added install to pip

Add artifacts

Enabled all permutations

Disable 2.6, add PIL

Python 2.6, 2.7 only with PIL

Testing with variable dependencies

Allow failure with IF ELSE

With Python 3.4

Scikit-learn like appveyor CI

Fixing paths

Undo path fix

path fix single line

path fix single line 2

Using Miniconda

More path fixes

New wheelhouse link

Added pillow to requirements.txt

Added networkx to requirements.txt

Add testing of 32/64-bit Python 2.7 and 3.4 to matrix

Debugging Cython compile

Retry with all 4 builds

Updated install.ps1 file

Updated based on latest python-appveyor-demo

Debugging pip install

Specify numpy 1.8.1 until whl is uploaded to rackspace

Use skimage-wide requirements.txt file

Minor comment change to trigger build

Install wheel and then install from WHEELHOUSE

Install six from pip

Install networkx from pip

Install pyparsing from pip

Install pytz from pip

Try using just find-links

Install the binary dependencies first, then the rest

Add pillow to the install list

Fix appveyor.yml syntax

Fix requirements.txt syntax

Fix requirements.txt syntax again

Fix appveyor call to initial install

Fix appveyor call to initial install again

Fix appveyor call to initial install yet again

Install wheel

Install wheel first

Install wheel and nose in the appveyor requirements.txt

Fix Python3 version to match python ftp site

Only use cleanup decorator if available

Add debug info to multiimage test

More debugging information

Fix handling of path separators on Windows

Add another warning guard

Fix warning handling for non-windows

Do not use TkAgg as it may be causing alloc error

Clean up echo command

Allow for unclosed file warning

Fix spacing in echo command
2015-02-28 19:57:45 -06:00

210 lines
5.5 KiB
Python

from collections import namedtuple
import numpy as np
from numpy.testing import assert_equal
from numpy.testing.decorators import skipif
from skimage import data
from skimage.viewer import ImageViewer, has_qt
from skimage.viewer.canvastools import (
LineTool, ThickLineTool, RectangleTool, PaintTool)
from skimage.viewer.canvastools.base import CanvasToolBase
try:
from matplotlib.testing.decorators import cleanup
except ImportError:
def cleanup(func):
return func
def get_end_points(image):
h, w = image.shape[0:2]
x = [w / 3, 2 * w / 3]
y = [h / 2] * 2
return np.transpose([x, y])
def do_event(viewer, etype, button=1, xdata=0, ydata=0, key=None):
"""
*name*
the event name
*canvas*
the FigureCanvas instance generating the event
*guiEvent*
the GUI event that triggered the matplotlib event
*x*
x position - pixels from left of canvas
*y*
y position - pixels from bottom of canvas
*inaxes*
the :class:`~matplotlib.axes.Axes` instance if mouse is over axes
*xdata*
x coord of mouse in data coords
*ydata*
y coord of mouse in data coords
*button*
button pressed None, 1, 2, 3, 'up', 'down' (up and down are used
for scroll events)
*key*
the key depressed when the mouse event triggered (see
:class:`KeyEvent`)
*step*
number of scroll steps (positive for 'up', negative for 'down')
"""
ax = viewer.ax
event = namedtuple('Event',
('name canvas guiEvent x y inaxes xdata ydata '
'button key step'))
event.button = button
event.x, event.y = ax.transData.transform((xdata, ydata))
event.xdata, event.ydata = xdata, ydata
event.inaxes = ax
event.canvas = ax.figure.canvas
event.key = key
event.step = 1
event.guiEvent = None
event.name = 'Custom'
func = getattr(viewer._event_manager, 'on_%s' % etype)
func(event)
@cleanup
@skipif(not has_qt)
def test_line_tool():
img = data.camera()
viewer = ImageViewer(img)
tool = LineTool(viewer, maxdist=10, line_props=dict(linewidth=3),
handle_props=dict(markersize=5))
tool.end_points = get_end_points(img)
assert_equal(tool.end_points, np.array([[170, 256], [341, 256]]))
# grab a handle and move it
do_event(viewer, 'mouse_press', xdata=170, ydata=256)
do_event(viewer, 'move', xdata=180, ydata=260)
do_event(viewer, 'mouse_release')
assert_equal(tool.geometry, np.array([[180, 260], [341, 256]]))
# create a new line
do_event(viewer, 'mouse_press', xdata=10, ydata=10)
do_event(viewer, 'move', xdata=100, ydata=100)
do_event(viewer, 'mouse_release')
assert_equal(tool.geometry, np.array([[100, 100], [10, 10]]))
@cleanup
@skipif(not has_qt)
def test_thick_line_tool():
img = data.camera()
viewer = ImageViewer(img)
tool = ThickLineTool(viewer, maxdist=10, line_props=dict(color='red'),
handle_props=dict(markersize=5))
tool.end_points = get_end_points(img)
do_event(viewer, 'scroll', button='up')
assert_equal(tool.linewidth, 2)
do_event(viewer, 'scroll', button='down')
assert_equal(tool.linewidth, 1)
do_event(viewer, 'key_press', key='+')
assert_equal(tool.linewidth, 2)
do_event(viewer, 'key_press', key='-')
assert_equal(tool.linewidth, 1)
@cleanup
@skipif(not has_qt)
def test_rect_tool():
img = data.camera()
viewer = ImageViewer(img)
tool = RectangleTool(viewer, maxdist=10)
tool.extents = (100, 150, 100, 150)
assert_equal(tool.corners,
((100, 150, 150, 100), (100, 100, 150, 150)))
assert_equal(tool.extents, (100, 150, 100, 150))
assert_equal(tool.edge_centers,
((100, 125.0, 150, 125.0), (125.0, 100, 125.0, 150)))
assert_equal(tool.geometry, (100, 150, 100, 150))
# grab a corner and move it
do_event(viewer, 'mouse_press', xdata=100, ydata=100)
do_event(viewer, 'move', xdata=120, ydata=120)
do_event(viewer, 'mouse_release')
assert_equal(tool.geometry, [120, 150, 120, 150])
# create a new line
do_event(viewer, 'mouse_press', xdata=10, ydata=10)
do_event(viewer, 'move', xdata=100, ydata=100)
do_event(viewer, 'mouse_release')
assert_equal(tool.geometry, [10, 100, 10, 100])
@cleanup
@skipif(not has_qt)
def test_paint_tool():
img = data.moon()
viewer = ImageViewer(img)
tool = PaintTool(viewer, img.shape)
tool.radius = 10
assert_equal(tool.radius, 10)
tool.label = 2
assert_equal(tool.label, 2)
assert_equal(tool.shape, img.shape)
do_event(viewer, 'mouse_press', xdata=100, ydata=100)
do_event(viewer, 'move', xdata=110, ydata=110)
do_event(viewer, 'mouse_release')
assert_equal(tool.overlay[tool.overlay == 2].size, 761)
tool.label = 5
do_event(viewer, 'mouse_press', xdata=20, ydata=20)
do_event(viewer, 'move', xdata=40, ydata=40)
do_event(viewer, 'mouse_release')
assert_equal(tool.overlay[tool.overlay == 5].size, 881)
assert_equal(tool.overlay[tool.overlay == 2].size, 761)
do_event(viewer, 'key_press', key='enter')
tool.overlay = tool.overlay * 0
assert_equal(tool.overlay.sum(), 0)
@cleanup
@skipif(not has_qt)
def test_base_tool():
img = data.moon()
viewer = ImageViewer(img)
tool = CanvasToolBase(viewer)
tool.set_visible(False)
tool.set_visible(True)
do_event(viewer, 'key_press', key='enter')
tool.redraw()
tool.remove()
tool = CanvasToolBase(viewer, useblit=False)
tool.redraw()