Пример #1
0
def test_invalid_allowed(value):
    """Check that ValueError is raised if the value is not in the allowed set."""

    allowed = [-4.0, -5.0, 20.0, 7.0]
    f = Float(help="Help!", allowed=allowed)
    with pytest.raises(ValueError):
        f.setValue(value)
Пример #2
0
def test_valid_min_max(value):
    """Check that all is okay when the value is within min/max."""

    f = Float(help="Help!", minimum=-2.0, maximum=7.9)
    f.setValue(value)
    assert f.getValue() == value
    assert f.getHelp() == "Help!"
    assert f.isOptional() == False
    assert f.getDefault() == None
    assert f.getMin() == -2.0
    assert f.getMax() == 7.9
    assert f.getAllowedValues() is None
    assert f.isMulti() == False
    assert f.getArgType() == float
Пример #3
0
def test_valid_allowed(value):
    """Test that all is okay if the value is in the allowed set."""

    allowed = [-4.5, -5.1, -7.0, 20.0, 9.0, 7.0]
    f = Float(help="Help!", allowed=allowed)
    f.setValue(value)
    assert f.getValue() == value
    assert f.getHelp() == "Help!"
    assert f.isOptional() == False
    assert f.getDefault() == None
    assert f.getMin() == None
    assert f.getMax() == None
    assert f.getAllowedValues() == allowed
    assert f.isMulti() == False
    assert f.getArgType() == float
Пример #4
0
def test_value(value):
    """Test whether object is initialised correctly and value is set."""

    # Create Float object with minimium required arguments.
    f = Float(help="Help!")

    # Set the value of the float.
    f.setValue(value)

    # Assert that all arguments are parsed correctly and the value is set.
    assert f.getValue() == value
    assert f.getHelp() == "Help!"
    assert f.isOptional() == False
    assert f.getDefault() == None
    assert f.getMin() == None
    assert f.getMax() == None
    assert f.getAllowedValues() is None
    assert f.isMulti() == False
    assert f.getArgType() == float
Пример #5
0
def test_invalid_min_max(value):
    """Check that ValueError is raised if value is outside of min/max range."""

    f = Float(help="Help!", minimum=-2.0, maximum=7.9)
    with pytest.raises(ValueError):
        f.setValue(value)
Пример #6
0
def test_bad_value(value):
    """Test that TypeError is raised when "value" is not a float or int."""

    f = Float(help="Help!")
    with pytest.raises(TypeError):
        f.setValue(value)