Exemple #1
0
    def test_custom_editor_with_selection(self):
        obj = ObjectWithList()
        tester = UITester()
        with tester.create_ui(obj, {'view': selection_view}) as ui:
            # test that the current object is None
            self.assertIsNone(obj.inst)

            # test that the displayed text is correct
            instance = tester.find_by_name(ui, "inst")
            text = instance.inspect(SelectedText())
            self.assertEqual(text, obj.inst_list[0].name)

            # test that changing selection works
            instance = tester.find_by_name(ui, "inst")
            instance.locate(Index(1)).perform(MouseClick())
            self.assertIs(obj.inst, obj.inst_list[1])

            # test that the displayed text is correct
            text = instance.inspect(SelectedText())
            self.assertEqual(text, obj.inst_list[1].name)

            # test editing the view works
            value_txt = instance.find_by_name("value")
            value_txt.perform(KeySequence("abc"))
            self.assertEqual(obj.inst.value, "twoabc")
Exemple #2
0
    def test_enum_editor_demo(self):
        demo = runpy.run_path(DEMO_PATH)["demo"]

        tester = UITester()
        with tester.create_ui(demo) as ui:
            simple_enum = tester.find_by_id(ui, "simple")
            simple_text_enum = tester.find_by_id(ui, "simple_text")
            radio_enum = tester.find_by_id(ui, "radio")
            list_enum = tester.find_by_id(ui, "list")
            text = tester.find_by_id(ui, "text")
            readonly = tester.find_by_id(ui, "readonly")

            self.assertEqual(demo.name_list, 'A-495')
            simple_enum.locate(Index(1)).perform(MouseClick())
            self.assertEqual(demo.name_list, 'A-498')

            for _ in range(5):
                simple_text_enum.perform(KeyClick("Backspace"))
            simple_text_enum.perform(KeySequence("R-1226"))
            simple_text_enum.perform(KeyClick("Enter"))
            self.assertEqual(demo.name_list, 'R-1226')

            radio_enum.locate(Index(5)).perform(MouseClick())
            self.assertEqual(demo.name_list, 'Foo')

            list_enum.locate(Index(3)).perform(MouseClick())
            self.assertEqual(demo.name_list, 'TS-17')

            for _ in range(5):
                text.perform(KeyClick("Backspace"))
            text.perform(KeySequence("A-498"))
            text.perform(KeyClick("Enter"))
            self.assertEqual(demo.name_list, 'A-498')

            demo.name_list = 'Foo'

            displayed_simple = simple_enum.inspect(DisplayedText())
            disp_simple_text = simple_text_enum.inspect(DisplayedText())
            selected_radio = radio_enum.inspect(SelectedText())
            selected_list = list_enum.inspect(SelectedText())
            displayed_text = text.inspect(DisplayedText())
            displayed_readonly = readonly.inspect(DisplayedText())

            displayed_selected = [
                displayed_simple,
                disp_simple_text,
                selected_radio,
                selected_list,
                displayed_text,
                displayed_readonly,
            ]
            for text in displayed_selected:
                self.assertEqual(text, 'Foo')
    def check_enum_text_update(self, view):
        enum_edit = EnumModel()

        tester = UITester()
        with tester.create_ui(enum_edit, dict(view=view)) as ui:

            list_editor = tester.find_by_name(ui, "value")
            displayed = list_editor.inspect(SelectedText())

            self.assertEqual(displayed, "one")

            list_editor.locate(Index(1)).perform(MouseClick())
            displayed = list_editor.inspect(SelectedText())
            self.assertEqual(displayed, "two")
 def test_radio_enum_none_selected(self):
     enum_edit = EnumModelWithNone()
     tester = UITester()
     with tester.create_ui(enum_edit, dict(view=get_radio_view())) as ui:
         self.assertEqual(enum_edit.value, None)
         radio_editor = tester.find_by_name(ui, "value")
         displayed = radio_editor.inspect(SelectedText())
         self.assertEqual(displayed, None)
    def test_radio_enum_editor_update(self):
        enum_edit = EnumModel()
        tester = UITester()

        with tester.create_ui(enum_edit, dict(view=get_view("custom"))) as ui:
            # sanity check
            self.assertEqual(enum_edit.value, "one")
            radio_editor = tester.find_by_name(ui, "value")
            self.assertEqual(
                radio_editor.inspect(SelectedText()),
                "One",
            )

            enum_edit.value = "two"

            self.assertEqual(
                radio_editor.inspect(SelectedText()),
                "Two",
            )
