Skip to content

Commit

Permalink
Merge pull request #6320 from janezd/fix-model-name-tests
Browse files Browse the repository at this point in the history
WidgetLearnerTestMixin: Fix for clicks of disabled buttons
  • Loading branch information
markotoplak authored Jan 27, 2023
2 parents 3d8ae07 + 69cf2c1 commit b78ff8c
Show file tree
Hide file tree
Showing 10 changed files with 64 additions and 58 deletions.
6 changes: 3 additions & 3 deletions Orange/widgets/model/tests/test_owcalibratedlearner.py
Original file line number Diff line number Diff line change
Expand Up @@ -31,7 +31,7 @@ def test_output_learner(self):
# Overridden to change the output type in the last test
initial = self.get_output("Learner")
self.assertIsNotNone(initial, "Does not initialize the learner output")
self.widget.apply_button.button.click()
self.click_apply()
newlearner = self.get_output("Learner")
self.assertIsNot(initial, newlearner,
"Does not send a new learner instance on `Apply`.")
Expand All @@ -44,10 +44,10 @@ def test_output_model(self):
"""Check if model is on output after sending data and apply"""
# Overridden to change the output type in the last two test
self.assertIsNone(self.get_output(self.widget.Outputs.model))
self.widget.apply_button.button.click()
self.click_apply()
self.assertIsNone(self.get_output(self.widget.Outputs.model))
self.send_signal('Data', self.data)
self.widget.apply_button.button.click()
self.click_apply()
self.wait_until_stop_blocking()
model = self.get_output(self.widget.Outputs.model)
self.assertIsNotNone(model)
Expand Down
24 changes: 12 additions & 12 deletions Orange/widgets/model/tests/test_owcurvefit.py
Original file line number Diff line number Diff line change
Expand Up @@ -219,7 +219,7 @@ def test_output_learner(self):

def test_output_model(self): # overwritten
self.assertIsNone(self.get_output(self.widget.Outputs.model))
self.widget.apply_button.button.click()
self.click_apply()
self.assertIsNone(self.get_output(self.widget.Outputs.model))

self.__init_widget()
Expand Down Expand Up @@ -358,7 +358,7 @@ def test_expression(self):
insert("2")
else:
simulate.combobox_activate_index(feature_combo, 1)
self.widget.apply_button.button.click()
self.click_apply()

self.assertIsNotNone(self.get_output(self.widget.Outputs.learner))
self.assertFalse(self.widget.Error.no_parameter.is_shown())
Expand Down Expand Up @@ -402,13 +402,13 @@ def test_invalid_expression(self):
self.__init_widget()
self.assertFalse(self.widget.Error.invalid_exp.is_shown())
self.widget._OWCurveFit__insert_into_expression(" + ")
self.widget.apply_button.button.click()
self.click_apply()
self.assertTrue(self.widget.Error.invalid_exp.is_shown())
self.widget._OWCurveFit__insert_into_expression(" 2 ")
self.widget.apply_button.button.click()
self.click_apply()
self.assertFalse(self.widget.Error.invalid_exp.is_shown())
self.widget._OWCurveFit__insert_into_expression(" + ")
self.widget.apply_button.button.click()
self.click_apply()
self.assertTrue(self.widget.Error.invalid_exp.is_shown())
self.send_signal(self.widget.Inputs.data, None)
self.assertFalse(self.widget.Error.invalid_exp.is_shown())
Expand Down Expand Up @@ -443,10 +443,10 @@ def test_parameter_name_in_features(self):
def test_no_parameter(self):
self.send_signal(self.widget.Inputs.data, self.housing)
self.widget._OWCurveFit__expression_edit.setText("LSTAT + 1")
self.widget.apply_button.button.click()
self.click_apply()
self.assertTrue(self.widget.Error.no_parameter.is_shown())
self.widget._OWCurveFit__expression_edit.setText("LSTAT + a")
self.widget.apply_button.button.click()
self.click_apply()
self.assertFalse(self.widget.Error.no_parameter.is_shown())

def test_unused_parameter(self):
Expand All @@ -456,11 +456,11 @@ def test_unused_parameter(self):
self.assertFalse(self.widget.Warning.unused_parameter.is_shown())

self.widget._OWCurveFit__expression_edit.setText("p1 + LSTAT + p2")
self.widget.apply_button.button.click()
self.click_apply()
self.assertFalse(self.widget.Warning.unused_parameter.is_shown())

