Beispiel #1
0
    def test_destroy_after_ok_qt(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 deleted
            control = ui.control

            # decorate control's `deleteLater` function to check that it is
            # called
            control.deleteLater = count_calls(control.deleteLater)

            # 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.deleteLater._n_calls, 1)
Beispiel #2
0
    def test_instance_editor_demo(self):
        demo = runpy.run_path(DEMO_PATH)["demo"]

        tester = UITester()
        with tester.create_ui(demo) as ui:
            simple = tester.find_by_id(ui, "simple")
            custom = tester.find_by_id(ui, "custom")
            occupation = custom.find_by_name("occupation")
            occupation.perform(KeySequence("Job"))
            occupation.perform(KeyClick("Enter"))
            self.assertEqual(demo.sample_instance.occupation, "Job")

            simple.perform(MouseClick())
            name = simple.find_by_name("name")
            name.perform(KeySequence("ABC"))
            name.perform(KeyClick("Enter"))
            self.assertEqual(demo.sample_instance.name, "ABC")

            demo.sample_instance.name = "XYZ"
            simple_displayed = name.inspect(DisplayedText())
            custom_name = custom.find_by_name("name")
            custom_displayed = custom_name.inspect(DisplayedText())
            self.assertEqual(simple_displayed, "XYZ")
            self.assertEqual(custom_displayed, "XYZ")
Beispiel #3
0
    def test_scrollable_group_visible_when(self):
        from pyface.qt import QtGui

        obj = ScrollableGroupVisibleWhen()
        tester = UITester()
        with tester.create_ui(obj) as ui:
            bar_group = tester.find_by_id(ui, 'bar_group')
            baz_group = tester.find_by_id(ui, 'baz_group')

            # for a scrollable group the GroupEditors control should be a
            # QScrollArea not just the QWidget.  We want the full area to be
            # not visible, not just the text box widget.
            self.assertIsInstance(bar_group._target.control, QtGui.QScrollArea)
            self.assertIsInstance(baz_group._target.control, QtGui.QScrollArea)

            self.assertTrue(bar_group.inspect(IsVisible()))
            self.assertFalse(baz_group.inspect(IsVisible()))

            enabled_box = tester.find_by_name(ui, 'enabled')
            baz_item = enabled_box.locate(Index(1))
            baz_item.perform(MouseClick())

            self.assertTrue(baz_group.inspect(IsVisible()))
            self.assertFalse(bar_group.inspect(IsVisible()))
    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 empty
            instance = tester.find_by_name(ui, "inst")
            text = instance.inspect(SelectedText())
            self.assertEqual(text, '')

            # test that changing selection works
            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")
Beispiel #5
0
    def test_open_internal_link(self):
        # this test requires Qt because it relies on the link filling up
        # the entire page through the use of CSS, which isn't supported
        # by Wx.
        model = HTMLModel(content="""
        <html>
            <a
              href='/#'
              target='_self'
              style='display:block; width: 100%; height: 100%'>
                Internal Link
            </a>
        </html>
        """)
        view = View(Item("content", editor=HTMLEditor()))

        with self.tester.create_ui(model, dict(view=view)) as ui:
            html_view = self.tester.find_by_name(ui, "content")

            # when
            with mock.patch("webbrowser.open_new") as mocked_browser:
                html_view.perform(MouseClick())

        mocked_browser.assert_not_called()
 def test_simple_editor_parent_closed(self):
     obj = ObjectWithInstance()
     tester = UITester()
     with tester.create_ui(obj, dict(view=get_view('simple'))) as ui:
         instance = tester.find_by_name(ui, "inst")
         instance.perform(MouseClick())
 def click_button():
     ui_tester.find_by_name(ui, "inst").perform(MouseClick())
Beispiel #8
0
    def test_run_demo(self):
        demo = runpy.run_path(DEMO_PATH)["demo"]

        tester = UITester()
        with tester.create_ui(demo) as ui:
            simple_small = tester.find_by_id(ui, 'simple_small')
            custom_small = tester.find_by_id(ui, 'custom_small')
            text_small = tester.find_by_id(ui, 'text_small')
            readonly_small = tester.find_by_id(ui, 'readonly_small')

            simple_medium = tester.find_by_id(ui, 'simple_medium')
            custom_medium = tester.find_by_id(ui, 'custom_medium')
            text_medium = tester.find_by_id(ui, 'text_medium')
            readonly_medium = tester.find_by_id(ui, 'readonly_medium')

            # Testing for SimpleSpinEditor is not supported yet so the simple
            # and custom styles for the large_range_int are not included here
            text_large = tester.find_by_id(ui, 'text_large')
            readonly_large = tester.find_by_id(ui, 'readonly_large')

            simple_float = tester.find_by_id(ui, 'simple_float')
            custom_float = tester.find_by_id(ui, 'custom_float')
            text_float = tester.find_by_id(ui, 'text_float')
            readonly_float = tester.find_by_id(ui, 'readonly_float')

            # Tests for the small_int_range ##################################
            simple_small_slider = simple_small.locate(Slider())
            simple_small_slider.perform(KeyClick("Page Up"))
            self.assertEqual(demo.small_int_range, 2)
            simple_small_text = simple_small.locate(Textbox())
            simple_small_text.perform(KeyClick("Backspace"))
            simple_small_text.perform(KeyClick("3"))
            simple_small_text.perform(KeyClick("Enter"))
            self.assertEqual(demo.small_int_range, 3)

            custom_small.locate(Index(0)).perform(MouseClick())
            self.assertEqual(demo.small_int_range, 1)

            text_small.perform(KeyClick("0"))
            text_small.perform(KeyClick("Enter"))
            self.assertEqual(demo.small_int_range, 10)

            demo.small_int_range = 7
            displayed_small = readonly_small.inspect(DisplayedText())
            self.assertEqual(displayed_small, '7')

            # Tests for the medium_int_range #################################
            simple_medium_slider = simple_medium.locate(Slider())
            # on this range, page up/down corresponds to a change of 2.
            simple_medium_slider.perform(KeyClick("Page Up"))
            self.assertEqual(demo.medium_int_range, 3)
            simple_medium_text = simple_medium.locate(Textbox())
            simple_medium_text.perform(KeyClick("Backspace"))
            simple_medium_text.perform(KeyClick("4"))
            simple_medium_text.perform(KeyClick("Enter"))
            self.assertEqual(demo.medium_int_range, 4)

            custom_medium_slider = custom_medium.locate(Slider())
            custom_medium_slider.perform(KeyClick("Page Down"))
            self.assertEqual(demo.medium_int_range, 2)
            custom_medium_text = custom_medium.locate(Textbox())
            custom_medium_text.perform(KeyClick("Backspace"))
            custom_medium_text.perform(KeyClick("1"))
            custom_medium_text.perform(KeyClick("Enter"))
            self.assertEqual(demo.medium_int_range, 1)

            text_medium.perform(KeyClick("0"))
            text_medium.perform(KeyClick("Enter"))
            self.assertEqual(demo.medium_int_range, 10)

            demo.medium_int_range = 7
            displayed_medium = readonly_medium.inspect(DisplayedText())
            self.assertEqual(displayed_medium, '7')

            # Tests for the large_int_range ##################################
            # Testing for SimpleSpinEditor is not supported yet
            text_large.perform(KeySequence("00"))
            text_large.perform(KeyClick("Enter"))
            self.assertEqual(demo.large_int_range, 100)

            demo.large_int_range = 77
            displayed_large = readonly_large.inspect(DisplayedText())
            self.assertEqual(displayed_large, '77')

            # Tests for the float_range ######################################
            simple_float_slider = simple_float.locate(Slider())
            # on this range, page up/down corresponds to a change of 1.000.
            simple_float_slider.perform(KeyClick("Page Up"))
            self.assertEqual(demo.float_range, 1.000)
            simple_float_text = simple_float.locate(Textbox())
            for _ in range(3):
                simple_float_text.perform(KeyClick("Backspace"))
            simple_float_text.perform(KeyClick("5"))
            simple_float_text.perform(KeyClick("Enter"))
            self.assertEqual(demo.float_range, 1.5)

            custom_float_slider = custom_float.locate(Slider())
            # after the trait is set to 1.5 above, the active range shown by
            # the LargeRangeSliderEditor for the custom style is [0,11.500]
            # so a page down is now a decrement of 1.15
            custom_float_slider.perform(KeyClick("Page Down"))
            self.assertEqual(round(demo.float_range, 2), 0.35)
            custom_float_text = custom_float.locate(Textbox())
            for _ in range(5):
                custom_float_text.perform(KeyClick("Backspace"))
            custom_float_text.perform(KeySequence("50.0"))
            custom_float_text.perform(KeyClick("Enter"))
            self.assertEqual(demo.float_range, 50.0)

            text_float.perform(KeyClick("5"))
            text_float.perform(KeyClick("Enter"))
            self.assertEqual(demo.float_range, 50.05)

            demo.float_range = 72.0
            displayed_float = readonly_float.inspect(DisplayedText())
            self.assertEqual(displayed_float, '72.0')
 def click_custom_button():
     custom_button.perform(MouseClick())
 def click_simple_button():
     simple_button.perform(MouseClick())
Beispiel #11
0
 def click_help():
     # should not fail
     help_button.perform(MouseClick())