Fixed database typo and removed unnecessary class identifier.
This commit is contained in:
parent
00ad49a143
commit
45fb349a7d
5098 changed files with 952558 additions and 85 deletions
9
venv/Lib/site-packages/skimage/viewer/tests/__init__.py
Normal file
9
venv/Lib/site-packages/skimage/viewer/tests/__init__.py
Normal file
|
@ -0,0 +1,9 @@
|
|||
from ..._shared.testing import setup_test, teardown_test
|
||||
|
||||
|
||||
def setup():
|
||||
setup_test()
|
||||
|
||||
|
||||
def teardown():
|
||||
teardown_test()
|
Binary file not shown.
Binary file not shown.
Binary file not shown.
Binary file not shown.
Binary file not shown.
Binary file not shown.
181
venv/Lib/site-packages/skimage/viewer/tests/test_plugins.py
Normal file
181
venv/Lib/site-packages/skimage/viewer/tests/test_plugins.py
Normal file
|
@ -0,0 +1,181 @@
|
|||
import numpy as np
|
||||
from skimage import util
|
||||
import skimage.data as data
|
||||
from skimage.filters.rank import median
|
||||
from skimage.morphology import disk
|
||||
from skimage.viewer import ImageViewer, has_qt
|
||||
from skimage.viewer.plugins.base import Plugin
|
||||
from skimage.viewer.widgets import Slider
|
||||
from skimage.viewer.plugins import (
|
||||
LineProfile, Measure, CannyPlugin, LabelPainter, Crop, ColorHistogram,
|
||||
PlotPlugin)
|
||||
|
||||
from skimage._shared import testing
|
||||
from skimage._shared.testing import (assert_equal, assert_allclose,
|
||||
assert_almost_equal)
|
||||
|
||||
|
||||
def setup_line_profile(image, limits='image'):
|
||||
viewer = ImageViewer(util.img_as_float(image))
|
||||
plugin = LineProfile(limits=limits)
|
||||
viewer += plugin
|
||||
return plugin
|
||||
|
||||
|
||||
@testing.skipif(not has_qt, reason="Qt not installed")
|
||||
def test_line_profile():
|
||||
""" Test a line profile using an ndim=2 image"""
|
||||
plugin = setup_line_profile(data.camera())
|
||||
line_image, scan_data = plugin.output()
|
||||
for inp in [line_image.nonzero()[0].size,
|
||||
line_image.sum() / line_image.max(),
|
||||
scan_data.size]:
|
||||
assert_equal(inp, 172)
|
||||
assert_equal(line_image.shape, (512, 512))
|
||||
assert_allclose(scan_data.max(), 0.9176, rtol=1e-3)
|
||||
assert_allclose(scan_data.mean(), 0.2812, rtol=1e-3)
|
||||
|
||||
|
||||
@testing.skipif(not has_qt, reason="Qt not installed")
|
||||
def test_line_profile_rgb():
|
||||
""" Test a line profile using an ndim=3 image"""
|
||||
plugin = setup_line_profile(data.chelsea(), limits=None)
|
||||
for i in range(6):
|
||||
plugin.line_tool._thicken_scan_line()
|
||||
line_image, scan_data = plugin.output()
|
||||
assert_equal(line_image[line_image == 128].size, 750)
|
||||
assert_equal(line_image[line_image == 255].size, 151)
|
||||
assert_equal(line_image.shape, (300, 451))
|
||||
assert_equal(scan_data.shape, (151, 3))
|
||||
assert_allclose(scan_data.max(), 0.772, rtol=1e-3)
|
||||
assert_allclose(scan_data.mean(), 0.4359, rtol=1e-3)
|
||||
|
||||
|
||||
@testing.skipif(not has_qt, reason="Qt not installed")
|
||||
def test_line_profile_dynamic():
|
||||
"""Test a line profile updating after an image transform"""
|
||||
image = data.coins()[:-50, :] # shave some off to make the line lower
|
||||
image = util.img_as_float(image)
|
||||
viewer = ImageViewer(image)
|
||||
|
||||
lp = LineProfile(limits='dtype')
|
||||
viewer += lp
|
||||
|
||||
line = lp.get_profiles()[-1][0]
|
||||
assert line.size == 129
|
||||
assert_almost_equal(np.std(viewer.image), 0.208, 3)
|
||||
assert_almost_equal(np.std(line), 0.229, 3)
|
||||
assert_almost_equal(np.max(line) - np.min(line), 0.725, 1)
|
||||
|
||||
viewer.image = util.img_as_float(
|
||||
median(util.img_as_ubyte(image), selem=disk(radius=3)))
|
||||
|
||||
line = lp.get_profiles()[-1][0]
|
||||
assert_almost_equal(np.std(viewer.image), 0.198, 3)
|
||||
assert_almost_equal(np.std(line), 0.220, 3)
|
||||
assert_almost_equal(np.max(line) - np.min(line), 0.639, 1)
|
||||
|
||||
|
||||
@testing.skipif(not has_qt, reason="Qt not installed")
|
||||
def test_measure():
|
||||
image = data.camera()
|
||||
viewer = ImageViewer(image)
|
||||
m = Measure()
|
||||
viewer += m
|
||||
|
||||
m.line_changed([(0, 0), (10, 10)])
|
||||
assert_equal(str(m._length.text), '14.1')
|
||||
assert_equal(str(m._angle.text[:5]), '135.0')
|
||||
|
||||
|
||||
@testing.skipif(not has_qt, reason="Qt not installed")
|
||||
def test_canny():
|
||||
image = data.camera()
|
||||
viewer = ImageViewer(image)
|
||||
c = CannyPlugin()
|
||||
viewer += c
|
||||
|
||||
canny_edges = viewer.show(False)
|
||||
viewer.close()
|
||||
edges = canny_edges[0][0]
|
||||
assert edges.sum() == 2846
|
||||
|
||||
|
||||
@testing.skipif(not has_qt, reason="Qt not installed")
|
||||
def test_label_painter():
|
||||
image = data.camera()
|
||||
moon = data.moon()
|
||||
viewer = ImageViewer(image)
|
||||
lp = LabelPainter()
|
||||
viewer += lp
|
||||
|
||||
assert_equal(lp.radius, 5)
|
||||
lp.label = 1
|
||||
assert_equal(str(lp.label), '1')
|
||||
lp.label = 2
|
||||
assert_equal(str(lp.paint_tool.label), '2')
|
||||
assert_equal(lp.paint_tool.radius, 5)
|
||||
lp._on_new_image(moon)
|
||||
assert_equal(lp.paint_tool.shape, moon.shape)
|
||||
|
||||
|
||||
@testing.skipif(not has_qt, reason="Qt not installed")
|
||||
def test_crop():
|
||||
image = data.camera()
|
||||
viewer = ImageViewer(image)
|
||||
c = Crop()
|
||||
viewer += c
|
||||
|
||||
c.crop((0, 100, 0, 100))
|
||||
assert_equal(viewer.image.shape, (101, 101))
|
||||
|
||||
|
||||
@testing.skipif(not has_qt, reason="Qt not installed")
|
||||
def test_color_histogram():
|
||||
image = util.img_as_float(data.colorwheel())
|
||||
viewer = ImageViewer(image)
|
||||
ch = ColorHistogram(dock='right')
|
||||
viewer += ch
|
||||
|
||||
assert_almost_equal(viewer.image.std(), 0.352, 3),
|
||||
ch.ab_selected((0, 100, 0, 100)),
|
||||
assert_almost_equal(viewer.image.std(), 0.325, 3)
|
||||
|
||||
|
||||
@testing.skipif(not has_qt, reason="Qt not installed")
|
||||
def test_plot_plugin():
|
||||
viewer = ImageViewer(data.moon())
|
||||
plugin = PlotPlugin(image_filter=lambda x: x)
|
||||
viewer += plugin
|
||||
|
||||
assert_equal(viewer.image, data.moon())
|
||||
plugin._update_original_image(data.coins())
|
||||
assert_equal(viewer.image, data.coins())
|
||||
viewer.close()
|
||||
|
||||
|
||||
@testing.skipif(not has_qt, reason="Qt not installed")
|
||||
def test_plugin():
|
||||
img = util.img_as_float(data.moon())
|
||||
viewer = ImageViewer(img)
|
||||
|
||||
def median_filter(img, radius=3):
|
||||
return median(
|
||||
util.img_as_ubyte(img), selem=disk(radius=radius))
|
||||
|
||||
plugin = Plugin(image_filter=median_filter)
|
||||
viewer += plugin
|
||||
|
||||
plugin += Slider('radius', 1, 5)
|
||||
|
||||
assert_almost_equal(np.std(viewer.image), 12.556, 3)
|
||||
|
||||
plugin.filter_image()
|
||||
|
||||
assert_almost_equal(np.std(viewer.image), 12.931, 3)
|
||||
|
||||
plugin.show()
|
||||
plugin.close()
|
||||
plugin.clean_up()
|
||||
img, _ = plugin.output()
|
||||
assert_equal(img, viewer.image)
|
212
venv/Lib/site-packages/skimage/viewer/tests/test_tools.py
Normal file
212
venv/Lib/site-packages/skimage/viewer/tests/test_tools.py
Normal file
|
@ -0,0 +1,212 @@
|
|||
from collections import namedtuple
|
||||
|
||||
import numpy as np
|
||||
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
|
||||
|
||||
from skimage._shared import testing
|
||||
from skimage._shared.testing import assert_equal, parametrize
|
||||
|
||||
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
|
||||
@testing.skipif(not has_qt, reason="Qt not installed")
|
||||
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
|
||||
@testing.skipif(not has_qt, reason="Qt not installed")
|
||||
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
|
||||
@testing.skipif(not has_qt, reason="Qt not installed")
|
||||
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
|
||||
@testing.skipif(not has_qt, reason="Qt not installed")
|
||||
@parametrize('img', [data.moon(), data.astronaut()])
|
||||
def test_paint_tool(img):
|
||||
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[:2])
|
||||
|
||||
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)
|
||||
assert_equal(tool.cmap.N, tool._overlay_plot.norm.vmax)
|
||||
|
||||
|
||||
@cleanup
|
||||
@testing.skipif(not has_qt, reason="Qt not installed")
|
||||
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()
|
40
venv/Lib/site-packages/skimage/viewer/tests/test_utils.py
Normal file
40
venv/Lib/site-packages/skimage/viewer/tests/test_utils.py
Normal file
|
@ -0,0 +1,40 @@
|
|||
from skimage.viewer import utils
|
||||
from skimage.viewer.utils import dialogs
|
||||
from skimage.viewer.qt import QtCore, QtWidgets, has_qt
|
||||
from skimage._shared import testing
|
||||
|
||||
|
||||
@testing.skipif(not has_qt, reason="Qt not installed")
|
||||
def test_event_loop():
|
||||
utils.init_qtapp()
|
||||
timer = QtCore.QTimer()
|
||||
timer.singleShot(10, QtWidgets.QApplication.quit)
|
||||
utils.start_qtapp()
|
||||
|
||||
|
||||
@testing.skipif(not has_qt, reason="Qt not installed")
|
||||
def test_format_filename():
|
||||
fname = dialogs._format_filename(('apple', 2))
|
||||
assert fname == 'apple'
|
||||
fname = dialogs._format_filename('')
|
||||
assert fname is None
|
||||
|
||||
|
||||
@testing.skipif(True, reason="Can't automatically close window. See #3081.")
|
||||
@testing.skipif(not has_qt, reason="Qt not installed")
|
||||
def test_open_file_dialog():
|
||||
QApp = utils.init_qtapp()
|
||||
timer = QtCore.QTimer()
|
||||
timer.singleShot(100, lambda: QApp.quit())
|
||||
filename = dialogs.open_file_dialog()
|
||||
assert filename is None
|
||||
|
||||
|
||||
@testing.skipif(True, reason="Can't automatically close window. See #3081.")
|
||||
@testing.skipif(not has_qt, reason="Qt not installed")
|
||||
def test_save_file_dialog():
|
||||
QApp = utils.init_qtapp()
|
||||
timer = QtCore.QTimer()
|
||||
timer.singleShot(100, lambda: QApp.quit())
|
||||
filename = dialogs.save_file_dialog()
|
||||
assert filename is None
|
79
venv/Lib/site-packages/skimage/viewer/tests/test_viewer.py
Normal file
79
venv/Lib/site-packages/skimage/viewer/tests/test_viewer.py
Normal file
|
@ -0,0 +1,79 @@
|
|||
from skimage import data
|
||||
from skimage.transform import pyramid_gaussian
|
||||
from skimage.filters import sobel
|
||||
|
||||
from skimage.viewer.qt import QtGui, QtCore, has_qt
|
||||
from skimage.viewer import ImageViewer, CollectionViewer
|
||||
from skimage.viewer.plugins import OverlayPlugin
|
||||
|
||||
from skimage._shared.version_requirements import is_installed
|
||||
from skimage._shared import testing
|
||||
from skimage._shared.testing import assert_equal
|
||||
|
||||
|
||||
@testing.skipif(not has_qt, reason="Qt not installed")
|
||||
def test_viewer():
|
||||
astro = data.astronaut()
|
||||
coins = data.coins()
|
||||
|
||||
view = ImageViewer(astro)
|
||||
import tempfile
|
||||
_, filename = tempfile.mkstemp(suffix='.png')
|
||||
|
||||
view.show(False)
|
||||
view.close()
|
||||
view.save_to_file(filename)
|
||||
view.open_file(filename)
|
||||
assert_equal(view.image, astro)
|
||||
view.image = coins
|
||||
assert_equal(view.image, coins),
|
||||
view.save_to_file(filename),
|
||||
view.open_file(filename),
|
||||
view.reset_image(),
|
||||
assert_equal(view.image, coins)
|
||||
|
||||
|
||||
def make_key_event(key):
|
||||
return QtGui.QKeyEvent(QtCore.QEvent.KeyPress, key,
|
||||
QtCore.Qt.NoModifier)
|
||||
|
||||
|
||||
@testing.skipif(not has_qt, reason="Qt not installed")
|
||||
def test_collection_viewer():
|
||||
|
||||
img = data.astronaut()
|
||||
img_collection = tuple(pyramid_gaussian(img, multichannel=True))
|
||||
|
||||
view = CollectionViewer(img_collection)
|
||||
make_key_event(48)
|
||||
|
||||
view.update_index('', 2),
|
||||
assert_equal(view.image, img_collection[2])
|
||||
view.keyPressEvent(make_key_event(53))
|
||||
assert_equal(view.image, img_collection[5])
|
||||
view._format_coord(10, 10)
|
||||
|
||||
|
||||
@testing.skipif(not has_qt, reason="Qt not installed")
|
||||
@testing.skipif(not is_installed('matplotlib', '>=1.2'),
|
||||
reason="matplotlib < 1.2")
|
||||
def test_viewer_with_overlay():
|
||||
img = data.coins()
|
||||
ov = OverlayPlugin(image_filter=sobel)
|
||||
viewer = ImageViewer(img)
|
||||
viewer += ov
|
||||
|
||||
import tempfile
|
||||
_, filename = tempfile.mkstemp(suffix='.png')
|
||||
|
||||
ov.color = 3
|
||||
assert_equal(ov.color, 'yellow')
|
||||
|
||||
viewer.save_to_file(filename)
|
||||
ov.display_filtered_image(img)
|
||||
assert_equal(ov.overlay, img)
|
||||
ov.overlay = None
|
||||
assert_equal(ov.overlay, None)
|
||||
ov.overlay = img
|
||||
assert_equal(ov.overlay, img)
|
||||
assert_equal(ov.filtered_image, img)
|
129
venv/Lib/site-packages/skimage/viewer/tests/test_widgets.py
Normal file
129
venv/Lib/site-packages/skimage/viewer/tests/test_widgets.py
Normal file
|
@ -0,0 +1,129 @@
|
|||
import os
|
||||
|
||||
from skimage import data, img_as_float, io, img_as_uint
|
||||
|
||||
from skimage.viewer import ImageViewer
|
||||
from skimage.viewer.qt import QtWidgets, QtCore, has_qt
|
||||
from skimage.viewer.widgets import (
|
||||
Slider, OKCancelButtons, SaveButtons, ComboBox, CheckBox, Text)
|
||||
from skimage.viewer.plugins.base import Plugin
|
||||
|
||||
from skimage._shared import testing
|
||||
from skimage._shared.testing import assert_almost_equal, assert_equal
|
||||
|
||||
|
||||
def get_image_viewer():
|
||||
image = data.coins()
|
||||
viewer = ImageViewer(img_as_float(image))
|
||||
viewer += Plugin()
|
||||
return viewer
|
||||
|
||||
|
||||
@testing.skipif(not has_qt, reason="Qt not installed")
|
||||
def test_check_box():
|
||||
viewer = get_image_viewer()
|
||||
cb = CheckBox('hello', value=True, alignment='left')
|
||||
viewer.plugins[0] += cb
|
||||
|
||||
assert_equal(cb.val, True)
|
||||
cb.val = False
|
||||
assert_equal(cb.val, False)
|
||||
cb.val = 1
|
||||
assert_equal(cb.val, True)
|
||||
cb.val = 0
|
||||
assert_equal(cb.val, False)
|
||||
|
||||
|
||||
@testing.skipif(not has_qt, reason="Qt not installed")
|
||||
def test_combo_box():
|
||||
viewer = get_image_viewer()
|
||||
cb = ComboBox('hello', ('a', 'b', 'c'))
|
||||
viewer.plugins[0] += cb
|
||||
|
||||
assert_equal(str(cb.val), 'a')
|
||||
assert_equal(cb.index, 0)
|
||||
cb.index = 2
|
||||
assert_equal(str(cb.val), 'c'),
|
||||
assert_equal(cb.index, 2)
|
||||
|
||||
|
||||
@testing.skipif(not has_qt, reason="Qt not installed")
|
||||
def test_text_widget():
|
||||
viewer = get_image_viewer()
|
||||
txt = Text('hello', 'hello, world!')
|
||||
viewer.plugins[0] += txt
|
||||
|
||||
assert_equal(str(txt.text), 'hello, world!')
|
||||
txt.text = 'goodbye, world!'
|
||||
assert_equal(str(txt.text), 'goodbye, world!')
|
||||
|
||||
|
||||
@testing.skipif(not has_qt, reason="Qt not installed")
|
||||
def test_slider_int():
|
||||
viewer = get_image_viewer()
|
||||
sld = Slider('radius', 2, 10, value_type='int')
|
||||
viewer.plugins[0] += sld
|
||||
|
||||
assert_equal(sld.val, 4)
|
||||
sld.val = 6
|
||||
assert_equal(sld.val, 6)
|
||||
sld.editbox.setText('5')
|
||||
sld._on_editbox_changed()
|
||||
assert_equal(sld.val, 5)
|
||||
|
||||
|
||||
@testing.skipif(not has_qt, reason="Qt not installed")
|
||||
def test_slider_float():
|
||||
viewer = get_image_viewer()
|
||||
sld = Slider('alpha', 2.1, 3.1, value=2.1, value_type='float',
|
||||
orientation='vertical', update_on='move')
|
||||
viewer.plugins[0] += sld
|
||||
|
||||
assert_equal(sld.val, 2.1)
|
||||
sld.val = 2.5
|
||||
assert_almost_equal(sld.val, 2.5, 2)
|
||||
sld.editbox.setText('0.1')
|
||||
sld._on_editbox_changed()
|
||||
assert_almost_equal(sld.val, 2.5, 2)
|
||||
|
||||
|
||||
@testing.skipif(True, reason="Can't automatically close window. See #3081.")
|
||||
@testing.skipif(not has_qt, reason="Qt not installed")
|
||||
def test_save_buttons():
|
||||
viewer = get_image_viewer()
|
||||
sv = SaveButtons()
|
||||
viewer.plugins[0] += sv
|
||||
|
||||
import tempfile
|
||||
fid, filename = tempfile.mkstemp(suffix='.png')
|
||||
os.close(fid)
|
||||
|
||||
timer = QtCore.QTimer()
|
||||
timer.singleShot(100, QtWidgets.QApplication.quit)
|
||||
|
||||
# exercise the button clicks
|
||||
sv.save_stack.click()
|
||||
sv.save_file.click()
|
||||
|
||||
# call the save functions directly
|
||||
sv.save_to_stack()
|
||||
sv.save_to_file(filename)
|
||||
|
||||
img = data.imread(filename)
|
||||
|
||||
assert_almost_equal(img, img_as_uint(viewer.image))
|
||||
|
||||
img = io.pop()
|
||||
assert_almost_equal(img, viewer.image)
|
||||
|
||||
os.remove(filename)
|
||||
|
||||
|
||||
@testing.skipif(not has_qt, reason="Qt not installed")
|
||||
def test_ok_buttons():
|
||||
viewer = get_image_viewer()
|
||||
ok = OKCancelButtons()
|
||||
viewer.plugins[0] += ok
|
||||
|
||||
ok.update_original_image(),
|
||||
ok.close_plugin()
|
Loading…
Add table
Add a link
Reference in a new issue