self.widget._OWCurveFit__expression_edit.setText("p1 + LSTAT")
self.widget.apply_button.button.click()
self.click_apply()
self.assertTrue(self.widget.Warning.unused_parameter.is_shown())

self.send_signal(self.widget.Inputs.data, None)
Expand All @@ -471,11 +471,11 @@ def test_unknown_parameter(self):
self.__add_button.click()

self.widget._OWCurveFit__expression_edit.setText("p1 + LSTAT")
self.widget.apply_button.button.click()
self.click_apply()
self.assertFalse(self.widget.Error.unknown_parameter.is_shown())

self.widget._OWCurveFit__expression_edit.setText("p2 + LSTAT")
self.widget.apply_button.button.click()
self.click_apply()
self.assertTrue(self.widget.Error.unknown_parameter.is_shown())

self.send_signal(self.widget.Inputs.data, None)
Expand Down Expand Up @@ -528,7 +528,7 @@ def test_output(self):
self.__add_button.click()
exp = "p1 * exp(-p2 * LSTAT) + p3"
self.widget._OWCurveFit__expression_edit.setText(exp)
self.widget.apply_button.button.click()
self.click_apply()
learner = self.get_output(self.widget.Outputs.learner)
self.assertIsInstance(learner, CurveFitLearner)
model = self.get_output(self.widget.Outputs.model)
Expand Down
2 changes: 1 addition & 1 deletion Orange/widgets/model/tests/test_owgradientboosting.py
Original file line number Diff line number Diff line change
Expand Up @@ -354,7 +354,7 @@ def test_methods(self):
if cls is None:
continue
simulate.combobox_activate_index(method_cb, i)
self.widget.apply_button.button.click()
self.click_apply()
self.assertIsInstance(self.widget.learner, cls)

def test_missing_lib(self):
Expand Down
12 changes: 6 additions & 6 deletions Orange/widgets/model/tests/test_owlogisticregression.py
Original file line number Diff line number Diff line change
Expand Up @@ -58,7 +58,7 @@ def test_output_coefficients(self):
"""Check if coefficients are on output after apply"""
self.assertIsNone(self.get_output(self.widget.Outputs.coefficients))
self.send_signal("Data", self.data)
self.widget.apply_button.button.click()
self.click_apply()
self.assertIsInstance(self.get_output(self.widget.Outputs.coefficients), Table)

def test_domain_with_more_values_than_table(self):
Expand All @@ -74,7 +74,7 @@ def test_domain_with_more_values_than_table(self):
for case in cases:
data = table[case, :]
self.send_signal("Data", data)
self.widget.apply_button.button.click()
self.click_apply()

