def _get_designated_report_view(self): # OWReport is a Report from Orange.widgets.report.owreport import OWReport if self.__report_view is not None: return self.__report_view() else: return OWReport.get_instance()
def _get_designated_report_view(self): # OWReport is a Report from Orange.widgets.report.owreport import OWReport if self.__report_view is not None: return self.__report_view() else: return OWReport.get_instance()
def test_report(self): count = 5 for _ in range(count): rep = OWReport.get_instance() file = self.create_widget(OWFile) file.create_report_html() rep.make_report(file) self.assertEqual(rep.table_model.rowCount(), count)
def test_report(self): count = 5 for _ in range(count): rep = OWReport.get_instance() file = self.create_widget(OWFile) file.create_report_html() rep.make_report(file) self.assertEqual(rep.table_model.rowCount(), count)
def test_report_widgets_visualize(self): _warnings = warnings.catch_warnings() _warnings.__enter__() warnings.simplefilter("ignore", OrangeDeprecationWarning) rep = OWReport.get_instance() data = Table("zoo") widgets = self.visu_widgets self._create_report(widgets, rep, data) _warnings.__exit__()
def test_report_widgets_all(self): _warnings = warnings.catch_warnings() _warnings.__enter__() warnings.simplefilter("ignore", OrangeDeprecationWarning) rep = OWReport.get_instance() widgets = self.model_widgets + self.data_widgets + self.eval_widgets + \ self.unsu_widgets + self.dist_widgets + self.visu_widgets + \ self.spec_widgets self._create_report(widgets, rep, None) _warnings.__exit__()
def setUpClass(cls): """Prepare environment for test execution Construct a dummy signal manager and monkey patch OWReport.get_instance to return a manually created instance. """ super().setUpClass() cls.widgets = [] cls.signal_manager = DummySignalManager() report = OWReport() cls.widgets.append(report) OWReport.get_instance = lambda: report if not (os.environ.get("TRAVIS") or os.environ.get("APPVEYOR")): report.show = Mock() Variable._clear_all_caches()
def setUpClass(cls): """Prepare environment for test execution Construct a dummy signal manager and monkey patch OWReport.get_instance to return a manually created instance. """ super().setUpClass() cls.widgets = [] cls.signal_manager = DummySignalManager() report = OWReport() cls.widgets.append(report) OWReport.get_instance = lambda: report if not (os.environ.get("TRAVIS") or os.environ.get("APPVEYOR")): report.show = Mock() Variable._clear_all_caches()
def show_report(self): """ Raise the report window. """ from Orange.widgets.report.owreport import OWReport report = OWReport.get_instance() self.create_report_html() report.make_report(self) report.show() report.raise_()
def test_report_widgets_model(self): rep = OWReport.get_instance() data = Table("titanic") widgets = self.model_widgets w = self.create_widget(OWTreeGraph) clf = TreeLearner(max_depth=3)(data) clf.instances = data w.ctree(clf) w.create_report_html() rep.make_report(w) self._create_report(widgets, rep, data)
def test_report_widgets_model(self): rep = OWReport.get_instance() data = Table("titanic") widgets = self.model_widgets w = self.create_widget(OWTreeGraph) clf = TreeLearner(max_depth=3)(data) clf.instances = data w.ctree(clf) w.create_report_html() rep.make_report(w) self._create_report(widgets, rep, data)
def test_save_report_permission(self): """ Permission Error may occur when trying to save report. GH-2147 """ rep = OWReport.get_instance() patch_target_1 = "Orange.widgets.report.owreport.open" patch_target_2 = "AnyQt.QtWidgets.QFileDialog.getSaveFileName" patch_target_3 = "AnyQt.QtWidgets.QMessageBox.exec_" filenames = ["f.report", "f.html"] for filename in filenames: with unittest.mock.patch(patch_target_1, create=True, side_effect=PermissionError),\ unittest.mock.patch(patch_target_2, return_value=(filename, 'HTML (*.html)')),\ unittest.mock.patch(patch_target_3, return_value=True): rep.save_report()
def test_save_report_permission(self): """ Permission Error may occur when trying to save report. GH-2147 """ rep = OWReport.get_instance() patch_target_1 = "Orange.widgets.report.owreport.open" patch_target_2 = "AnyQt.QtWidgets.QFileDialog.getSaveFileName" patch_target_3 = "AnyQt.QtWidgets.QMessageBox.exec_" filenames = ["f.report", "f.html"] for filename in filenames: with unittest.mock.patch(patch_target_1, create=True, side_effect=PermissionError),\ unittest.mock.patch(patch_target_2, return_value=(filename, 'HTML (*.html)')),\ unittest.mock.patch(patch_target_3, return_value=True): rep.save_report()
def test_report_widgets_evaluate(self): rep = OWReport.get_instance() data = Table("zoo") widgets = self.eval_widgets cv = CrossValidation(k=3, store_data=True) results = cv(data, [LogisticRegressionLearner()]) results.learner_names = ["LR l2"] w = self.create_widget(OWTestAndScore) w.insert_learner(0, LogisticRegressionLearner()) w.set_train_data(data) w.set_test_data(data) w.create_report_html() rep.make_report(w) self._create_report(widgets, rep, results)
def test_disable_saving_empty(self): """Test if save and print buttons are disabled on empty report""" rep = OWReport.get_instance() self.assertFalse(rep.save_button.isEnabled()) self.assertFalse(rep.print_button.isEnabled()) table = OWDataTable() table.set_dataset(Table("iris")) table.create_report_html() rep.make_report(table) self.assertTrue(rep.save_button.isEnabled()) self.assertTrue(rep.print_button.isEnabled()) rep.clear() self.assertFalse(rep.save_button.isEnabled()) self.assertFalse(rep.print_button.isEnabled())
def test_disable_saving_empty(self): """Test if save and print buttons are disabled on empty report""" rep = OWReport.get_instance() self.assertFalse(rep.save_button.isEnabled()) self.assertFalse(rep.print_button.isEnabled()) table = OWDataTable() table.set_dataset(Table("iris")) table.create_report_html() rep.make_report(table) self.assertTrue(rep.save_button.isEnabled()) self.assertTrue(rep.print_button.isEnabled()) rep.clear() self.assertFalse(rep.save_button.isEnabled()) self.assertFalse(rep.print_button.isEnabled())
def test_save_report(self): rep = OWReport.get_instance() file = self.create_widget(OWFile) file.create_report_html() rep.make_report(file) temp_dir = tempfile.mkdtemp() temp_name = os.path.join(temp_dir, "f.report") try: with mock.patch("AnyQt.QtWidgets.QFileDialog.getSaveFileName", return_value=(temp_name, 'Report (*.report)')), \ mock.patch("AnyQt.QtWidgets.QMessageBox.exec_", return_value=True): rep.save_report() finally: os.remove(temp_name) os.rmdir(temp_dir)
def test_save_report(self): rep = OWReport.get_instance() file = self.create_widget(OWFile) file.create_report_html() rep.make_report(file) temp_dir = tempfile.mkdtemp() temp_name = os.path.join(temp_dir, "f.report") try: with mock.patch("AnyQt.QtWidgets.QFileDialog.getSaveFileName", return_value=(temp_name, 'Report (*.report)')), \ mock.patch("AnyQt.QtWidgets.QMessageBox.exec_", return_value=True): rep.save_report() finally: os.remove(temp_name) os.rmdir(temp_dir)
def test_save_report_permission(self): """ Permission Error may occur when trying to save report. GH-2147 """ rep = OWReport.get_instance() filenames = ["f.report", "f.html"] for filename in filenames: with patch("Orange.widgets.report.owreport.open", create=True, side_effect=PermissionError),\ patch("AnyQt.QtWidgets.QFileDialog.getSaveFileName", return_value=(filename, 'HTML (*.html)')),\ patch("AnyQt.QtWidgets.QMessageBox.exec_", return_value=True), \ patch("Orange.widgets.report.owreport.log.error") as log: rep.save_report() log.assert_called()
def test_save_report_permission(self): """ Permission Error may occur when trying to save report. GH-2147 """ rep = OWReport.get_instance() filenames = ["f.report", "f.html"] for filename in filenames: with patch("Orange.widgets.report.owreport.open", create=True, side_effect=PermissionError),\ patch("AnyQt.QtWidgets.QFileDialog.getSaveFileName", return_value=(filename, 'HTML (*.html)')),\ patch("AnyQt.QtWidgets.QMessageBox.exec_", return_value=True), \ patch("Orange.widgets.report.owreport.log.error") as log: rep.save_report() log.assert_called()
def test_report_table(self): rep = OWReport.get_instance() model = PyTableModel([["x", 1, 2], ["y", 2, 2]]) model.setHorizontalHeaderLabels(["a", "b", "c"]) model.setData(model.index(0, 0), Qt.AlignHCenter | Qt.AlignTop, Qt.TextAlignmentRole) model.setData(model.index(1, 0), QFont("", -1, QFont.Bold), Qt.FontRole) model.setData(model.index(1, 2), QBrush(Qt.red), Qt.BackgroundRole) view = gui.TableView() view.show() view.setModel(model) rep.report_table("Name", view) self.maxDiff = None self.assertEqual( rep.report_html, "<h2>Name</h2><table>\n" "<tr>" '<th style="color:black;border:0;background:transparent;' 'text-align:left;vertical-align:middle;">a</th>' '<th style="color:black;border:0;background:transparent;' 'text-align:left;vertical-align:middle;">b</th>' '<th style="color:black;border:0;background:transparent;' 'text-align:left;vertical-align:middle;">c</th>' "</tr>" "<tr>" '<td style="color:black;border:0;background:transparent;' 'text-align:center;vertical-align:top;">x</td>' '<td style="color:black;border:0;background:transparent;' 'text-align:right;vertical-align:middle;">1</td>' '<td style="color:black;border:0;background:transparent;' 'text-align:right;vertical-align:middle;">2</td>' "</tr>" "<tr>" '<td style="color:black;border:0;background:transparent;' 'font-weight: bold;text-align:left;vertical-align:middle;">y</td>' '<td style="color:black;border:0;background:transparent;' 'text-align:right;vertical-align:middle;">2</td>' '<td style="color:black;border:0;background:#ff0000;' 'text-align:right;vertical-align:middle;">2</td>' "</tr></table>", )
def test_report_widgets_evaluate(self): rep = OWReport.get_instance() data = Table("zoo") widgets = self.eval_widgets results = CrossValidation(data, [LogisticRegressionLearner()], store_data=True) results.learner_names = ["LR l2"] w = self.create_widget(OWTestLearners) set_learner = getattr(w, w.Inputs.learner.handler) set_train = getattr(w, w.Inputs.train_data.handler) set_test = getattr(w, w.Inputs.test_data.handler) set_learner(LogisticRegressionLearner(), 0) set_train(data) set_test(data) w.create_report_html() rep.make_report(w) self._create_report(widgets, rep, results)
def test_report_table(self): rep = OWReport.get_instance() model = PyTableModel([['x', 1, 2], ['y', 2, 2]]) model.setHorizontalHeaderLabels(['a', 'b', 'c']) model.setData(model.index(0, 0), Qt.AlignHCenter | Qt.AlignTop, Qt.TextAlignmentRole) model.setData(model.index(1, 0), QFont('', -1, QFont.Bold), Qt.FontRole) model.setData(model.index(1, 2), QBrush(Qt.red), Qt.BackgroundRole) view = gui.TableView() view.show() view.setModel(model) rep.report_table('Name', view) self.maxDiff = None self.assertEqual( rep.report_html, '<h2>Name</h2><table>\n' '<tr>' '<th style="color:black;border:0;background:transparent;' 'text-align:left;vertical-align:middle;">a</th>' '<th style="color:black;border:0;background:transparent;' 'text-align:left;vertical-align:middle;">b</th>' '<th style="color:black;border:0;background:transparent;' 'text-align:left;vertical-align:middle;">c</th>' '</tr>' '<tr>' '<td style="color:black;border:0;background:transparent;' 'text-align:center;vertical-align:top;">x</td>' '<td style="color:black;border:0;background:transparent;' 'text-align:right;vertical-align:middle;">1</td>' '<td style="color:black;border:0;background:transparent;' 'text-align:right;vertical-align:middle;">2</td>' '</tr>' '<tr>' '<td style="color:black;border:0;background:transparent;' 'font-weight: bold;text-align:left;vertical-align:middle;">y</td>' '<td style="color:black;border:0;background:transparent;' 'text-align:right;vertical-align:middle;">2</td>' '<td style="color:black;border:0;background:#ff0000;' 'text-align:right;vertical-align:middle;">2</td>' '</tr></table>')
def test_report_widgets_evaluate(self): rep = OWReport.get_instance() data = Table("zoo") widgets = self.eval_widgets results = CrossValidation(data, [LogisticRegressionLearner()], store_data=True) results.learner_names = ["LR l2"] w = self.create_widget(OWTestLearners) set_learner = getattr(w, w.Inputs.learner.handler) set_train = getattr(w, w.Inputs.train_data.handler) set_test = getattr(w, w.Inputs.test_data.handler) set_learner(LogisticRegressionLearner(), 0) set_train(data) set_test(data) w.create_report_html() rep.make_report(w) self._create_report(widgets, rep, results)
def test_report_widgets_all(self): rep = OWReport.get_instance() widgets = self.model_widgets + self.data_widgets + self.eval_widgets + \ self.unsu_widgets + self.dist_widgets + self.visu_widgets + \ self.spec_widgets self._create_report(widgets, rep, None)
def test_report_widgets_data(self): rep = OWReport.get_instance() data = Table("zoo") widgets = self.data_widgets self._create_report(widgets, rep, data)
def test_report_widgets_unsupervised(self): rep = OWReport.get_instance() data = Table("zoo") widgets = self.unsu_widgets self._create_report(widgets, rep, data)
def test_report_widgets_unsupervised_dist(self): rep = OWReport.get_instance() data = Table("zoo") dist = Euclidean(data) widgets = self.dist_widgets self._create_report(widgets, rep, dist)
def test_report_widgets_all(self): rep = OWReport.get_instance() widgets = self.model_widgets + self.data_widgets + self.eval_widgets + \ self.unsu_widgets + self.dist_widgets + self.visu_widgets + \ self.spec_widgets self._create_report(widgets, rep, None)
def test_report_widgets_visualize(self): rep = OWReport.get_instance() data = Table("zoo") widgets = self.visu_widgets self._create_report(widgets, rep, data)
def test_report_widgets_unsupervised_dist(self): rep = OWReport.get_instance() data = Table("zoo") dist = Euclidean(data) widgets = self.dist_widgets self._create_report(widgets, rep, dist)
def test_report_widgets_unsupervised(self): rep = OWReport.get_instance() data = Table("zoo") widgets = self.unsu_widgets self._create_report(widgets, rep, data)