Example #1
0
    def test_calendar_dates(self):
        data = Table(test_filename("datasets/cyber-security-breaches.tab"))
        self.send_signal(self.widget.Inputs.data, data)
        simulate.combobox_activate_item(self.widget.cond_list.cellWidget(0, 0),
                                        "Date_Posted_or_Updated",
                                        delay=0)
        value_combo = self.widget.cond_list.cellWidget(0, 2).children()[1]
        self.assertIsInstance(value_combo, DateTimeWidget)

        # first displayed date is min date
        self.assertEqual(value_combo.date(), QDate(2014, 1, 23))
        self.assertEqual(len(self.get_output("Matching Data")), 691)
        self.widget.remove_all_button.click()
        self.enterFilter("Date_Posted_or_Updated", "is below",
                         QDate(2014, 4, 17))
        self.assertEqual(len(self.get_output("Matching Data")), 840)
        self.enterFilter("Date_Posted_or_Updated", "is greater than",
                         QDate(2014, 6, 30))
        self.assertIsNone(self.get_output("Matching Data"))
        self.widget.remove_all_button.click()
        # date is in range min-max date
        self.enterFilter("Date_Posted_or_Updated", "equals", QDate(2013, 1, 1))
        self.assertEqual(self.widget.conditions[0][2][0], QDate(2014, 1, 23))
        self.enterFilter("Date_Posted_or_Updated", "equals", QDate(2015, 1, 1))
        self.assertEqual(self.widget.conditions[1][2][0], QDate(2014, 6, 30))
        self.widget.remove_all_button.click()
        # no date crossings
        self.enterFilter("Date_Posted_or_Updated", "is between",
                         QDate(2014, 4, 17), QDate(2014, 1, 23))
        self.assertEqual(self.widget.conditions[0][2],
                         (QDate(2014, 4, 17), QDate(2014, 4, 17)))
        self.widget.remove_all_button.click()
        self.enterFilter("Date_Posted_or_Updated", "is between",
                         QDate(2014, 4, 17), QDate(2014, 4, 30))
        self.assertEqual(len(self.get_output("Matching Data")), 58)
Example #2
0
    def test_select_by_click(self):
        view = self.widget.table_view
        self.send_signal(self.widget.Inputs.data, self.heart_disease)
        self.agg_checkboxes[Pivot.Functions.Sum.value].click()
        simulate.combobox_activate_item(self.widget.controls.val_feature,
                                        self.heart_disease.domain[0].name)

        # column in a group
        QTest.mouseClick(view.viewport(), Qt.LeftButton, pos=QPoint(208, 154))
        self.assertSetEqual({(3, 0), (2, 0)}, view.get_selection())

        # column
        QTest.mouseClick(view.viewport(), Qt.LeftButton, pos=QPoint(340, 40))
        self.assertSetEqual({(0, 1), (3, 1), (1, 1), (2, 1)},
                            view.get_selection())

        # group
        QTest.mouseClick(view.viewport(), Qt.LeftButton, pos=QPoint(155, 75))
        self.assertSetEqual({(0, 1), (1, 0), (0, 0), (1, 1)},
                            view.get_selection())

        # all
        QTest.mouseClick(view.viewport(), Qt.LeftButton, pos=QPoint(400, 198))
        self.assertSetEqual(
            {(0, 1), (0, 0), (3, 0), (3, 1), (2, 1), (2, 0), (1, 0), (1, 1)},
            view.get_selection())
Example #3
0
    def test_nan_plot(self):
        data = datasets.missing_data_1()
        espy = EventSpy(self.widget, OWLinearProjection.ReplotRequest)
        with excepthook_catch():
            self.send_signal(self.widget.Inputs.data, data)
            # ensure delayed replot request is processed
            if not espy.events():
                assert espy.wait(1000)

        cb = self.widget.graph.controls
        simulate.combobox_run_through_all(cb.attr_color)
        simulate.combobox_run_through_all(cb.attr_size)

        data = data.copy()
        data.X[:, 0] = np.nan
        data.Y[:] = np.nan

        spy = EventSpy(self.widget, OWLinearProjection.ReplotRequest)
        self.send_signal(self.widget.Inputs.data, data)
        self.send_signal(self.widget.Inputs.data_subset, data[2:3])
        if not spy.events():
            assert spy.wait()

        with excepthook_catch():
            simulate.combobox_activate_item(cb.attr_color, "X1")

        with excepthook_catch():
            simulate.combobox_activate_item(cb.attr_size, "X1")
Example #4
0
 def test_unique_domain(self):
     simulate.combobox_activate_item(self.widget.manifold_methods_combo, "MDS")
     data = possible_duplicate_table('C0', class_var=True)
     self.send_signal(self.widget.Inputs.data, data)
     self.widget.apply_button.button.click()
     out = self.get_output(self.widget.Outputs.transformed_data)
     self.assertTrue(out.domain.attributes[0], 'C0 (1)')
