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)
def validator_min(request): return NumberValidator('prop', 'parent', min=-1.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)
def number_validator(request): return NumberValidator("prop", "parent", array_ok=True)
def test_acceptance_max(val, validator_max: NumberValidator): assert validator_max.validate_coerce(val) == approx(val)
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)
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)
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)
def test_acceptance(val, validator: NumberValidator): assert validator.validate_coerce(val) == approx(val, nan_ok=True)
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)
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)
def validator_max(request): return NumberValidator('prop', 'parent', max=2.0)
def test_acceptance_aok_scalars(val, validator_aok: NumberValidator): assert validator_aok.validate_coerce(val) == val
def validator_aok(): return NumberValidator('prop', 'parent', min=-1, max=1.5, array_ok=True)
def validator(request): return NumberValidator("prop", "parent")
def number_validator(request): return NumberValidator('prop', 'parent', array_ok=True)
def test_acceptance_aok_list(val, validator_aok: NumberValidator): assert np.array_equal(validator_aok.validate_coerce(val), np.array(val, dtype='float'))