def test_multiple_runs(self): w = self.widgetClass previewer = WidgetPreview(w) previewer.run(42, no_exit=True) w.int1(43) previewer.send_signals([(44, 1), (45, 2)]) previewer.run(46, no_exit=True) w.int1.assert_has_calls( [call(42), call(43), call(44, 1), call(45, 2), call(46)])
def test_multiple_runs(self): w = self.widgetClass previewer = WidgetPreview(w) previewer.run(42, no_exit=True) w.int1(43) previewer.send_signals([(44, 1), (45, 2)]) previewer.run(46, no_exit=True) w.int1.assert_has_calls( [call(42), call(43), call(44, 1), call(45, 2), call(46)])
def test_widget_is_shown_and_ran(self): w = self.widgetClass app.exec_.reset_mock() previewer = WidgetPreview(w) previewer.run() w.show.assert_called() w.show.reset_mock() app.exec_.assert_called() app.exec_.reset_mock() w.saveSettings.assert_called() w.saveSettings.reset_mock() sys.exit.assert_called() sys.exit.reset_mock() self.assertIsNone(previewer.widget) previewer.run(no_exit=True) w.show.assert_called() w.show.reset_mock() app.exec_.assert_called() app.exec_.reset_mock() w.saveSettings.assert_not_called() sys.exit.assert_not_called() self.assertIsNotNone(previewer.widget) widget = previewer.widget previewer.run(no_exec=True, no_exit=True) w.show.assert_not_called() app.exec_.assert_not_called() w.saveSettings.assert_not_called() sys.exit.assert_not_called() self.assertIs(widget, previewer.widget) previewer.run(no_exec=True) w.show.assert_not_called() app.exec_.assert_not_called() w.saveSettings.assert_called() sys.exit.assert_called() self.assertIsNone(previewer.widget)
def test_widget_is_shown_and_ran(self): w = self.widgetClass app.exec_.reset_mock() previewer = WidgetPreview(w) previewer.run() w.show.assert_called() w.show.reset_mock() app.exec_.assert_called() app.exec_.reset_mock() w.saveSettings.assert_called() w.saveSettings.reset_mock() sys.exit.assert_called() sys.exit.reset_mock() self.assertIsNone(previewer.widget) previewer.run(no_exit=True) w.show.assert_called() w.show.reset_mock() app.exec_.assert_called() app.exec_.reset_mock() w.saveSettings.assert_not_called() sys.exit.assert_not_called() self.assertIsNotNone(previewer.widget) widget = previewer.widget previewer.run(no_exec=True, no_exit=True) w.show.assert_not_called() app.exec_.assert_not_called() w.saveSettings.assert_not_called() sys.exit.assert_not_called() self.assertIs(widget, previewer.widget) previewer.run(no_exec=True) w.show.assert_not_called() app.exec_.assert_not_called() w.saveSettings.assert_called() sys.exit.assert_called() self.assertIsNone(previewer.widget)
headerState = headerState[0] if isinstance(headerState, bytes): hview = QHeaderView(Qt.Horizontal) hview.restoreState(headerState) column, order = hview.sortIndicatorSection() - 1, hview.sortIndicatorOrder() settings["sorting"] = (column, order) @classmethod def migrate_context(cls, context, version): if version is None or version < 2: # Old selection was saved as sorted indices. New selection is original indices. # Since we can't devise the latter without first computing the ranks, # just reset the selection to avoid confusion. context.values['selected_rows'] = [] if __name__ == "__main__": # pragma: no cover from Orange.classification import RandomForestLearner previewer = WidgetPreview(OWRank) previewer.run(Table("heart_disease.tab"), no_exit=True) previewer.send_signals( set_learner=(RandomForestLearner(), (3, 'Learner', None))) previewer.run() """ WidgetPreview(OWRank).run( set_learner=(RandomForestLearner(), (3, 'Learner', None)), set_data=Table("heart_disease.tab")) """
if self.use_min_count: filters.append( FilterProxyModel.Filter(Header.count, Qt.DisplayRole, lambda value: value >= self.min_count)) return filters def filter_view(self): filter_proxy: FilterProxyModel = self.filter_proxy_model model: QStandardItemModel = filter_proxy.sourceModel() if isinstance(model, QStandardItemModel): # apply filtering rules filter_proxy.set_filters(self.create_filters()) if model.rowCount() and not filter_proxy.rowCount(): self.Warning.all_sets_filtered() else: self.Warning.clear() def sizeHint(self): return QSize(800, 600) if __name__ == "__main__": from Orange.widgets.utils.widgetpreview import WidgetPreview widget = WidgetPreview(OWGeneSets) widget.run()
if isinstance(headerState, bytes): hview = QHeaderView(Qt.Horizontal) hview.restoreState(headerState) column, order = hview.sortIndicatorSection() - 1, hview.sortIndicatorOrder() settings["sorting"] = (column, order) @classmethod def migrate_context(cls, context, version): if version is None or version < 2: # Old selection was saved as sorted indices. New selection is original indices. # Since we can't devise the latter without first computing the ranks, # just reset the selection to avoid confusion. context.values['selected_rows'] = [] if __name__ == "__main__": # pragma: no cover from Orange.classification import RandomForestLearner previewer = WidgetPreview(OWRank) previewer.run(Table("heart_disease.tab"), no_exit=True) previewer.send_signals( set_learner=(RandomForestLearner(), (3, 'Learner', None))) previewer.run() # pylint: disable=pointless-string-statement """ WidgetPreview(OWRank).run( set_learner=(RandomForestLearner(), (3, 'Learner', None)), set_data=Table("heart_disease.tab")) """
self.model.index(0, 0), self.model.index(n_selected - 1, column_count - 1)) else: selection = QItemSelection() if self.selected_attrs is not None: attr_indices = [ self.covariates_from_worker_result.index(var.name) for var in self.selected_attrs ] for row in self.model.mapFromSourceRows(attr_indices): selection.append( QItemSelectionRange( self.model.index(row, 0), self.model.index(row, column_count - 1))) selection_model.select(selection, QItemSelectionModel.ClearAndSelect) def on_select(self): selected_rows = self.table_view.selectionModel().selectedRows(0) row_indices = [i.row() for i in selected_rows] attr_indices = self.model.mapToSourceRows(row_indices) self.selected_attrs = [ self.model._headers[Qt.Vertical][row] for row in attr_indices ] self.commit() if __name__ == '__main__': previewer = WidgetPreview(OWRankSurvivalFeatures) previewer.run(Table('iris.tab'))