def check_button_disabled(self, style): button_text_edit = ButtonTextEdit(button_enabled=False, ) view = View( Item( "play_button", editor=ButtonEditor(), enabled_when="button_enabled", style=style, ), ) tester = UITester() with tester.create_ui(button_text_edit, dict(view=view)) as ui: button = tester.find_by_name(ui, "play_button") self.assertFalse(button.inspect(IsEnabled())) with self.assertTraitDoesNotChange(button_text_edit, "play_button"): button.perform(MouseClick()) button_text_edit.button_enabled = True self.assertTrue(button.inspect(IsEnabled())) with self.assertTraitChanges(button_text_edit, "play_button", count=1): button.perform(MouseClick())
def test_propagate_errors_switch_selection(self): obj = ObjectWithValidatedList() ui_tester = UITester() with ui_tester.create_ui(obj, {'view': selection_view}) as ui: something_ui = ui_tester.find_by_name(ui, "inst") something_ui.locate(Index(0)).perform(MouseClick()) some_string_field = something_ui.locate( TargetByName('some_string')) some_string_field.perform(KeySequence("bcde")) some_string_field.perform(KeyClick("Enter")) ok_button = ui_tester.find_by_id(ui, "OK") instance_editor_ui = something_ui._target._ui instance_editor_ui_parent = something_ui._target._ui.parent self.assertNotEqual(instance_editor_ui, ui) self.assertEqual(instance_editor_ui_parent, ui) self.assertEqual(instance_editor_ui.errors, ui.errors) self.assertFalse(ok_button.inspect(IsEnabled())) # change to a different selected that is not in an error state something_ui.locate(Index(1)).perform(MouseClick()) self.assertTrue(ok_button.inspect(IsEnabled()))
def test_propagate_errors(self): obj = ObjectWithValidatedInstance() ui_tester = UITester() with ui_tester.create_ui(obj) as ui: something_ui = ui_tester.find_by_name(ui, "something") some_string_field = something_ui.locate( TargetByName('some_string') ) some_string_field.perform(KeySequence("abcd")) some_string_field.perform(KeyClick("Enter")) ok_button = ui_tester.find_by_id(ui, "OK") instance_editor_ui = something_ui._target._ui instance_editor_ui_parent = something_ui._target._ui.parent self.assertNotEqual( instance_editor_ui, ui ) self.assertEqual( instance_editor_ui_parent, ui ) self.assertEqual( instance_editor_ui.errors, ui.errors ) self.assertFalse(ok_button.inspect(IsEnabled()))
def test_simple_editor_disabled(self): enum_edit = EnumModel(value="two") view = View( UItem( "value", style="simple", enabled_when="value == 'one'", editor=EnumEditor(evaluate=True, values=["one", "two"]), ), ) tester = UITester() with tester.create_ui(enum_edit, dict(view=view)) as ui: combobox = tester.find_by_name(ui, "value") with self.assertRaises(Disabled): combobox.perform(KeyClick("Enter")) with self.assertRaises(Disabled): combobox.perform(KeySequence("two")) self.assertFalse(combobox.inspect(IsEnabled()))
def test_destroy_after_ok_wx(self): # Behavior: after pressing 'OK' in a dialog, the method UI.finish is # called and the view control and its children are destroyed foo = FooDialog() tester = UITester() with tester.create_ui(foo) as ui: # keep reference to the control to check that it was destroyed control = ui.control # decorate control's `Destroy` function to check that it is called control.Destroy = count_calls(control.Destroy) # press the OK button and close the dialog ok_button = tester.find_by_id(ui, "OK") self.assertEqual(ok_button.inspect(DisplayedText()), "OK") self.assertTrue(ok_button.inspect(IsEnabled())) ok_button.perform(MouseClick()) self.assertIsNone(ui.control) self.assertEqual(control.Destroy._n_calls, 1)
def test_is_enabled(self): self.widget.Enable(True) self.assertTrue(self.good_wrapper.inspect(IsEnabled()))
def test_is_disabled(self): self.widget.setEnabled(False) self.assertFalse(self.good_wrapper.inspect(IsEnabled()))