def test_format_type_error(path: PathHolder, formatted: str, *, formatter: Formatter): with given: error = TypeValidationError(path, actual_value="banana", expected_type=int) with when: res = error.format(formatter) with then: assert res == formatted
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_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_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_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_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_dict_type_validation_error(): with given: sch = schema.dict value = [] with when: result = validate(sch, value) with then: assert result.get_errors() == [ TypeValidationError(PathHolder(), value, dict) ]
def test_list_of_type_validation_kwargs(): with given: value = 3.14 path = PathHolder().items[0]["key"] with when: result = validate(schema.list(schema.int), [42, value], path=path) with then: assert result.get_errors() == [ TypeValidationError(path[1], value, int) ]
def test_dict_with_optional_key_validation_error(): with given: sch = schema.dict({ "id": schema.int, optional("name"): schema.str, }) with when: result = validate(sch, { "id": 1, "name": None }) with then: assert result.get_errors() == [ TypeValidationError(PathHolder()["name"], None, str) ]
def make_error() -> ValidationError: return TypeValidationError(PathHolder(), "", int)
def test_validation_type_error(): with when: res = TypeValidationError(PathHolder(), "banana", int) with then: assert repr(res) == "TypeValidationError(PathHolder(), 'banana', <class 'int'>)"