@@ -166,25 +166,38 @@ def test_one_class_value(self):
166166 "yyyy" ))
167167 )
168168 self .widget .n_folds = 0
169- self .assertFalse (self .widget .Error .only_one_class_var_value .is_shown ())
169+ self .assertFalse (self .widget .Error .train_data_error .is_shown ())
170170 self .send_signal ("Data" , table )
171171 self .send_signal ("Learner" , MajorityLearner (), 0 , wait = 1000 )
172- self .assertTrue (self .widget .Error .only_one_class_var_value .is_shown ())
172+ self .assertTrue (self .widget .Error .train_data_error .is_shown ())
173173
174- def test_nan_class (self ):
175- """
176- Do not crash on a data with only nan class values.
177- GH-2751
178- """
179- def assertErrorShown (data , is_shown ):
174+ def test_data_errors (self ):
175+ """ Test all data_errors """
176+ def assertErrorShown (data , is_shown , message ):
180177 self .send_signal ("Data" , data )
181- self .assertEqual (is_shown , self .widget .Error .no_class_values .is_shown ())
178+ self .assertEqual (is_shown , self .widget .Error .train_data_error .is_shown ())
179+ self .assertEqual (message , str (self .widget .Error .train_data_error ))
182180
183181 data = Table ("iris" )[::30 ]
184182 data .Y [:] = np .nan
185183
186- for data , is_shown in zip ([None , data , Table ("iris" )[:30 ]], [False , True , False ]):
187- assertErrorShown (data , is_shown )
184+ iris_empty_x = Table .from_table (
185+ Domain ([], data .domain .class_var ), Table ("iris" )
186+ )
187+
188+ for data , is_shown , message in zip (
189+ [None , data , Table ("iris" )[:30 ], iris_empty_x , data [:0 ]],
190+ [False , True , True , True , True ],
191+ [
192+ "" ,
193+ "Target variable has no values." ,
194+ "Target variable has only one value." ,
195+ "Data has no features to learn from." ,
196+ "Train dataset is empty."
197+ ]
198+
199+ ):
200+ assertErrorShown (data , is_shown , message )
188201
189202 def test_addon_scorers (self ):
190203 try :
@@ -319,15 +332,19 @@ def _test_scores(self, train_data, test_data, learner, sampling, n_folds):
319332 self .send_signal (self .widget .Inputs .learner , learner , 0 , wait = 5000 )
320333 return self ._retrieve_scores ()
321334
322- def test_scores_constant_all_same (self ):
335+ def test_scores_constant (self ):
323336 table = Table .from_list (
324337 self .scores_domain ,
325- list (zip (* self .scores_table_values + [list ("yyyy " )]))
338+ list (zip (* self .scores_table_values + [list ("yyyn " )]))
326339 )
327340
328- self .assertTupleEqual (self ._test_scores (
329- table , table , ConstantLearner (), OWTestAndScore .TestOnTest , None ),
330- (None , 1 , 1 , 1 , 1 ))
341+ self .assertTupleEqual (
342+ self ._test_scores (
343+ table , table [:3 ], ConstantLearner (),
344+ OWTestAndScore .TestOnTest , None
345+ ),
346+ (None , 1 , 1 , 1 , 1 )
347+ )
331348
332349 def test_scores_log_reg_overfitted (self ):
333350 table = Table .from_list (
0 commit comments