Example #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)
Example #2
0
def test_acceptance_aok_scalars(val, validator_aok: NumberValidator):
    assert validator_aok.validate_coerce(val) == val
Example #3
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)
Example #4
0
def test_acceptance_max(val, validator_max: NumberValidator):
    assert validator_max.validate_coerce(val) == approx(val)
Example #5
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)
Example #6
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)
Example #7
0
def test_acceptance(val, validator: NumberValidator):
    assert validator.validate_coerce(val) == approx(val, nan_ok=True)
Example #8
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)
Example #9
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)
Example #10
0
def test_acceptance_aok_list(val, validator_aok: NumberValidator):
    assert np.array_equal(validator_aok.validate_coerce(val),
                          np.array(val, dtype='float'))