From 53bedefa505305eba87c2accf5416796f9b3a1ba Mon Sep 17 00:00:00 2001 From: Aleksandra Date: Fri, 6 Mar 2020 13:57:46 +0100 Subject: [PATCH] Data info displayed in the status bar --- Orange/widgets/data/owimpute.py | 12 +++++++++ Orange/widgets/data/tests/test_owimpute.py | 30 +++++++++++++++++++++- 2 files changed, 41 insertions(+), 1 deletion(-) diff --git a/Orange/widgets/data/owimpute.py b/Orange/widgets/data/owimpute.py index bc054a6ace2..ec889da1b1d 100644 --- a/Orange/widgets/data/owimpute.py +++ b/Orange/widgets/data/owimpute.py @@ -24,6 +24,7 @@ from Orange.widgets.utils import concurrent as qconcurrent from Orange.widgets.utils.sql import check_sql_input from Orange.widgets.utils.widgetpreview import WidgetPreview +from Orange.widgets.utils.state_summary import format_summary_details from Orange.widgets.widget import OWWidget, Msg, Input, Output from Orange.classification import SimpleTreeLearner @@ -249,6 +250,9 @@ def __init__(self): box.button.setFixedWidth(180) box.layout().insertStretch(0) + self.info.set_input_summary(self.info.NoInput) + self.info.set_output_summary(self.info.NoOutput) + def create_imputer(self, method, *args): # type: (Method, ...) -> impute.BaseImputeMethod if method == Method.Model: @@ -300,6 +304,10 @@ def set_data(self, data): # restore per variable imputation state self._restore_state(self._variable_imputation_state) + summary = len(data) if data else self.info.NoInput + details = format_summary_details(data) if data else "" + self.info.set_input_summary(summary, details) + self.update_varview() self.unconditional_commit() @@ -346,6 +354,7 @@ def commit(self): if not self.data or not self.varmodel.rowCount(): self.Outputs.data.send(self.data) + self.info.set_output_summary(self.info.NoOutput) self.modified = False return @@ -452,6 +461,9 @@ def create_data(attributes, class_vars): self.Outputs.data.send(data) self.modified = False + summary = len(data) if data else self.info.NoOutput + details = format_summary_details(data) if data else "" + self.info.set_output_summary(summary, details) @Slot(int, int) def __progress_changed(self, n, d): diff --git a/Orange/widgets/data/tests/test_owimpute.py b/Orange/widgets/data/tests/test_owimpute.py index 934c0dd1f18..6398a067033 100644 --- a/Orange/widgets/data/tests/test_owimpute.py +++ b/Orange/widgets/data/tests/test_owimpute.py @@ -1,5 +1,6 @@ # Test methods with long descriptive names can omit docstrings -# pylint: disable=missing-docstring,pointless-statement,blacklisted-name +# pylint: disable=missing-docstring,pointless-statement,blacklisted-name,unsubscriptable-object +from unittest.mock import Mock import numpy as np from AnyQt.QtCore import Qt, QItemSelection @@ -11,6 +12,7 @@ from Orange.widgets.tests.base import WidgetTest from Orange.widgets.tests.utils import simulate from Orange.widgets.utils.itemmodels import select_row +from Orange.widgets.utils.state_summary import format_summary_details class Foo(Learner): @@ -181,3 +183,29 @@ def effective_method(var): widget.value_combo.isEnabledTo(widget)) self.assertEqual(varbg.checkedId(), Method.Default) self.assertEqual(widget.value_combo.currentIndex(), 1) + + def test_summary(self): + """Check if the status bar is updated when data is received""" + data = Table("heart_disease") + 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.data) + output_sum.assert_called_with(len(output), + format_summary_details(output)) + + varbg = self.widget.variable_button_group + varbg.button(Method.AsValue).click() + output = self.get_output(self.widget.Outputs.data) + output_sum.assert_called_with(len(output), + format_summary_details(output)) + + 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, "")