Example #5
0
 def test_overlap(self):
     """Test option 'Overlap' in 'Size' combo box"""
     self.send_signal(self.widget.Inputs.data, self.data)
     self.assertEqual(len(set(self.widget.graph.get_sizes())), 1)
     simulate.combobox_activate_item(self.widget.controls.attr_size,
                                     OWPlotGUI.SizeByOverlap)
     self.assertGreater(len(set(self.widget.graph.get_sizes())), 1)
Example #6
0
 def test_handle_primitive_metas(self):
     """Set 'Color' from continuous meta attribute"""
     d, attrs = self.data.domain, self.data.domain.attributes
     data = self.data.transform(Domain(attrs[:2], d.class_vars, attrs[2:]))
     self.send_signal(self.widget.Inputs.data, data)
     simulate.combobox_activate_item(self.widget.controls.attr_color,
                                     data.domain.metas[0].name)
    def test_nan_plot(self):
        data = datasets.missing_data_1()
        espy = EventSpy(self.widget, OWLinearProjection.ReplotRequest)
        with excepthook_catch():
            self.send_signal(self.widget.Inputs.data, data)
            # ensure delayed replot request is processed
            if not espy.events():
                assert espy.wait(1000)

        cb = self.widget.graph.controls
        simulate.combobox_run_through_all(cb.attr_color)
        simulate.combobox_run_through_all(cb.attr_size)

        data = data.copy()
        data.X[:, 0] = np.nan
        data.Y[:] = np.nan

        spy = EventSpy(self.widget, OWLinearProjection.ReplotRequest)
        self.send_signal(self.widget.Inputs.data, data)
        self.send_signal(self.widget.Inputs.data_subset, data[2:3])
        if not spy.events():
            assert spy.wait()

        with excepthook_catch():
            simulate.combobox_activate_item(cb.attr_color, "X1")

        with excepthook_catch():
            simulate.combobox_activate_item(cb.attr_size, "X1")
Example #8
0
    def test_summary(self):
        """Check if the status bar is updated when data is received"""
        data = self.iris
        input_sum = self.widget.info.set_input_summary = Mock()
        output_sum = self.widget.info.set_output_summary = Mock()

        self.send_signal(self.widget.Inputs.data, data)
        input_sum.assert_called_with(len(data), format_summary_details(data))
        output = self.get_output(self.widget.Outputs.filtered_data)
        self.assertIsNone(output)
        simulate.combobox_activate_item(self.widget.controls.row_feature,
                                        self.iris.domain.attributes[0].name)
        simulate.combobox_activate_item(self.widget.controls.col_feature,
                                        self.iris.domain.class_var.name)
        self.widget.table_view.set_selection(set([(11, 0), (11, 1), (12, 0)]))
        self.widget.table_view.selection_changed.emit()
        filtered = self.get_output(self.widget.Outputs.filtered_data)
        pivot = self.get_output(self.widget.Outputs.pivot_table)
        grouped = self.get_output(self.widget.Outputs.grouped_data)
        output_sum.assert_called_with(
            f"{len(pivot)}, {len(filtered)}, {len(grouped)}",
            format_multiple_summaries([("Pivot table", pivot),
                                       ("Filtered data", filtered),
                                       ("Grouped data", grouped)]),
            format=1)
        input_sum.reset_mock()
        output_sum.reset_mock()
        self.send_signal(self.widget.Inputs.data, None)
        input_sum.assert_called_once()
        self.assertEqual(input_sum.call_args[0][0].brief, "")
        output_sum.assert_called_once()
        self.assertEqual(output_sum.call_args[0][0].brief, "")
Example #9
0
    def test_select_by_click(self):
        view = self.widget.table_view
        self.send_signal(self.widget.Inputs.data, self.heart_disease)
        self.agg_checkboxes[Pivot.Functions.Sum.value].click()
        simulate.combobox_activate_item(self.widget.controls.val_feature,
                                        self.heart_disease.domain[0].name)

        def pos(row, col) -> QPoint:
            model = view.model()
            rect = view.visualRect(  # pylint:disable=protected-access
                model.index(row + view._n_leading_rows,
                            col + view._n_leading_cols))
            return rect.center()

        # column in a group
        QTest.mouseClick(view.viewport(), Qt.LeftButton, pos=pos(2, 0))
        self.assertSetEqual({(3, 0), (2, 0)}, view.get_selection())

        # column
        QTest.mouseClick(view.viewport(), Qt.LeftButton, pos=pos(-1, 1))
        self.assertSetEqual({(0, 1), (3, 1), (1, 1), (2, 1)},
                            view.get_selection())

        # group
        QTest.mouseClick(view.viewport(), Qt.LeftButton, pos=pos(0, -1))
        self.assertSetEqual({(0, 1), (1, 0), (0, 0), (1, 1)},
                            view.get_selection())

        # all
        QTest.mouseClick(view.viewport(), Qt.LeftButton, pos=pos(4, 2))
        self.assertSetEqual(
            {(0, 1), (0, 0), (3, 0), (3, 1), (2, 1), (2, 0), (1, 0), (1, 1)},
            view.get_selection())
