2121class DummyLearner (PLSRegressionLearner ):
2222 def fitted_parameters (self ):
2323 return [
24- self .FittedParameter ("n_components" , "Foo" , "foo" , int , 1 , None ),
25- self .FittedParameter ("n_components" , "Bar" , "bar" , int , 1 , 10 ),
24+ self .FittedParameter ("n_components" , "Foo" , "foo" , int , 5 , None ),
25+ self .FittedParameter ("n_components" , "Bar" , "bar" , int , 5 , 10 ),
2626 self .FittedParameter ("n_components" , "Baz" , "baz" , int , None , 10 ),
2727 self .FittedParameter ("n_components" , "Qux" , "qux" , int , None , None )
2828 ]
@@ -134,6 +134,82 @@ def test_manual_steps(self):
134134 x = self .widget .graph ._FitterPlot__bar_item_cv .opts ["x" ]
135135 self .assertEqual (list (x ), [0.2 , 1.2 , 2.2 ])
136136
137+ def test_manual_steps_limits (self ):
138+ w = self .widget
139+
140+ def test_errors (act ):
141+ err = w .Error
142+ for error in (err .manual_steps_error , err .manual_invalid_minmax ,
143+ err .manual_invalid_minimum , err .manual_invalid_maximum ):
144+ self .assertIs (error .is_shown (), error is act )
145+
146+ def enter (text ):
147+ w .controls .manual_steps .setText (text )
148+ w .controls .manual_steps .returnPressed .emit ()
149+
150+ self .send_signal (w .Inputs .data , self ._housing )
151+ self .send_signal (w .Inputs .learner , self ._dummy )
152+ self .wait_until_finished ()
153+
154+ # 5 to None
155+ simulate .combobox_activate_index (w .controls .parameter_index , 0 )
156+ self .wait_until_finished ()
157+
158+ enter ("6, 9, 7" )
159+ self .assertEqual (w .steps , (6 , 7 , 9 ))
160+ test_errors (None )
161+
162+ enter ("6, 9, 7, 3" )
163+ self .assertEqual (w .steps , ())
164+ test_errors (w .Error .manual_invalid_minimum )
165+
166+ enter ("6, 9, 7" )
167+ self .assertEqual (w .steps , (6 , 7 , 9 ))
168+ test_errors (None )
169+
170+ enter ("6, 9, 7, 3" )
171+
172+ # None to 10
173+ simulate .combobox_activate_index (w .controls .parameter_index , 2 )
174+ self .wait_until_finished ()
175+
176+ test_errors (None )
177+
178+ enter ("12, 1, 3, -5" )
179+ self .assertEqual (w .steps , ())
180+ test_errors (w .Error .manual_invalid_maximum )
181+
182+ enter ("1, 3, -5" )
183+ self .assertEqual (w .steps , (- 5 , 1 , 3 ))
184+ test_errors (None )
185+
186+ enter ("12, 1, 3, -5" )
187+
188+ # No limits
189+ simulate .combobox_activate_index (w .controls .parameter_index , 3 )
190+ self .wait_until_finished ()
191+ self .assertEqual (w .steps , (- 5 , 1 , 3 , 12 ))
192+ test_errors (None )
193+
194+ # 5 to 10
195+ simulate .combobox_activate_index (w .controls .parameter_index , 1 )
196+ self .wait_until_finished ()
197+
198+ self .assertEqual (w .steps , ())
199+ test_errors (w .Error .manual_invalid_minmax )
200+
201+ enter ("12, 8, 7, 5" )
202+ self .assertEqual (w .steps , ())
203+ test_errors (w .Error .manual_invalid_maximum )
204+
205+ enter ("8, 7, -5" )
206+ self .assertEqual (w .steps , ())
207+ test_errors (w .Error .manual_invalid_minimum )
208+
209+ enter ("8, 7, 5" )
210+ self .assertEqual (w .steps , (5 , 7 , 8 ))
211+ test_errors (None )
212+
137213 def test_steps_preview (self ):
138214 self .send_signal (self .widget .Inputs .data , self ._housing )
139215 self .send_signal (self .widget .Inputs .learner , self ._pls )
@@ -353,8 +429,10 @@ def test_steps_from_range_error(self):
353429
354430 def test_steps_from_manual_error (self ):
355431 w : OWParameterFitter = self .widget
356- self .send_signal (w .Inputs .data , self ._heart )
432+ self .send_signal (w .Inputs .data , self ._housing )
357433 self .send_signal (w .Inputs .learner , self ._dummy )
434+ self .wait_until_finished ()
435+ simulate .combobox_activate_index (w .controls .parameter_index , 3 )
358436 w .type = w .MANUAL
359437
360438 w .manual_steps = "1, 2, 3, asdf, 4, 5"
@@ -374,8 +452,10 @@ def test_steps_from_manual_error(self):
374452
375453 def test_steps_from_manual (self ):
376454 w : OWParameterFitter = self .widget
377- self .send_signal (w .Inputs .data , self ._heart )
455+ self .send_signal (w .Inputs .data , self ._housing )
378456 self .send_signal (w .Inputs .learner , self ._dummy )
457+ self .wait_until_finished ()
458+ simulate .combobox_activate_index (w .controls .parameter_index , 3 )
379459 w .type = w .MANUAL
380460
381461 w .manual_steps = "1, 2, 3, 4, 5"
@@ -384,10 +464,26 @@ def test_steps_from_manual(self):
384464 w .manual_steps = "1, 2, 3, 4, 5, 6"
385465 self .assertEqual (w .steps , (1 , 2 , 3 , 4 , 5 , 6 ))
386466
387- # TODO: We may or may not want this.
388467 w .manual_steps = "1, 2, 10, 3, 4, 123, 5, 6"
389468 self .assertEqual (w .steps , (1 , 2 , 3 , 4 , 5 , 6 , 10 , 123 ))
390469
470+ def test_manual_tooltip (self ):
471+ w : OWParameterFitter = self .widget
472+ self .send_signal (w .Inputs .data , self ._housing )
473+ self .send_signal (w .Inputs .learner , self ._dummy )
474+ self .wait_until_finished ()
475+
476+ simulate .combobox_activate_index (w .controls .parameter_index , 0 )
477+ self .assertIn ("greater or equal to 5" , w .edit .toolTip ())
478+
479+ simulate .combobox_activate_index (w .controls .parameter_index , 1 )
480+ self .assertIn ("between 5 and 10" , w .edit .toolTip ())
481+
482+ simulate .combobox_activate_index (w .controls .parameter_index , 2 )
483+ self .assertIn ("smaller or equal to 10" , w .edit .toolTip ())
484+
485+ simulate .combobox_activate_index (w .controls .parameter_index , 3 )
486+ self .assertEqual ("" , w .edit .toolTip ())
391487
392488if __name__ == "__main__" :
393489 unittest .main ()
0 commit comments