Example #1
0
def test_float_bounds():
    p = FloatParameter('Test', minimum=0.1, maximum=0.5)
    p.value = 0.3
    assert p.value == 0.3
    with pytest.raises(ValueError):
        p.value = 10  # above maximum
    with pytest.raises(ValueError):
        p.value = -10  # below minimum
Example #2
0
def test_float_bounds():
    p = FloatParameter('Test', minimum=0.1, maximum=0.5)
    p.value = 0.3
    assert p.value == 0.3
    with pytest.raises(ValueError):
        p.value = 10  # above maximum
    with pytest.raises(ValueError):
        p.value = -10  # below minimum
Example #3
0
def test_float_value():
    p = FloatParameter('Test')
    with pytest.raises(ValueError):
        v = p.value  # not set
    with pytest.raises(ValueError):
        p.value = 'a'  # not a float
    p.value = False  # boolean
    assert p.value == 0.0
    p.value = 100
    assert p.value == 100.0
Example #4
0
def test_float_value():
    p = FloatParameter('Test')
    with pytest.raises(ValueError):
        v = p.value  # not set
    with pytest.raises(ValueError):
        p.value = 'a'  # not a float
    p.value = False  # boolean
    assert p.value == 0.0
    p.value = 100
    assert p.value == 100.0
Example #5
0
def test_float_bounds():
    p = FloatParameter('Test', minimum=0.1, maximum=0.5)
    p.value = 0.3
    assert p.value == 0.3
    with pytest.raises(ValueError):
        p.value = 10  # above maximum
    with pytest.raises(ValueError):
        p.value = -10  # below minimum


# TODO: Add tests for VectorParameter, ListParamter, and Measurable
Example #6
0
def test_float_bounds():
    p = FloatParameter('Test', minimum=0.1, maximum=0.5)
    p.value = 0.3
    assert p.value == 0.3
    with pytest.raises(ValueError):
        p.value = 10 # above maximum
    with pytest.raises(ValueError):
        p.value = -10 # below minimum


# TODO: Add tests for VectorParameter, ListParamter, and Measurable
Example #7
0
def test_float_value():
    p = FloatParameter('Test', units='tests')
    with pytest.raises(ValueError):
        _ = p.value  # not set
    with pytest.raises(ValueError):
        p.value = 'a'  # not a float
    p.value = False  # boolean
    assert p.value == 0.0
    p.value = 100
    assert p.value == 100.0
    p.value = '1.06'
    assert p.value == 1.06
    p.value = '11.3 tests'
    assert p.value == 11.3
    assert p.units == 'tests'
    with pytest.raises(ValueError):
        p.value = '31.3 incorrect units'  # not the correct units
Example #8
0
    def test_init_from_param(self, qtbot, min_, max_, default_value,
                             value_remains_default):
        float_param = FloatParameter('potato',
                                     minimum=min_,
                                     maximum=max_,
                                     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
            float_param.value = min_
            # Enable check that the value is changed after initialization to a non default value
            check_value = min_

        sci_input = ScientificInput(float_param)
        qtbot.addWidget(sci_input)

        assert sci_input.minimum() == min_
        assert sci_input.maximum() == max_
        assert sci_input.value() == check_value
        assert sci_input.suffix() == ' m'