Esempio n. 1
0
def test_coercion_aok_list(val, expected, validator_aok: NumberValidator):
    v = validator_aok.validate_coerce(val)
    if isinstance(val, np.ndarray):
        assert v.dtype == 'float'
        assert np.array_equal(v, expected)
    else:
        assert isinstance(v, list)
        assert validator_aok.present(v) == tuple(val)
Esempio n. 2
0
def validator_min(request):
    return NumberValidator('prop', 'parent', min=-1.0)
Esempio n. 3
0
def validator(request):
    return NumberValidator('prop', 'parent')
def validator_aok():
    return NumberValidator("prop", "parent", min=-1, max=1.5, array_ok=True)
def validator_max(request):
    return NumberValidator("prop", "parent", max=2.0)
def validator_min(request):
    return NumberValidator("prop", "parent", min=-1.0)
Esempio n. 7
0
def number_validator(request):
    return NumberValidator("prop", "parent", array_ok=True)
Esempio n. 8
0
def test_acceptance_max(val, validator_max: NumberValidator):
    assert validator_max.validate_coerce(val) == approx(val)
Esempio n. 9
0
def test_rejection_max(val, validator_max: NumberValidator):
    with pytest.raises(ValueError) as validation_failure:
        validator_max.validate_coerce(val)

    assert 'in the interval [-inf, 2.0]' in str(validation_failure.value)
Esempio n. 10
0
def test_rejection_by_value(val, validator: NumberValidator):
    with pytest.raises(ValueError) as validation_failure:
        validator.validate_coerce(val)

    assert 'Invalid value' in str(validation_failure.value)
Esempio n. 11
0
def test_rejection_min(val, validator_min: NumberValidator):
    with pytest.raises(ValueError) as validation_failure:
        validator_min.validate_coerce(val)

    assert 'in the interval [-1.0, inf]' in str(validation_failure.value)
Esempio n. 12
0
def test_acceptance(val, validator: NumberValidator):
    assert validator.validate_coerce(val) == approx(val, nan_ok=True)
Esempio n. 13
0
def test_rejection_aok_min_max(val, validator_aok: NumberValidator):
    with pytest.raises(ValueError) as validation_failure:
        validator_aok.validate_coerce(val)

    assert 'Invalid element(s)' in str(validation_failure.value)
    assert 'in the interval [-1, 1.5]' in str(validation_failure.value)
Esempio n. 14
0
def test_rejection_aok(val, validator_aok: NumberValidator):
    with pytest.raises(ValueError) as validation_failure:
        validator_aok.validate_coerce(val)

    assert 'Invalid element(s)' in str(validation_failure.value)
Esempio n. 15
0
def validator_max(request):
    return NumberValidator('prop', 'parent', max=2.0)
Esempio n. 16
0
def test_acceptance_aok_scalars(val, validator_aok: NumberValidator):
    assert validator_aok.validate_coerce(val) == val
Esempio n. 17
0
def validator_aok():
    return NumberValidator('prop', 'parent', min=-1, max=1.5, array_ok=True)
def validator(request):
    return NumberValidator("prop", "parent")
Esempio n. 19
0
def number_validator(request):
    return NumberValidator('prop', 'parent', array_ok=True)
Esempio n. 20
0
def test_acceptance_aok_list(val, validator_aok: NumberValidator):
    assert np.array_equal(validator_aok.validate_coerce(val),
                          np.array(val, dtype='float'))