File: test_owstack.py

package info (click to toggle)
orange3 3.40.0-1
  • links: PTS, VCS
  • area: main
  • in suites: sid
  • size: 15,908 kB
  • sloc: python: 162,745; ansic: 622; makefile: 322; sh: 93; cpp: 77
file content (47 lines) | stat: -rw-r--r-- 2,326 bytes parent folder | download | duplicates (2)
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
# Test methods with long descriptive names can omit docstrings
# pylint: disable=missing-docstring
from Orange.data import Table
from Orange.widgets.model.owstack import OWStackedLearner
from Orange.classification import LogisticRegressionLearner
from Orange.widgets.tests.base import WidgetTest


class TestOWStackedLearner(WidgetTest):
    def setUp(self):
        self.widget = self.create_widget(OWStackedLearner,
                                         stored_settings={"auto_apply": False})
        self.data = Table('iris')

    def test_input_data(self):
        """Check widget's data with data on the input"""
        self.assertEqual(self.widget.data, None)
        self.send_signal(self.widget.Inputs.data, self.data)
        self.assertEqual(self.widget.data, self.data)
        self.wait_until_stop_blocking()

    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(self.widget.Inputs.learners, LogisticRegressionLearner(), 0)
        self.widget.apply_button.button.clicked.emit()
        initial = self.get_output(self.widget.Outputs.learner)
        self.assertIsNotNone(initial, "Does not initialize the learner output")
        self.widget.apply_button.button.clicked.emit()
        newlearner = self.get_output(self.widget.Outputs.learner)
        self.assertIsNot(initial, newlearner,
                         "Does not send a new learner instance on `Apply`.")
        self.assertIsNotNone(newlearner)
        self.assertIsInstance(newlearner, self.widget.LEARNER)

    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(self.widget.Inputs.learners, LogisticRegressionLearner(), 0)
        self.widget.apply_button.button.clicked.emit()
        self.assertIsNone(self.get_output(self.widget.Outputs.model))
        self.send_signal(self.widget.Inputs.data, self.data)
        self.widget.apply_button.button.clicked.emit()
        self.wait_until_stop_blocking()
        model = self.get_output(self.widget.Outputs.model)
        self.assertIsNotNone(model)
        self.assertIsInstance(model, self.widget.LEARNER.__returns__)