Exemple #6
0
    def test_custom_editor_with_selection_initialized(self):
        obj = ObjectWithList()
        obj.inst = obj.inst_list[1]
        tester = UITester()
        with tester.create_ui(obj, {'view': selection_view}) as ui:
            # test that the current object is the correct one
            self.assertIs(obj.inst, obj.inst_list[1])

            # test that the displayed text is correct
            instance = tester.find_by_name(ui, "inst")
            text = instance.inspect(SelectedText())
            self.assertEqual(text, obj.inst.name)
    def test_none_selected(self):
        obj = ObjectWithList()
        tester = UITester()
        with tester.create_ui(obj, {'view': none_view}) as ui:
            # test that the current object is None
            self.assertIsNone(obj.inst)

            # test that the displayed text is empty to start
            instance = tester.find_by_name(ui, "inst")
            text = instance.inspect(SelectedText())
            self.assertEqual(text, '')

            # test that changing selection works and displayed text is correct
            instance.locate(Index(1)).perform(MouseClick())
            self.assertIs(obj.inst, obj.inst_list[1])
            text = instance.inspect(SelectedText())
            self.assertEqual(text, obj.inst_list[1].name)

            # test resetting selection to None
            reset_to_none_button = tester.find_by_name(ui, "reset_to_none")
            reset_to_none_button.perform(MouseClick())
            self.assertIsNone(obj.inst)
            text = instance.inspect(SelectedText())
            self.assertEqual(text, '')

            # change selection again
            instance.locate(Index(1)).perform(MouseClick())
            self.assertIs(obj.inst, obj.inst_list[1])
            text = instance.inspect(SelectedText())
            self.assertEqual(text, obj.inst_list[1].name)

            # test modifying list of selectable options returns current object
            # to None
            change_options_button = tester.find_by_name(ui, "change_options")
            change_options_button.perform(MouseClick())
            self.assertIsNone(obj.inst)
            text = instance.inspect(SelectedText())
            self.assertEqual(text, '')
    def test_custom_editor_with_selection_change_option_name(self):
        obj = ObjectWithList()
        tester = UITester()
        with tester.create_ui(obj, {'view': selection_view}) as ui:
            # test that the current object is None
            self.assertIsNone(obj.inst)

            # actually select the first item
            instance = tester.find_by_name(ui, "inst")
            instance.locate(Index(0)).perform(MouseClick())
            self.assertIs(obj.inst, obj.inst_list[0])

            # test that the displayed text is correct after change
            name_txt = instance.find_by_name("name")
            for _ in range(3):
                name_txt.perform(KeyClick("Backspace"))
            name_txt.perform(KeySequence("Something New"))
            text = instance.inspect(SelectedText())
            self.assertEqual(text, "Something New")
            self.assertEqual("Something New", obj.inst_list[0].name)
 def test_list_enum_none_selected(self):
     enum_edit = EnumModelWithNone()
     view = View(
         UItem(
             "value",
             editor=EnumEditor(
                 # Note that for the list style editor, in order to select
                 # None, it must be one of the displayed options
                 values=[None, "one", "two", "three", "four"],
                 mode="list",
             ),
             style="custom",
         ),
         resizable=True,
     )
     tester = UITester()
     with tester.create_ui(enum_edit, dict(view=view)) as ui:
         self.assertEqual(enum_edit.value, None)
         list_editor = tester.find_by_name(ui, "value")
         # As a result the displayed text is actually the string 'None'
         displayed = list_editor.inspect(SelectedText())
         self.assertEqual(displayed, 'None')