Example #10
0
 def test_handle_primitive_metas(self):
     """Set 'Color' from continuous meta attribute"""
     d, attrs = self.data.domain, self.data.domain.attributes
     data = self.data.transform(Domain(attrs[:2], d.class_vars, attrs[2:]))
     self.send_signal(self.widget.Inputs.data, data)
     simulate.combobox_activate_item(self.widget.controls.attr_color,
                                     data.domain.metas[0].name)
Example #11
0
    def test_settings_correctly_restored(self):
        """
        This test checks if contextsettings are correctly restored after
        dataset changed.
        """
        w = self.widget

        self.send_signal(w.Inputs.data, self.iris)
        w.controls.apply_pca.setChecked(False)
        w.controls.pca_components.setValue(2)
        simulate.combobox_activate_item(w.controls.metric_idx, "Manhattan")
        w.controls.normalize.setChecked(False)
        w.controls.k_neighbors.setValue(4)
        w.controls.resolution.setValue(0.5)

        self.send_signal(w.Inputs.data, Table("zoo"))
        w.controls.apply_pca.setChecked(True)
        w.controls.pca_components.setValue(3)
        simulate.combobox_activate_item(w.controls.metric_idx, "Euclidean")
        w.controls.normalize.setChecked(True)
        w.controls.k_neighbors.setValue(5)
        w.controls.resolution.setValue(1)

        self.send_signal(w.Inputs.data, self.iris)
        self.assertFalse(w.apply_pca)
        self.assertEqual(2, w.pca_components)
        self.assertEqual(1, w.metric_idx)
        self.assertFalse(w.normalize)
        self.assertEqual(4, w.k_neighbors)
        self.assertEqual(0.5, w.resolution)
Example #12
0
 def test_attr_label_metas(self, timeout=DEFAULT_TIMEOUT):
     """Set 'Label' from string meta attribute"""
     cont = Continuize(multinomial_treatment=Continuize.AsOrdinal)
     data = cont(Table("zoo"))
     self.send_signal(self.widget.Inputs.data, data)
     self.wait_until_finished(timeout=timeout)
     simulate.combobox_activate_item(self.widget.controls.attr_label,
                                     data.domain[-1].name)
Example #13
0
    def test_send_report(self, _):
        simulate.combobox_activate_item(self.widget.controls.mode, "Content")
        self.widget.controls.max_tweets.setValue(2)
        self.widget.word_list = ["OrangeDataMiner"]
        self.widget.search_button.click()
        self.wait_until_finished()

        self.widget.send_report()
Example #14
0
 def test_time_variable(self):
     """ Spiralogram should work with TimeVariable. """
     w = self.widget
     self.send_signal(w.Inputs.time_series, self.philadelphia)
     # select time variable
     simulate.combobox_activate_item(w.attr_cb, 'Datetime')
     # test all possibilities for aggregations
     simulate.combobox_run_through_all(w.combo_func)
Example #15
0
 def __set_value(widget, value):
     if isinstance(widget, QLineEdit):
         QTest.mouseClick(widget, Qt.LeftButton)
         QTest.keyClicks(widget, value, delay=0)
         QTest.keyClick(widget, Qt.Key_Enter)
     elif isinstance(widget, QComboBox):
         simulate.combobox_activate_item(widget, value)
     else:
         raise ValueError("Unsupported widget {}".format(widget))
Example #16
0
 def test_attr_label_metas(self, timeout=DEFAULT_TIMEOUT):
     """Set 'Label' from string meta attribute"""
     data = Table("zoo")
     self.send_signal(self.widget.Inputs.data, data)
     if self.widget.isBlocking():
         spy = QSignalSpy(self.widget.blockingStateChanged)
         self.assertTrue(spy.wait(timeout))
     simulate.combobox_activate_item(self.widget.controls.attr_label,
                                     data.domain[-1].name)
Example #17
0
 def __set_value(widget, value):
     if isinstance(widget, QLineEdit):
         QTest.mouseClick(widget, Qt.LeftButton)
         QTest.keyClicks(widget, value, delay=0)
         QTest.keyClick(widget, Qt.Key_Enter)
     elif isinstance(widget, QComboBox):
         simulate.combobox_activate_item(widget, value)
     else:
         raise ValueError("Unsupported widget {}".format(widget))
Example #18
0
 def test_overlap(self):
     self.send_signal(self.signal_name, self.signal_data)
     if self.widget.isBlocking():
         spy = QSignalSpy(self.widget.blockingStateChanged)
         self.assertTrue(spy.wait(5000))
     self.assertEqual(len(set(self.widget.graph.get_sizes())), 1)
     simulate.combobox_activate_item(self.widget.controls.attr_size,
                                     OWPlotGUI.SizeByOverlap)
     self.assertEqual(len(set(self.widget.graph.get_sizes())), 1)
 def test_data_column_infs(self):
     """
     Scatter Plot should not crash on data with infinity values
     GH-2707
     GH-2684
     """
     table = datasets.data_one_column_infs()
     self.send_signal(self.widget.Inputs.data, table)
     attr_x = self.widget.controls.attr_x
     simulate.combobox_activate_item(attr_x, "b")
