From 3aea9276150571c24ef6810ce9b64bdcc79e01e7 Mon Sep 17 00:00:00 2001 From: janezd Date: Fri, 26 Aug 2016 12:34:05 +0200 Subject: [PATCH] Confusion matrix widget: Add tests for selected_learner --- Orange/widgets/evaluate/owconfusionmatrix.py | 1 - Orange/widgets/evaluate/tests/__init__.py | 0 .../evaluate/tests/test_owconfusionmatrix.py | 44 +++++++++++++++++++ 3 files changed, 44 insertions(+), 1 deletion(-) create mode 100644 Orange/widgets/evaluate/tests/__init__.py create mode 100644 Orange/widgets/evaluate/tests/test_owconfusionmatrix.py diff --git a/Orange/widgets/evaluate/owconfusionmatrix.py b/Orange/widgets/evaluate/owconfusionmatrix.py index ac21708be6b..d23592df1a1 100644 --- a/Orange/widgets/evaluate/owconfusionmatrix.py +++ b/Orange/widgets/evaluate/owconfusionmatrix.py @@ -250,7 +250,6 @@ def set_results(self, results): self._init_table(len(class_values)) self.openContext(data.domain.class_var) - print("ZZZ", prev_sel_learner) if not prev_sel_learner or prev_sel_learner[0] >= len(self.learners): self.selected_learner[:] = [0] else: diff --git a/Orange/widgets/evaluate/tests/__init__.py b/Orange/widgets/evaluate/tests/__init__.py new file mode 100644 index 00000000000..e69de29bb2d diff --git a/Orange/widgets/evaluate/tests/test_owconfusionmatrix.py b/Orange/widgets/evaluate/tests/test_owconfusionmatrix.py new file mode 100644 index 00000000000..b9944e36ff6 --- /dev/null +++ b/Orange/widgets/evaluate/tests/test_owconfusionmatrix.py @@ -0,0 +1,44 @@ +import unittest +import ast +import sys + +from Orange.data import Table +from Orange.classification import NaiveBayesLearner, TreeLearner +from Orange.evaluation.testing import CrossValidation +from Orange.widgets.evaluate.owconfusionmatrix import OWConfusionMatrix +from Orange.widgets.tests.base import WidgetTest, WidgetLearnerTestMixin + + +class TestOWClassificationTree(WidgetTest): + @classmethod + def setUpClass(cls): + super().setUpClass() + bayes = NaiveBayesLearner() + tree = TreeLearner() + iris = Table("iris") + titanic = Table("titanic") + common = dict(k=3, store_data=True) + cls.results_1_iris = CrossValidation(iris, [bayes], **common) + cls.results_2_iris = CrossValidation(iris, [bayes, tree], **common) + cls.results_2_titanic = CrossValidation(titanic, [bayes, tree], + **common) + + def setUp(self): + self.widget = self.create_widget(OWConfusionMatrix, + stored_settings={"auto_apply": False}) + + def test_selected_learner(self): + """Check learner and model for various values of all parameters + when pruning parameters are not checked + """ + self.widget.set_results(self.results_2_iris) + self.assertEqual(self.widget.selected_learner, [0]) + self.widget.selected_learner[:] = [1] + self.widget.set_results(self.results_2_titanic) + self.widget.selected_learner[:] = [1] + self.widget.set_results(self.results_1_iris) + self.widget.selected_learner[:] = [0] + self.widget.set_results(None) + self.widget.set_results(self.results_1_iris) + self.widget.selected_learner[:] = [0] +