def test_doc_generation(): schema = Integer(description="Test description", minimum=10) assert schema.to_doc() == { "description": "Test description", "minimum": 10, "type": "integer", }
def test_nullable(): assert Integer(nullable=True).validate(None) is None
def test_can_instantiate(): test_integer = Integer() assert test_integer.validate(10)
def test_pass_range(min, max, value): assert Integer(minimum=min, maximum=max).validate(value) is value
def test_fail_range(min, max, value): with pytest.raises(ValidationError): Integer(minimum=min, maximum=max).validate(value)
def test_fail_multiple_of(multiplication, value): with pytest.raises(ValidationError): Integer(multiple_of=multiplication).validate(value)
def test_pass_multiple_of(multiplication, value): assert Integer(multiple_of=multiplication).validate(value) is value
def test_validation_pass(value): assert Integer().validate(value) is value
def test_validation_fail(value): with pytest.raises(ValidationError): Integer().validate(value)
assert validate(value, type_definition) is None @pytest.mark.parametrize( "value,type_definition", [ [[], Sequence], [(1, ), Sequence], [[1], Sequence[int]], [("a", "b", None), Sequence[Optional[str]]], [[1, 2, 3], Sequence[int]], ], ) def test_validate_sequence_type_definitions(value, type_definition): assert validate(value, type_definition) is None @pytest.mark.parametrize( "value,type_definition", [[(1, ), Tuple], [("a", "b", None), Tuple[Optional[str]]], [(1, 2, 3), Tuple[int]]], ) def test_validate_tuple_type_definitions(value, type_definition): assert validate(value, type_definition) is None @pytest.mark.parametrize("value,type_definition", [([1, 2, 3], Array(Integer(minimum=0, maximum=5)))]) def test_validate_schema_types(value, type_definition): assert validate(value, type_definition) is None