Example #20
0
 def test_data_column_infs(self):
     """
     Scatter Plot should not crash on data with infinity values
     GH-2707
     GH-2684
     """
     table = datasets.data_one_column_infs()
     self.send_signal(self.widget.Inputs.data, table)
     attr_x = self.widget.controls.attr_x
     simulate.combobox_activate_item(attr_x, "b")
Example #21
0
 def test_output_pivot_table(self):
     self.send_signal(self.widget.Inputs.data, self.iris)
     simulate.combobox_activate_item(self.widget.controls.val_feature,
                                     self.iris.domain.attributes[0].name)
     table = self.get_output(self.widget.Outputs.pivot_table)
     names = ["iris", "Aggregate", "Iris-setosa",
              "Iris-versicolor", "Iris-virginica"]
     self.assertListEqual(names, [a.name for a in table.domain.variables])
     self.send_signal(self.widget.Inputs.data, None)
     self.assertIsNone(self.get_output(self.widget.Outputs.pivot_table))
Example #22
0
 def test_attr_label_metas(self, timeout=DEFAULT_TIMEOUT):
     """Set 'Label' from string meta attribute"""
     cont = Continuize(multinomial_treatment=Continuize.AsOrdinal)
     data = cont(Table("zoo"))
     self.send_signal(self.widget.Inputs.data, data)
     if self.widget.isBlocking():
         spy = QSignalSpy(self.widget.blockingStateChanged)
         self.assertTrue(spy.wait(timeout))
     simulate.combobox_activate_item(self.widget.controls.attr_label,
                                     data.domain[-1].name)
Example #23
0
    def test_empty_query_error(self):
        self.widget.search_button.click()
        self.assertTrue(self.widget.Error.empty_query.is_shown())
        self.assertTrue(str(self.widget.Error.empty_query).endswith("keywords."))
        self.assertIsNone(self.get_output(self.widget.Outputs.corpus))

        simulate.combobox_activate_item(self.widget.controls.mode, "Author")
        self.widget.search_button.click()
        self.assertTrue(self.widget.Error.empty_query.is_shown())
        self.assertTrue(str(self.widget.Error.empty_query).endswith("authors."))
        self.assertIsNone(self.get_output(self.widget.Outputs.corpus))
Example #24
0
    def test_target_prior(self):
        w = self.widget
        self.send_signal(w.Inputs.evaluation_results, self.res)
        # hard selected
        self.assertEqual(np.round(4 / 12 * 100), w.target_prior)

        simulate.combobox_activate_item(w.controls.target_index, "none")
        self.assertEqual(np.round(3 / 12 * 100), w.target_prior)

        simulate.combobox_activate_item(w.controls.target_index, "soft")
        self.assertEqual(np.round(5 / 12 * 100), w.target_prior)
Example #25
0
    def test_correlation_type(self):
        c_type = self.widget.controls.correlation_type
        self.send_signal(self.widget.Inputs.data, self.data_cont)
        self.wait_until_finished()
        self.process_events()
        pearson_corr = self.get_output(self.widget.Outputs.correlations)

        simulate.combobox_activate_item(c_type, "Spearman correlation")
        self.wait_until_finished()
        self.process_events()
        sperman_corr = self.get_output(self.widget.Outputs.correlations)
        self.assertFalse((pearson_corr.X == sperman_corr.X).all())
    def test_correlation_type(self):
        c_type = self.widget.controls.correlation_type
        self.send_signal(self.widget.Inputs.data, self.data_cont)
        time.sleep(0.1)
        self.process_events()
        pearson_corr = self.get_output(self.widget.Outputs.correlations)

        simulate.combobox_activate_item(c_type, "Spearman correlation")
        time.sleep(0.1)
        self.process_events()
        sperman_corr = self.get_output(self.widget.Outputs.correlations)
        self.assertFalse((pearson_corr.X == sperman_corr.X).all())
Example #27
0
 def test_author_not_existing(self):
     with patch("tweepy.Client.get_user") as m:
         m.return_value = MagicMock(data=None)
         simulate.combobox_activate_item(self.widget.controls.mode, "Author")
         self.widget.word_list = ["orange"]
         self.widget.search_button.click()
         self.wait_until_finished()
         self.assertTrue(self.widget.Error.wrong_author.is_shown())
         self.assertEqual(
             "Author 'orange' does not exist.", str(self.widget.Error.wrong_author)
         )
         self.assertEqual("Search", self.widget.search_button.text())
Example #28
0
 def test_metas_zero_column(self):
     """
     Prevent crash when metas column is zero.
     GH-2775
     """
     data = Table("iris")
     domain = data.domain
     domain = Domain(domain.attributes[:3], domain.class_vars, domain.attributes[3:])
     data = data.transform(domain)
     data.metas[:, 0] = 0
     w = self.widget
     self.send_signal(w.Inputs.data, data)
     simulate.combobox_activate_item(w.controls.attr_x, domain.metas[0].name)
