Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

[ENH] Widget testing utilities #1939

Merged
Merged
Changes from 1 commit
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
Prev Previous commit
tests/owlinearprojection: Test on input dataset with NaN values
  • Loading branch information
ales-erjavec committed Jan 24, 2017
commit 76814cde8a683318233d60825ef3cee9f3b0894e
48 changes: 46 additions & 2 deletions Orange/widgets/visualize/tests/test_owlinearprojection.py
Original file line number Diff line number Diff line change
@@ -1,10 +1,12 @@
# Test methods with long descriptive names can omit docstrings
# pylint: disable=missing-docstring
import random
import numpy as np

from Orange.data import Table
from Orange.widgets.visualize.owlinearprojection import OWLinearProjection
from Orange.widgets.tests.base import WidgetTest, WidgetOutputsTestMixin
from Orange.widgets.tests.base import WidgetTest, WidgetOutputsTestMixin, datasets
from Orange.widgets.tests.utils import EventSpy, excepthook_catch, simulate


class TestOWLinearProjection(WidgetTest, WidgetOutputsTestMixin):
Expand All @@ -17,7 +19,7 @@ def setUpClass(cls):
cls.signal_data = cls.data

def setUp(self):
self.widget = self.create_widget(OWLinearProjection)
self.widget = self.create_widget(OWLinearProjection) # type: OWLinearProjection

def _select_data(self):
random.seed(42)
Expand All @@ -28,3 +30,45 @@ def _select_data(self):
def test_no_data(self):
"""Check that the widget doesn't crash on empty data"""
self.send_signal("Data", Table(Table("iris").domain))

def test_nan_plot(self):
data = datasets.missing_data_1()
espy = EventSpy(self.widget, OWLinearProjection.ReplotRequest)
with excepthook_catch():
self.send_signal("Data", data)
# ensure delayed replot request is processed
if not espy.events():
assert espy.wait(1000)

cb_color = self.widget.controls.color_index
cb_size = self.widget.controls.size_index
cb_shape = self.widget.controls.shape_index
cb_jitter = self.widget.controls.jitter_value

simulate.combobox_run_through_all(cb_color)
simulate.combobox_run_through_all(cb_size)
simulate.combobox_run_through_all(cb_shape)
with excepthook_catch():
simulate.combobox_activate_index(cb_jitter, 1, delay=1)

data = data.copy()
data.X[:, 0] = np.nan
data.Y[:] = np.nan

spy = EventSpy(self.widget, OWLinearProjection.ReplotRequest)
self.send_signal("Data", data)
self.send_signal("Data Subset", data[2:3])
if not spy.events():
assert spy.wait()

with excepthook_catch():
simulate.combobox_activate_item(cb_color, "X1")

with excepthook_catch():
simulate.combobox_activate_item(cb_size, "X1")

with excepthook_catch():
simulate.combobox_activate_item(cb_shape, "D")

with excepthook_catch():
simulate.combobox_activate_index(cb_jitter, 2, delay=1)