def test_int_numpy(): from config import Int np = pytest.importorskip("numpy") item = Int() value = item.validate(np.int32(1)) assert isinstance(value, int) assert value == 1
def test_int_validate(): from config import Int item = Int() assert item.validate(5) == 5 assert item.validate(None) is None # float with is_integer() == True is allowed assert isinstance(item.validate(5.0), int) with pytest.raises(ConfigError): item.validate(5.1) with pytest.raises(ConfigError): item.validate('5.0') item = Int(default=1, allow_none=False) with pytest.raises(ConfigError): item.validate(None)