Example #29
0
 def test_metas_zero_column(self):
     """
     Prevent crash when metas column is zero.
     GH-2775
     """
     data = Table("iris")
     domain = data.domain
     domain = Domain(domain.attributes[:3], domain.class_vars, domain.attributes[3:])
     data = data.transform(domain)
     data.metas[:, 0] = 0
     w = self.widget
     self.send_signal(w.Inputs.data, data)
     simulate.combobox_activate_item(w.controls.attr_x, domain.metas[0].name)
 def test_color_pass_black(self):
     """
     Do not fail when continuous variable has a color
     gradient which passes through black.
     GH-27
     GH-28
     """
     data = Table("iris")
     colors = data.domain.attributes[0].colors[:2] + (True, )
     data.domain.attributes[0].colors = colors
     self.send_signal(self.widget.Inputs.data, data)
     cb_attr_color = self.widget.controls.color_attr
     simulate.combobox_activate_item(cb_attr_color,
                                     data.domain.attributes[0].name)
    def test_language_changed(self):
        """Test if output changes on language change"""
        self.send_signal(self.widget.Inputs.corpus, self.corpus)
        self.assertEqual(self.widget.multi_box.count(),
                         len(self.widget.MULTI_LANG))

        # default for Liu Hu should be English
        self.widget.liu_hu.click()
        simulate.combobox_activate_item(self.widget.liu_lang, "English")
        output_eng = self.get_output(self.widget.Outputs.corpus)

        simulate.combobox_activate_item(self.widget.liu_lang, "Slovenian")
        output_slo = self.get_output(self.widget.Outputs.corpus)
        self.assertFalse(array_equal(output_eng.X, output_slo.X))
    def enterFilter(self, variable, filter, value1=None, value2=None):
        row = self.widget.cond_list.model().rowCount()
        self.widget.add_button.click()

        var_combo = self.widget.cond_list.cellWidget(row, 0)
        simulate.combobox_activate_item(var_combo, variable.name, delay=0)

        oper_combo = self.widget.cond_list.cellWidget(row, 1)
        simulate.combobox_activate_item(oper_combo, filter, delay=0)

        value_inputs = self.__get_value_widgets(row)
        for i, value in enumerate([value1, value2]):
            if value is None:
                continue
            self.__set_value(value_inputs[i], value)
Example #33
0
    def test_max_tweets(self):
        simulate.combobox_activate_item(self.widget.controls.mode, "Content")
        self.widget.controls.max_tweets.setValue(2)
        self.widget.word_list = ["OrangeDataMiner"]
        self.widget.search_button.click()

        output = self.get_output(self.widget.Outputs.corpus)
        self.assertEqual(2, len(output))

        self.widget.controls.max_tweets.setValue(3)
        self.widget.word_list = ["OrangeDataMiner"]
        self.widget.search_button.click()

        output = self.get_output(self.widget.Outputs.corpus)
        self.assertEqual(3, len(output))
Example #34
0
    def enterFilter(self, variable, filter, value1=None, value2=None):
        # pylint: disable=redefined-builtin
        row = self.widget.cond_list.model().rowCount()
        self.widget.add_button.click()

        var_combo = self.widget.cond_list.cellWidget(row, 0)
        simulate.combobox_activate_item(var_combo, variable.name, delay=0)

        oper_combo = self.widget.cond_list.cellWidget(row, 1)
        simulate.combobox_activate_item(oper_combo, filter, delay=0)

        value_inputs = self.__get_value_widgets(row)
        for i, value in enumerate([value1, value2]):
            if value is None:
                continue
            self.__set_value(value_inputs[i], value)
Example #35
0
    def test_remove_redundant_instance(self):
        cb = self.widget.feature_combo
        data = Table("iris")

        self.send_signal(self.widget.Inputs.data, data)
        simulate.combobox_activate_item(cb, "petal length")
        self.widget.controls.remove_redundant_inst.setChecked(True)
        self.wait_until_finished()

        output = self.get_output(self.widget.Outputs.data)
        self.assertEqual(len(output), 3)
        self.assertNotIn("petal length", output.metas)

        self.widget.controls.remove_redundant_inst.setChecked(False)
        self.wait_until_finished()
        self.assertEqual(len(self.get_output(self.widget.Outputs.data)), 4)
 def test_preprocessed(self):
     widget = self.create_widget(OWSentimentAnalysis)
     corpus = self.corpus.copy()
     pp_list = [
         preprocess.LowercaseTransformer(),
         preprocess.WordPunctTokenizer()
     ]
     for pp in pp_list:
         corpus = pp(corpus)
     self.send_signal(widget.Inputs.corpus, corpus)
     self.assertTrue(widget.pp_corpus)
     widget.liu_hu.click()
     simulate.combobox_activate_item(widget.liu_lang, "English")
     self.assertTrue(widget.pp_corpus)
     self.send_signal(widget.Inputs.corpus, None)
     self.assertIsNone(widget.pp_corpus)
