11# Test methods with long descriptive names can omit docstrings
22# pylint: disable=missing-docstring
33import random
4+ import numpy as np
45
56from Orange .data import Table
67from Orange .widgets .visualize .owlinearprojection import OWLinearProjection
7- from Orange .widgets .tests .base import WidgetTest , WidgetOutputsTestMixin
8+ from Orange .widgets .tests .base import WidgetTest , WidgetOutputsTestMixin , datasets
9+ from Orange .widgets .tests .utils import EventSpy , excepthook_catch , simulate
810
911
1012class TestOWLinearProjection (WidgetTest , WidgetOutputsTestMixin ):
@@ -17,7 +19,7 @@ def setUpClass(cls):
1719 cls .signal_data = cls .data
1820
1921 def setUp (self ):
20- self .widget = self .create_widget (OWLinearProjection )
22+ self .widget = self .create_widget (OWLinearProjection ) # type: OWLinearProjection
2123
2224 def _select_data (self ):
2325 random .seed (42 )
@@ -28,3 +30,45 @@ def _select_data(self):
2830 def test_no_data (self ):
2931 """Check that the widget doesn't crash on empty data"""
3032 self .send_signal ("Data" , Table (Table ("iris" ).domain ))
33+
34+ def test_nan_plot (self ):
35+ data = datasets .missing_data_1 ()
36+ espy = EventSpy (self .widget , OWLinearProjection .ReplotRequest )
37+ with excepthook_catch ():
38+ self .send_signal ("Data" , data )
39+ # ensure delayed replot request is processed
40+ if not espy .events ():
41+ assert espy .wait (1000 )
42+
43+ cb_color = self .widget .controls .color_index
44+ cb_size = self .widget .controls .size_index
45+ cb_shape = self .widget .controls .shape_index
46+ cb_jitter = self .widget .controls .jitter_value
47+
48+ simulate .combobox_run_through_all (cb_color )
49+ simulate .combobox_run_through_all (cb_size )
50+ simulate .combobox_run_through_all (cb_shape )
51+ with excepthook_catch ():
52+ simulate .combobox_activate_index (cb_jitter , 1 , delay = 1 )
53+
54+ data = data .copy ()
55+ data .X [:, 0 ] = np .nan
56+ data .Y [:] = np .nan
57+
58+ spy = EventSpy (self .widget , OWLinearProjection .ReplotRequest )
59+ self .send_signal ("Data" , data )
60+ self .send_signal ("Data Subset" , data [2 :3 ])
61+ if not spy .events ():
62+ assert spy .wait ()
63+
64+ with excepthook_catch ():
65+ simulate .combobox_activate_item (cb_color , "X1" )
66+
67+ with excepthook_catch ():
68+ simulate .combobox_activate_item (cb_size , "X1" )
69+
70+ with excepthook_catch ():
71+ simulate .combobox_activate_item (cb_shape , "D" )
72+
73+ with excepthook_catch ():
74+ simulate .combobox_activate_index (cb_jitter , 2 , delay = 1 )
0 commit comments