Esempio n. 1
0
 def test_modify_slider_log_range_slider(self):
     model = RangeModel()
     view = View(
         Item(
             "float_value",
             editor=RangeEditor(low=.1, high=1000000000, mode='logslider')
         )
     )
     tester = UITester()
     with tester.create_ui(model, dict(view=view)) as ui:
         number_field = tester.find_by_name(ui, "float_value")
         slider = number_field.locate(Slider())
         text = number_field.locate(Textbox())
         # 10 steps is equivalent to 1 page step
         # on this scale either of those is equivalent to increasing the
         # trait's value from 10^n to 10^(n+1)
         for _ in range(10):
             slider.perform(KeyClick("Right"))
         displayed = text.inspect(DisplayedText())
         self.assertEqual(model.float_value, 1.0)
         self.assertEqual(displayed, str(model.float_value))
         slider.perform(KeyClick("Page Up"))
         displayed = text.inspect(DisplayedText())
         self.assertEqual(model.float_value, 10.0)
         self.assertEqual(displayed, str(model.float_value))
Esempio n. 2
0
 def check_modify_slider(self, mode):
     model = RangeModel(value=0)
     view = View(
         Item(
             "value",
             editor=RangeEditor(low=0, high=10, mode=mode)
         )
     )
     tester = UITester()
     with tester.create_ui(model, dict(view=view)) as ui:
         number_field = tester.find_by_name(ui, "value")
         slider = number_field.locate(Slider())
         text = number_field.locate(Textbox())
         # slider values are converted to a [0, 10000] scale.  A single
         # step is a change of 100 on that scale and a page step is 1000.
         # Our range in [0, 10] so these correspond to changes of .1 and 1.
         # Note: when tested manually, the step size seen on OSX and Wx is
         # different.
         for _ in range(10):
             slider.perform(KeyClick("Right"))
         displayed = text.inspect(DisplayedText())
         self.assertEqual(model.value, 1)
         self.assertEqual(displayed, str(model.value))
         slider.perform(KeyClick("Page Up"))
         displayed = text.inspect(DisplayedText())
         self.assertEqual(model.value, 2)
         self.assertEqual(displayed, str(model.value))
Esempio n. 3
0
    def test_modify_out_of_range_with_slider(self):
        obj = RangeExcludeLow()
        tester = UITester(auto_process_events=False)
        with tester.create_ui(obj) as ui:
            number_field = tester.find_by_name(ui, "x")
            slider = number_field.locate(Slider())

            # slider values are converted to a [0, 10000] scale.  A single
            # step is a change of 100 on that scale and a page step is 1000.
            # Our range in [0, 10] so these correspond to changes of .1 and 1.
            # Note: when tested manually, the step size seen on OSX and Wx is
            # different.

            # should not fail
            def move_slider_out_of_range():
                slider.perform(KeyClick("Page Down"))

            mdtester = ModalDialogTester(move_slider_out_of_range)
            mdtester.open_and_run(lambda x: x.click_button(OK))
Esempio n. 4
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')