Example #37
0
    def enterFilter(self, variable, filter, value=None, value2=None):
        row = self.widget.cond_list.model().rowCount()
        self.widget.add_button.click()

        var_combo = self.widget.cond_list.cellWidget(row, 0)
        simulate.combobox_activate_item(var_combo, variable.name, delay=0)

        oper_combo = self.widget.cond_list.cellWidget(row, 1)
        simulate.combobox_activate_item(oper_combo, filter, delay=0)

        value_inputs = self._get_value_line_edits(row)
        for i, value in enumerate([value, value2]):
            if value is None:
                continue
            QTest.mouseClick(value_inputs[i], Qt.LeftButton)
            QTest.keyClicks(value_inputs[i], value, delay=0)
            QTest.keyClick(value_inputs[i], Qt.Key_Enter)
    def enterFilter(self, variable, filter, value=None, value2=None):
        row = self.widget.cond_list.model().rowCount()
        self.widget.add_button.click()

        var_combo = self.widget.cond_list.cellWidget(row, 0)
        simulate.combobox_activate_item(var_combo, variable.name, delay=0)

        oper_combo = self.widget.cond_list.cellWidget(row, 1)
        simulate.combobox_activate_item(oper_combo, filter, delay=0)

        value_inputs = self._get_value_line_edits(row)
        for i, value in enumerate([value, value2]):
            if value is None:
                continue
            QTest.mouseClick(value_inputs[i], Qt.LeftButton)
            QTest.keyClicks(value_inputs[i], value, delay=0)
            QTest.keyClick(value_inputs[i], Qt.Key_Enter)
Example #39
0
    def enterFilter(self, variable, filter, value1=None, value2=None):
        # pylint: disable=redefined-builtin
        row = self.widget.cond_list.model().rowCount()
        self.widget.add_button.click()

        var_combo = self.widget.cond_list.cellWidget(row, 0)
        name = variable.name if isinstance(variable, Variable) else variable
        simulate.combobox_activate_item(var_combo, name, delay=0)

        oper_combo = self.widget.cond_list.cellWidget(row, 1)
        simulate.combobox_activate_item(oper_combo, filter, delay=0)

        value_inputs = self.__get_value_widgets(row)
        for i, value in enumerate([value1, value2]):
            if value is None:
                continue
            self.__set_value(value_inputs[i], value)
Example #40
0
    def test_metrics(self):
        # Select t-SNE method, which is the only method that supports metrics
        simulate.combobox_activate_item(self.widget.manifold_methods_combo, "t-SNE")

        def __callback():
            # Send data to input
            self.send_signal(self.widget.Inputs.data, self.iris)
            self.widget.apply_button.button.click()
            self.assertFalse(self.widget.Error.manifold_error.is_shown())

            # Clear input
            self.send_signal(self.widget.Inputs.data, None)
            self.widget.apply_button.button.click()
            self.assertFalse(self.widget.Error.manifold_error.is_shown())

        simulate.combobox_run_through_all(
            self.widget.tsne_editor.metric_combo, callback=__callback,
        )
Example #41
0
 def test_handle_metas(self):
     """
     Scatter Plot Graph can handle metas
     GH-2699
     """
     w = self.widget
     data = Table("iris")
     domain = Domain(
         attributes=data.domain.attributes[:2],
         class_vars=data.domain.class_vars,
         metas=data.domain.attributes[2:]
     )
     data = data.transform(domain)
     # Sometimes floats in metas are saved as objects
     data.metas = data.metas.astype(object)
     self.send_signal(w.Inputs.data, data)
     simulate.combobox_activate_item(w.cb_attr_x, data.domain.metas[1].name)
     simulate.combobox_activate_item(w.controls.graph.attr_color, data.domain.metas[0].name)
     w.update_graph()
Example #42
0
    def test_log_scale_slider(self):
        # Disabled when no tree
        self.assertFalse(self.widget.log_scale_box.isEnabled(),
                         'Should be disabled with no tree')

        self.send_signal(self.widget.Inputs.tree, self.titanic)
        # No size adjustment
        simulate.combobox_activate_item(self.widget.size_calc_combo, 'Normal')
        self.assertFalse(self.widget.log_scale_box.isEnabled(),
                         'Should be disabled when no size adjustment')
        # Square root adjustment
        simulate.combobox_activate_item(self.widget.size_calc_combo, 'Square root')
        self.assertFalse(self.widget.log_scale_box.isEnabled(),
                         'Should be disabled when square root size adjustment')
        # Log adjustment
        simulate.combobox_activate_item(self.widget.size_calc_combo, 'Logarithmic')
        self.assertTrue(self.widget.log_scale_box.isEnabled(),
                        'Should be enabled when square root size adjustment')

        # Get squares for one value of log factor
        self.widget.log_scale_box.setValue(1)
        inital_sizing_sq = [n.square for n in self.get_tree_nodes()]
        # Get squares for a different value of log factor
        self.widget.log_scale_box.setValue(2)
        updated_sizing_sq = [n.square for n in self.get_tree_nodes()]

        # Only compare to the -1 list element since the base square is always
        # the same
        self.assertTrue(
            any([x != y for x, y in zip(inital_sizing_sq, updated_sizing_sq)]),
            'Squares are drawn in same positions after changing log factor')
