def setUp(self): self.data = Table("iris") self.model = model = VariableItemModel() model.set_data(self.data) widget = OWCreateInstance() self.delegate = VariableDelegate(widget) self.parent = QWidget() self.opt = QStyleOptionViewItem()
class TestVariableDelegate(GuiTest): def setUp(self): self.data = Table("iris") self.model = model = VariableItemModel() model.set_data(self.data) widget = OWCreateInstance() self.delegate = VariableDelegate(widget) self.parent = QWidget() self.opt = QStyleOptionViewItem() def test_create_editor(self): index = self.model.index(0, 1) editor = self.delegate.createEditor(self.parent, self.opt, index) self.assertIsInstance(editor, ContinuousVariableEditor) index = self.model.index(4, 1) editor = self.delegate.createEditor(self.parent, self.opt, index) self.assertIsInstance(editor, DiscreteVariableEditor) def test_set_editor_data(self): index = self.model.index(0, 1) editor = self.delegate.createEditor(self.parent, self.opt, index) self.delegate.setEditorData(editor, index) self.assertEqual(editor.value, np.median(self.data.X[:, 0])) def test_set_model_data(self): index = self.model.index(0, 1) editor = self.delegate.createEditor(self.parent, self.opt, index) editor.value = 7.5 self.delegate.setModelData(editor, self.model, index) self.assertEqual(self.model.data(index, ValueRole), 7.5) def test_editor_geometry(self): index = self.model.index(0, 1) editor = self.delegate.createEditor(self.parent, self.opt, index) self.delegate.updateEditorGeometry(editor, self.opt, index) self.assertGreaterEqual(editor.geometry().width(), self.opt.rect.width()) size = self.delegate.sizeHint(self.opt, index) self.assertEqual(size.width(), editor.geometry().width()) self.assertEqual(size.height(), 40)