def test_coefficients_one_value(self):
"""
Expand All @@ -94,7 +94,7 @@ def test_coefficients_one_value(self):
["yes", "no"]))
)
self.send_signal("Data", table)
self.widget.apply_button.button.click()
self.click_apply()
coef = self.get_output(self.widget.Outputs.coefficients)
self.assertEqual(coef.domain[0].name, "no")
self.assertGreater(coef[2][0], 0.)
Expand All @@ -120,21 +120,21 @@ def test_class_weights(self):
self.assertFalse(self.widget.class_weight)
self.widget.controls.class_weight.setChecked(True)
self.assertTrue(self.widget.class_weight)
self.widget.apply_button.button.click()
self.click_apply()
self.assertEqual(self.widget.model.skl_model.class_weight, "balanced")
self.assertTrue(self.widget.Warning.class_weights_used.is_shown())

def test_no_penalty(self):
self.widget.set_penalty("none")
self.widget.apply_button.button.click()
self.click_apply()
lr = self.get_output(self.widget.Outputs.learner)
self.assertEqual(lr.penalty, "none")
self.assertEqual(lr.C, 1.0)
self.assertEqual(self.widget.c_label.text(), "N/A")
self.assertFalse(self.widget.c_slider.isEnabledTo(self.widget))

self.widget.set_penalty("l2")
self.widget.apply_button.button.click()
self.click_apply()
lr = self.get_output(self.widget.Outputs.learner)
self.assertEqual(lr.penalty, "l2")
self.assertEqual(self.widget.c_label.text(), "C=1")
Expand Down
4 changes: 2 additions & 2 deletions Orange/widgets/model/tests/test_owneuralnetwork.py
Original file line number Diff line number Diff line change
Expand Up @@ -30,9 +30,9 @@ def test_no_layer_warning(self):
self.assertFalse(self.widget.Warning.no_layers.is_shown())

self.widget.hidden_layers_input = ""
self.widget.apply_button.button.click()
self.click_apply()
self.assertTrue(self.widget.Warning.no_layers.is_shown())

self.widget.hidden_layers_input = "10,"
self.widget.apply_button.button.click()
self.click_apply()
self.assertFalse(self.widget.Warning.no_layers.is_shown())
2 changes: 1 addition & 1 deletion Orange/widgets/model/tests/test_owrandomforest.py
Original file line number Diff line number Diff line change
Expand Up @@ -55,7 +55,7 @@ def test_class_weights(self):
self.assertFalse(self.widget.class_weight)
self.widget.controls.class_weight.setChecked(True)
self.assertTrue(self.widget.class_weight)
self.widget.apply_button.button.click()
self.click_apply()
self.assertEqual(self.widget.model.skl_model.class_weight, "balanced")
self.assertTrue(self.widget.Warning.class_weights_used.is_shown())

Expand Down
6 changes: 3 additions & 3 deletions Orange/widgets/model/tests/test_owrulesclassification.py
Original file line number Diff line number Diff line change
Expand Up @@ -114,10 +114,10 @@ def test_sparse_data(self):
data.X = sparse.csr_matrix(data.X)
self.assertTrue(sparse.issparse(data.X))
self.send_signal("Data", data)
self.widget.apply_button.button.click()
self.click_apply()
self.assertTrue(self.widget.Error.sparse_not_supported.is_shown())
self.send_signal("Data", None)
self.widget.apply_button.button.click()
self.click_apply()
self.assertFalse(self.widget.Error.sparse_not_supported.is_shown())

def test_out_of_memory(self):
Expand All @@ -138,5 +138,5 @@ def test_out_of_memory(self):
def test_default_rule(self):
data = Table("zoo")
self.send_signal("Data", data)
self.widget.apply_button.button.click()
self.click_apply()
self.assertEqual(sum(self.widget.model.rule_list[-1].curr_class_dist.tolist()), len(data))
8 changes: 4 additions & 4 deletions Orange/widgets/model/tests/test_owstack.py
Original file line number Diff line number Diff line change
Expand Up @@ -23,10 +23,10 @@ def test_output_learner(self):
"""Check if learner is on output after apply"""
self.assertIsNone(self.get_output(self.widget.Outputs.model))
self.send_signal("Learners", LogisticRegressionLearner(), 0)
self.widget.apply_button.button.click()
self.widget.apply_button.button.clicked.emit()
initial = self.get_output("Learner")
self.assertIsNotNone(initial, "Does not initialize the learner output")
self.widget.apply_button.button.click()
self.widget.apply_button.button.clicked.emit()
newlearner = self.get_output("Learner")
self.assertIsNot(initial, newlearner,
"Does not send a new learner instance on `Apply`.")
Expand All @@ -37,10 +37,10 @@ def test_output_model(self):
"""Check if model is on output after sending data and apply"""
self.assertIsNone(self.get_output(self.widget.Outputs.model))
self.send_signal("Learners", LogisticRegressionLearner(), 0)
self.widget.apply_button.button.click()
self.widget.apply_button.button.clicked.emit()
self.assertIsNone(self.get_output(self.widget.Outputs.model))
self.send_signal('Data', self.data)
self.widget.apply_button.button.click()
self.widget.apply_button.button.clicked.emit()
self.wait_until_stop_blocking()
model = self.get_output(self.widget.Outputs.model)
self.assertIsNotNone(model)
Expand Down
33 changes: 18 additions & 15 deletions Orange/widgets/tests/base.py
Original file line number Diff line number Diff line change
Expand Up @@ -248,6 +248,9 @@ def init(self):

self.parameters = []

def click_apply(self):
self.widget.apply_button.button.clicked.emit()

def test_has_unconditional_apply(self):
self.assertTrue(hasattr(self.widget, "unconditional_apply"))

Expand All @@ -262,7 +265,7 @@ def test_input_data_disconnect(self):
"""Check widget's data and model after disconnecting data from input"""
self.send_signal("Data", self.data)
self.assertEqual(self.widget.data, self.data)
self.widget.apply_button.button.click()
self.click_apply()
self.wait_until_stop_blocking()
self.send_signal("Data", None)
self.wait_until_stop_blocking()
Expand All @@ -273,7 +276,7 @@ def test_input_data_learner_adequacy(self):
"""Check if error message is shown with inadequate data on input"""
for inadequate in self.inadequate_dataset:
self.send_signal("Data", inadequate)
self.widget.apply_button.button.click()
self.click_apply()
self.wait_until_stop_blocking()
self.assertTrue(self.widget.Error.data_error.is_shown())
for valid in self.valid_datasets:
Expand All @@ -288,7 +291,7 @@ def test_input_preprocessor(self):
self.assertEqual(
randomize, self.widget.preprocessors,
'Preprocessor not added to widget preprocessors')
self.widget.apply_button.button.click()
self.click_apply()
self.wait_until_stop_blocking()
self.assertEqual(
(randomize,), self.widget.learner.preprocessors,
Expand All @@ -298,7 +301,7 @@ def test_input_preprocessors(self):
"""Check multiple preprocessors on input"""
pp_list = PreprocessorList([Randomize(), RemoveNaNColumns()])
self.send_signal("Preprocessor", pp_list)
self.widget.apply_button.button.click()
self.click_apply()
self.wait_until_stop_blocking()
self.assertEqual(
(pp_list,), self.widget.learner.preprocessors,
Expand All @@ -308,12 +311,12 @@ def test_input_preprocessor_disconnect(self):
"""Check learner's preprocessors after disconnecting pp from input"""
randomize = Randomize()
self.send_signal("Preprocessor", randomize)
self.widget.apply_button.button.click()
self.click_apply()
self.wait_until_stop_blocking()
self.assertEqual(randomize, self.widget.preprocessors)

self.send_signal("Preprocessor", None)
self.widget.apply_button.button.click()
self.click_apply()
self.wait_until_stop_blocking()
self.assertIsNone(self.widget.preprocessors,
'Preprocessors not removed on disconnect.')
Expand All @@ -322,7 +325,7 @@ def test_output_learner(self):
"""Check if learner is on output after apply"""
initial = self.get_output("Learner")
self.assertIsNotNone(initial, "Does not initialize the learner output")
self.widget.apply_button.button.click()
self.click_apply()
newlearner = self.get_output("Learner")
self.assertIsNot(initial, newlearner,
"Does not send a new learner instance on `Apply`.")
Expand All @@ -332,10 +335,10 @@ def test_output_learner(self):
def test_output_model(self):
"""Check if model is on output after sending data and apply"""
self.assertIsNone(self.get_output(self.widget.Outputs.model))
self.widget.apply_button.button.click()
self.click_apply()
self.assertIsNone(self.get_output(self.widget.Outputs.model))
self.send_signal('Data', self.data)
self.widget.apply_button.button.click()
self.click_apply()
self.wait_until_stop_blocking()
model = self.get_output(self.widget.Outputs.model)
self.assertIsNotNone(model)
Expand All @@ -345,12 +348,12 @@ def test_output_model(self):
def test_output_learner_name(self):
"""Check if learner's name properly changes"""
new_name = "Learner Name"
self.widget.apply_button.button.click()
self.click_apply()
self.assertEqual(self.widget.learner.name,
self.widget.name_line_edit.text()
or self.widget.name_line_edit.placeholderText())
self.widget.name_line_edit.setText(new_name)
self.widget.apply_button.button.click()
self.click_apply()
self.wait_until_stop_blocking()
self.assertEqual(self.get_output("Learner").name, new_name)

Expand All @@ -359,14 +362,14 @@ def test_output_model_name(self):
new_name = "Model Name"
self.widget.name_line_edit.setText(new_name)
self.send_signal("Data", self.data)
self.widget.apply_button.button.click()
self.click_apply()
self.wait_until_stop_blocking()
self.assertEqual(self.get_output(self.widget.Outputs.model).name, new_name)

def test_output_model_picklable(self):
"""Check if model can be pickled"""
self.send_signal("Data", self.data)
self.widget.apply_button.button.click()
self.click_apply()
self.wait_until_stop_blocking()
model = self.get_output(self.widget.Outputs.model)
self.assertIsNotNone(model)
Expand All @@ -390,7 +393,7 @@ def test_parameters_default(self):
"""
for dataset in self.valid_datasets:
self.send_signal("Data", dataset)
self.widget.apply_button.button.click()
self.click_apply()
self.wait_until_stop_blocking()
for parameter in self.parameters:
# Skip if the param isn't used for the given data type
Expand All @@ -416,7 +419,7 @@ def test_parameters(self):

for value in parameter.values:
parameter.set_value(value)
self.widget.apply_button.button.click()
self.click_apply()
self.wait_until_stop_blocking()
param = self._get_param_value(self.widget.learner, parameter)
self.assertEqual(
Expand Down
Loading

0 comments on commit b78ff8c

Please sign in to comment.