Example #43
0
    def test_target_changing(self):
        data = Table("iris")
        w = self.widget  #: OWTestLearners

        w.n_folds = 2
        self.send_signal(self.widget.Inputs.train_data, data)
        self.send_signal(self.widget.Inputs.learner,
                         LogisticRegressionLearner(), 0, wait=5000)

        average_auc = float(w.view.model().item(0, 1).text())

        simulate.combobox_activate_item(w.controls.class_selection, "Iris-setosa")
        setosa_auc = float(w.view.model().item(0, 1).text())

        simulate.combobox_activate_item(w.controls.class_selection, "Iris-versicolor")
        versicolor_auc = float(w.view.model().item(0, 1).text())

        simulate.combobox_activate_item(w.controls.class_selection, "Iris-virginica")
        virginica_auc = float(w.view.model().item(0, 1).text())

        self.assertGreater(average_auc, versicolor_auc)
        self.assertGreater(average_auc, virginica_auc)
        self.assertLess(average_auc, setosa_auc)
        self.assertGreater(setosa_auc, versicolor_auc)
        self.assertGreater(setosa_auc, virginica_auc)
Example #44
0
    def test_color_is_optional(self):
        zoo = Table("zoo")
        backbone, breathes, airborne, type = \
            [zoo.domain[x] for x in ["backbone", "breathes", "airborne", "type"]]
        default_x, default_y, default_color = \
            zoo.domain[0], zoo.domain[1], zoo.domain.class_var
        attr_x = self.widget.controls.attr_x
        attr_y = self.widget.controls.attr_y
        attr_color = self.widget.controls.graph.attr_color

        # Send dataset, ensure defaults are what we expect them to be
        self.send_signal(self.widget.Inputs.data, zoo)
        self.assertEqual(attr_x.currentText(), default_x.name)
        self.assertEqual(attr_y.currentText(), default_y.name)
        self.assertEqual(attr_color.currentText(), default_color.name)
        # Select different values
        simulate.combobox_activate_item(attr_x, backbone.name)
        simulate.combobox_activate_item(attr_y, breathes.name)
        simulate.combobox_activate_item(attr_color, airborne.name)

        # Send compatible dataset, values should not change
        zoo2 = zoo[:, (backbone, breathes, airborne, type)]
        self.send_signal(self.widget.Inputs.data, zoo2)
        self.assertEqual(attr_x.currentText(), backbone.name)
        self.assertEqual(attr_y.currentText(), breathes.name)
        self.assertEqual(attr_color.currentText(), airborne.name)

        # Send dataset without color variable
        # x and y should remain, color reset to default
        zoo3 = zoo[:, (backbone, breathes, type)]
        self.send_signal(self.widget.Inputs.data, zoo3)
        self.assertEqual(attr_x.currentText(), backbone.name)
        self.assertEqual(attr_y.currentText(), breathes.name)
        self.assertEqual(attr_color.currentText(), default_color.name)

        # Send dataset without x
        # y and color should be the same as with zoo
        zoo4 = zoo[:, (default_x, default_y, breathes, airborne, type)]
        self.send_signal(self.widget.Inputs.data, zoo4)
        self.assertEqual(attr_x.currentText(), default_x.name)
        self.assertEqual(attr_y.currentText(), default_y.name)
        self.assertEqual(attr_color.currentText(), default_color.name)

        # Send dataset compatible with zoo2 and zoo3
        # Color should reset to one in zoo3, as it was used more
        # recently
        zoo5 = zoo[:, (default_x, backbone, breathes, airborne, type)]
        self.send_signal(self.widget.Inputs.data, zoo5)
        self.assertEqual(attr_x.currentText(), backbone.name)
        self.assertEqual(attr_y.currentText(), breathes.name)
        self.assertEqual(attr_color.currentText(), type.name)
Example #45
0
    def test_data_column_nans(self):
        """
        ValueError cannot convert float NaN to integer.
        In case when all column values are NaN then it throws that error.
        GH-2061
        """
        table = datasets.data_one_column_nans()
        self.send_signal(self.widget.Inputs.data, table)
        cb_attr_color = self.widget.controls.graph.attr_color
        simulate.combobox_activate_item(cb_attr_color, "b")
        simulate.combobox_activate_item(self.widget.cb_attr_x, "a")
        simulate.combobox_activate_item(self.widget.cb_attr_y, "a")

        self.widget.update_graph()
