Пример #1
0
def test_list_value_with_units():
    # TODO: check against setting the string version (with units) of the numeric choices
    p = ListParameter('Test', choices=[1, 2.2, 'three', 'and four'], units='tests')
    p.value = 'three tests'
    assert p.value == 'three'
    p.value = 'and four tests'
    assert p.value == 'and four'
Пример #2
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)
Пример #3
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'
Пример #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_list_value():
    p = ListParameter('Test', choices=[1, 2.2, 'three', 'and four'])
    p.value = 1
    assert p.value == 1
    p.value = 2.2
    assert p.value == 2.2
    p.value = '1'  # reading from file
    assert p.value == 1
    p.value = '2.2'  # reading from file
    assert p.value == 2.2
    p.value = 'three'
    assert p.value == 'three'
    p.value = 'and four'
    assert p.value == 'and four'
    with pytest.raises(ValueError):
        p.value = 5
Пример #6
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
Пример #7
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
Пример #8
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)))
Пример #9
0
def test_list_value():
    # TODO: check against setting the string version of the numeric choices
    p = ListParameter('Test', choices=[1, 2.2, 'three', 'and four'])
    p.value = 1
    assert p.value == 1
    p.value = 2.2
    assert p.value == 2.2
    p.value = 'three'
    assert p.value == 'three'
    p.value = 'and four'
    assert p.value == 'and four'
    with pytest.raises(ValueError):
        p.value = 5
Пример #10
0
def test_list_value_with_units():
    p = ListParameter(
        'Test', choices=[1, 2.2, 'three', 'and four'],
        units='tests')
    p.value = '1 tests'
    assert p.value == 1
    p.value = '2.2 tests'
    assert p.value == 2.2
    p.value = 'three tests'
    assert p.value == 'three'
    p.value = 'and four tests'
    assert p.value == 'and four'
Пример #11
0
def test_list_order():
    p = ListParameter('Test', choices=[1, 2.2, 'three', 'and four'])
    # check if order is preserved, choices are internally stored as dict
    assert p.choices == (1, 2.2, 'three', 'and four')
Пример #12
0
def test_list_string():
    # make sure string representation of choices is unique
    with pytest.raises(ValueError):
        _ = ListParameter('Test', choices=[1, '1'])