def test_validator_validate_pass(): with when: result = validate(schema.int, 42) with then: assert isinstance(result, ValidationResult) assert not result.has_errors()
def test_str_contains_validation(value: str): with given: substr = "banana" with when: result = validate(schema.str.contains(substr), value) with then: assert result.get_errors() == []
def test_int_value_validation(): with given: value = 42 with when: result = validate(schema.int(value), value) with then: assert result.get_errors() == []
def test_dict_relaxed_no_keys_validation(value: Dict[Any, Any]): with given: sch = schema.dict({...:...}) with when: result = validate(sch, value) with then: assert result.get_errors() == []
def test_str_min_max_len_validation_error(min_length: int, max_length: int): with given: value = "banana" with when: result = validate(schema.str.len(min_length, max_length), value) with then: assert len(result.get_errors()) == 1
def test_dict_type_validation(value: Dict[Any, Any]): with given: sch = schema.dict with when: result = validate(sch, value) with then: assert result.get_errors() == []
def test_list_len_validation(): with given: value = [1, 2] with when: result = validate(schema.list.len(2), value) with then: assert result.get_errors() == []
def test_bytes_value_validation(): with given: value = b"banana" with when: result = validate(schema.bytes(value), value) with then: assert result.get_errors() == []
def test_list_contains_head_validation(value: List[Any]): with given: sch = schema.list([schema.int(1), schema.int(2), ...]) with when: result = validate(sch, value) with then: assert result.get_errors() == []
def test_list_min_max_len_validation_error(min_length: int, max_length: int): with given: value = [1, 2] with when: result = validate(schema.list.len(min_length, max_length), value) with then: assert len(result.get_errors()) == 1
def test_float_value_validation(): with given: value = 3.14 with when: result = validate(schema.float(value), value) with then: assert result.get_errors() == []
def test_str_len_validation(): with given: value = "banana" with when: result = validate(schema.str.len(6), value) with then: assert result.get_errors() == []
def test_dict_no_keys_validation(): with given: sch = schema.dict({}) value = {} with when: result = validate(sch, value) with then: assert result.get_errors() == []
def test_str_regex_validation(): with given: pattern = "[a-z]+" value = "banana" with when: result = validate(schema.str.regex(pattern), value) with then: assert result.get_errors() == []
def test_list_of_type_elements_validation_error(): with given: value = 3.14 with when: result = validate(schema.list(schema.int), [42, value]) with then: path = PathHolder()[1] assert result.get_errors() == [TypeValidationError(path, value, int)]
def test_none_validation_error(): with given: value = False with when: result = validate(schema.none, value) with then: assert result.get_errors() == [ TypeValidationError(PathHolder(), value, type(None)) ]
def test_list_type_validation_error(): with given: value = {} with when: result = validate(schema.list, value) with then: assert result.get_errors() == [ TypeValidationError(PathHolder(), value, list), ]
def test_bytes_type_validation_error(): with given: value = "banana" with when: result = validate(schema.bytes, value) with then: assert result.get_errors() == [ TypeValidationError(PathHolder(), value, bytes), ]
def test_bool_type_validation_error(): with given: value = "True" with when: result = validate(schema.bool, value) with then: assert result.get_errors() == [ TypeValidationError(PathHolder(), value, bool) ]
def test_list_len_validation_error(value: List[Any]): with given: length = 2 with when: result = validate(schema.list.len(length), value) with then: assert result.get_errors() == [ LengthValidationError(PathHolder(), value, length) ]
def test_str_contains_validation_error(value: str): with given: substr = "banana" with when: result = validate(schema.str.contains(substr), value) with then: assert result.get_errors() == [ SubstrValidationError(PathHolder(), value, substr) ]
def test_int_type_validation_error(): with given: value = 3.14 with when: result = validate(schema.int, value) with then: assert result.get_errors() == [ TypeValidationError(PathHolder(), value, int) ]
def test_str_type_validation_error(): with given: value = ["b", "a", "n", "a", "n", "a"] with when: result = validate(schema.str, value) with then: assert result.get_errors() == [ TypeValidationError(PathHolder(), value, str), ]
def test_str_len_validation_error(value: str): with given: length = 7 with when: result = validate(schema.str.len(length), value) with then: assert result.get_errors() == [ LengthValidationError(PathHolder(), value, length), ]
def test_float_type_validation_error(): with given: value = 42 with when: result = validate(schema.float, value) with then: assert result.get_errors() == [ TypeValidationError(PathHolder(), value, float) ]
def test_any_type_validation_kwargs(): with given: actual_value = False path = PathHolder().items[0]["key"] with when: result = validate(schema.any(schema.none), actual_value, path=path) with then: assert result.get_errors() == [ SchemaMismatchValidationError(path, actual_value, (schema.none, )) ]
def test_any_types_validation_error(): with given: value = None types = (schema.int, schema.str) with when: result = validate(schema.any(*types), value) with then: assert result.get_errors() == [ SchemaMismatchValidationError(PathHolder(), value, types) ]
def test_none_type_validation_kwargs(): with given: actual_value = False path = PathHolder().items[0]["key"] with when: result = validate(schema.none, actual_value, path=path) with then: assert result.get_errors() == [ TypeValidationError(path, actual_value, type(None)) ]
def test_list_homogeneous_elements_validation(): with given: value = [1, 2] with when: result = validate(schema.list([ schema.int(1), schema.int(2), ]), value) with then: assert result.get_errors() == []
def test_list_max_len_validation_error(): with given: value = [1, 2, 3] max_length = 2 with when: result = validate(schema.list.len(..., max_length), value) with then: assert result.get_errors() == [ MaxLengthValidationError(PathHolder(), value, max_length) ]