示例#1
0
 def test_set_invalid_value_should_raise(self, qtbot):
     list_param = ListParameter('potato',
                                choices=[123, 456],
                                default=123,
                                units='m')
     list_input = ListInput(list_param)
     qtbot.addWidget(list_input)
     with pytest.raises(ValueError):
         list_input.setValue(789)
示例#2
0
    def test_unit_should_append_to_strings(self, qtbot):
        list_param = ListParameter('potato',
                                   choices=[123, 456],
                                   default=123,
                                   units='m')
        list_input = ListInput(list_param)
        qtbot.addWidget(list_input)

        assert list_input.currentText() == '123 m'
示例#3
0
    def test_init_from_param(self, qtbot, choices, default_value):
        list_param = ListParameter('potato',
                choices=choices,
                default=default_value,
                units='m')
        list_input = ListInput(list_param)
        qtbot.addWidget(list_input)

        assert list_input.isEditable() == False
        assert list_input.value() == default_value
示例#4
0
    def test_init_from_param(self, qtbot, choices, default_value):
        list_param = ListParameter('potato',
                                   choices=choices,
                                   default=default_value,
                                   units='m')
        list_input = ListInput(list_param)
        qtbot.addWidget(list_input)

        assert list_input.isEditable() == False
        assert list_input.value() == default_value
示例#5
0
    def test_setValue_should_update_value(self, qtbot):
        # Test write-read loop: verify value -> index -> value conversion
        choices = [123, 'abc', 0]
        list_param = ListParameter('potato', choices=choices, default=123)
        list_input = ListInput(list_param)
        qtbot.addWidget(list_input)

        for choice in choices:
            list_input.setValue(choice)
            assert list_input.currentText() == str(choice)
            assert list_input.value() == choice
示例#6
0
    def test_setValue_should_update_parameter(self, qtbot):
        choices = [123, 'abc', 0]
        list_param = ListParameter('potato', choices=choices, default=123)
        list_input = ListInput(list_param)
        qtbot.addWidget(list_input)

        with mock.patch('test_inputs.ListParameter.value',
                new_callable=mock.PropertyMock,
                return_value=123) as p:
            for choice in choices:
                list_input.setValue(choice)
                list_input.parameter # lazy update
            p.assert_has_calls((mock.call(123), mock.call('abc'), mock.call(0)))
示例#7
0
    def test_setValue_should_update_parameter(self, qtbot):
        choices = [123, 'abc', 0]
        list_param = ListParameter('potato', choices=choices, default=123)
        list_input = ListInput(list_param)
        qtbot.addWidget(list_input)

        with mock.patch('test_inputs.ListParameter.value',
                new_callable=mock.PropertyMock,
                return_value=123) as p:
            for choice in choices:
                list_input.setValue(choice)
                list_input.parameter # lazy update
            p.assert_has_calls((mock.call(123), mock.call('abc'), mock.call(0)))
示例#8
0
    def test_init_from_param(self, qtbot, choices, default_value,
                             value_remains_default):
        list_param = ListParameter('potato',
                                   choices=choices,
                                   default=default_value,
                                   units='m')

        if (value_remains_default):
            # Enable check that the value is initialized to default_value
            check_value = default_value
        else:
            # Set to a non default value
            list_param.value = choices[2]
            # Enable check that the value is changed after initialization to a non default_value
            check_value = choices[2]

        list_input = ListInput(list_param)
        qtbot.addWidget(list_input)

        assert list_input.isEditable() == False
        assert list_input.value() == check_value
示例#9
0
    def test_setValue_should_update_value(self, qtbot):
        # Test write-read loop: verify value -> index -> value conversion
        choices = [123, 'abc', 0]
        list_param = ListParameter('potato', choices=choices, default=123)
        list_input = ListInput(list_param)
        qtbot.addWidget(list_input)

        for choice in choices:
            list_input.setValue(choice)
            assert list_input.currentText() == str(choice)
            assert list_input.value() == choice
示例#10
0
    def _make_input(self, name, parameter):
        if parameter.ui_class is not None:
            element = parameter.ui_class(parameter)

        elif isinstance(parameter, FloatParameter):
            element = ScientificInput(parameter)

        elif isinstance(parameter, IntegerParameter):
            element = IntegerInput(parameter)

        elif isinstance(parameter, BooleanParameter):
            element = BooleanInput(parameter)

        elif isinstance(parameter, ListParameter):
            element = ListInput(parameter)

        elif isinstance(parameter, FileParameter):
            element = FileInput(parameter)

        elif isinstance(parameter, DirectoryParameter):
            element = DirectoryInput(parameter)

        elif isinstance(parameter, TextEditParameter):
            element = FloatTextEditInput(parameter)

        elif isinstance(parameter, Parameter):
            element = StringInput(parameter)

        else:
            raise ValueError("unrecognized parameter type: {}".format(
                type(parameter)))

        setattr(self, name, element)

        if name in self._procedure.TOOLTIPS.keys():
            element.setToolTip(self._procedure.TOOLTIPS[name])
示例#11
0
 def test_set_invalid_value_should_raise(self, qtbot):
     list_param = ListParameter('potato', choices=[123, 456], default=123, units='m')
     list_input = ListInput(list_param)
     qtbot.addWidget(list_input)
     with pytest.raises(ValueError):
         list_input.setValue(789)
示例#12
0
    def test_unit_should_append_to_strings(self, qtbot):
        list_param = ListParameter('potato', choices=[123, 456], default=123, units='m')
        list_input = ListInput(list_param)
        qtbot.addWidget(list_input)

        assert list_input.currentText() == '123 m'