Example #46
0
    def test_color_is_optional(self):
        heart = Table("heart_disease")
        age, rest_sbp, max_hr, cholesterol, gender, narrowing = \
            [heart.domain[x]
             for x in ["age", "rest SBP", "max HR", "cholesterol", "gender",
                       "diameter narrowing"]]
        attr_x = self.widget.controls.attr_x
        attr_y = self.widget.controls.attr_y
        attr_color = self.widget.controls.attr_color

        # Send dataset, ensure defaults are what we expect them to be
        self.send_signal(self.widget.Inputs.data, heart)
        self.assertEqual(attr_x.currentText(), age.name)
        self.assertEqual(attr_y.currentText(), rest_sbp.name)
        self.assertEqual(attr_color.currentText(), narrowing.name)
        # Select different values
        simulate.combobox_activate_item(attr_x, max_hr.name)
        simulate.combobox_activate_item(attr_y, cholesterol.name)
        simulate.combobox_activate_item(attr_color, gender.name)

        # Send compatible dataset, values should not change
        heart2 = heart[:, (cholesterol, gender, max_hr, narrowing)]
        self.send_signal(self.widget.Inputs.data, heart2)
        simulate.combobox_activate_item(attr_x, max_hr.name)
        simulate.combobox_activate_item(attr_y, cholesterol.name)
        simulate.combobox_activate_item(attr_color, gender.name)

        # Send dataset without color variable
        # x and y should remain, color reset to default
        heart3 = heart[:, (age, max_hr, cholesterol, narrowing)]
        self.send_signal(self.widget.Inputs.data, heart3)
        simulate.combobox_activate_item(attr_x, max_hr.name)
        simulate.combobox_activate_item(attr_y, cholesterol.name)
        self.assertEqual(attr_color.currentText(), narrowing.name)

        # Send dataset without x
        # y and color should be the same as with heart
        heart4 = heart[:, (age, rest_sbp, cholesterol, narrowing)]
        self.send_signal(self.widget.Inputs.data, heart4)
        self.assertEqual(attr_x.currentText(), age.name)
        self.assertEqual(attr_y.currentText(), rest_sbp.name)
        self.assertEqual(attr_color.currentText(), narrowing.name)

        # Send dataset compatible with heart2 and heart3
        # Color should reset to one in heart3, as it was used more
        # recently
        heart5 = heart[:, (age, max_hr, cholesterol, gender, narrowing)]
        self.send_signal(self.widget.Inputs.data, heart5)
        simulate.combobox_activate_item(attr_x, max_hr.name)
        simulate.combobox_activate_item(attr_y, cholesterol.name)
        self.assertEqual(attr_color.currentText(), narrowing.name)
Example #47
0
    def test_value_edit(self):
        data = Table("heart_disease")[::10]
        self.send_signal(self.widget.Inputs.data, data)
        widget = self.widget
        model = widget.varmodel
        view = widget.varview
        selmodel = view.selectionModel()
        varbg = widget.variable_button_group

        def selectvars(varlist, command=selmodel.ClearAndSelect):
            indices = [data.domain.index(var) for var in varlist]
            itemsel = QItemSelection()
            for ind in indices:
                midx = model.index(ind)
                itemsel.select(midx, midx)
            selmodel.select(itemsel, command)

        def effective_method(var):
            return widget.get_method_for_column(data.domain.index(var))

        # select 'chest pain'
        selectvars(['chest pain'])
        self.assertTrue(widget.value_combo.isVisibleTo(widget) and
                        widget.value_combo.isEnabledTo(widget))
        self.assertEqual(varbg.checkedId(), Method.AsAboveSoBelow)

        simulate.combobox_activate_item(
            widget.value_combo, data.domain["chest pain"].values[1])
        # The 'Value' (impute.Default) should have been selected automatically
        self.assertEqual(varbg.checkedId(), Method.Default)
        imputer = effective_method('chest pain')
        self.assertIsInstance(imputer, impute.Default)
        self.assertEqual(imputer.default, 1)

        # select continuous 'rest SBP' and 'cholesterol' variables
        selectvars(["rest SBP", "cholesterol"])
        self.assertTrue(widget.value_double.isVisibleTo(widget) and
                        widget.value_double.isEnabledTo(widget))
        self.assertEqual(varbg.checkedId(), Method.AsAboveSoBelow)
        widget.value_double.setValue(-1.0)
        QTest.keyClick(self.widget.value_double, Qt.Key_Enter)
        # The 'Value' (impute.Default) should have been selected automatically
        self.assertEqual(varbg.checkedId(), Method.Default)
        imputer = effective_method("rest SBP")
        self.assertIsInstance(imputer, impute.Default)
        self.assertEqual(imputer.default, -1.0)
        imputer = effective_method("cholesterol")
        self.assertIsInstance(imputer, impute.Default)
        self.assertEqual(imputer.default, -1.0)

        # Add 'chest pain' to the selection and ensure the value stack is
        # disabled
        selectvars(["chest pain"], selmodel.Select)
        self.assertEqual(varbg.checkedId(), -1)
        self.assertFalse(widget.value_combo.isEnabledTo(widget) and
                         widget.value_double.isEnabledTo(widget))

        # select 'chest pain' only and check that the selected value is
        # restored in the value combo
        selectvars(["chest pain"])
        self.assertTrue(widget.value_combo.isVisibleTo(widget) and
                        widget.value_combo.isEnabledTo(widget))
        self.assertEqual(varbg.checkedId(), Method.Default)
        self.assertEqual(widget.value_combo.currentIndex(), 1)