def test_ranges(self): number_field = NumberField(min_value=0, max_value=5) number_field.validate(0) number_field.validate(1) number_field.validate(2) with pytest.raises(ConfigError): number_field.validate(-1) with pytest.raises(ConfigError): number_field.validate(7)
def test_infs(self): number_field = NumberField(allow_inf=True) number_field.validate(inf) number_field = NumberField(allow_inf=False) with pytest.raises(ConfigError): number_field.validate(inf)
def test_nans(self): number_field = NumberField(allow_nan=True) number_field.validate(nan) number_field = NumberField(allow_nan=False) with pytest.raises(ConfigError): number_field.validate(nan)
def test_expects_number(self): number_field = NumberField(floats=True) number_field.validate(1.0) with pytest.raises(ConfigError): number_field.validate("foo") with pytest.raises(ConfigError): number_field.validate({}) with pytest.raises(ConfigError): number_field.validate([]) number_field = NumberField(floats=False) number_field.validate(1) with pytest.raises(ConfigError): number_field.validate(1.0)
class SampleValidatorWithOptionals(ConfigValidator): foo = StringField(choices=['foo']) bar = NumberField(optional=True)
class SampleValidator(ConfigValidator): foo = StringField(choices=['foo']) bar = NumberField()
def test_expects_number(self): number_field = NumberField(value_type=float) number_field.validate(1.0) with pytest.raises(ConfigError): number_field.validate("foo") with pytest.raises(ConfigError): number_field.validate({}) with pytest.raises(ConfigError): number_field.validate([]) number_field = NumberField(value_type=int) number_field.validate(1) with pytest.raises(ConfigError): number_field.validate(1.0)