Example #1
0
def test_format_value_error(path: PathHolder, formatted: str, *,
                            formatter: Formatter):
    with given:
        error = ValueValidationError(path,
                                     actual_value="orange",
                                     expected_value="banana")

    with when:
        res = error.format(formatter)

    with then:
        assert res == formatted
Example #2
0
def test_list_contains_head_validation_error_extra_element():
    with given:
        value = [0, 1, 2]
        sch = schema.list([schema.int(1), schema.int(2), ...])

    with when:
        result = validate(sch, value)

    with then:
        assert result.get_errors() == [
            ValueValidationError(PathHolder()[0],
                                 actual_value=value[0],
                                 expected_value=1),
            ValueValidationError(PathHolder()[1],
                                 actual_value=value[1],
                                 expected_value=2),
        ]
Example #3
0
def test_validation_value_error():
    with given:
        actual = "banana"
        expected = "cucumber"

    with when:
        res = ValueValidationError(PathHolder(), actual, expected)

    with then:
        assert repr(res) == "ValueValidationError(PathHolder(), 'banana', 'cucumber')"
def test_int_value_validation_error():
    with given:
        expected_value = 42
        actual_value = 43

    with when:
        result = validate(schema.int(expected_value), actual_value)

    with then:
        assert result.get_errors() == [
            ValueValidationError(PathHolder(), actual_value, expected_value)
        ]
Example #5
0
def test_const_validation_error():
    with given:
        expected_value = "banana"
        actual_value = "apple"

    with when:
        result = validate(schema.const(expected_value), actual_value)

    with then:
        assert result.get_errors() == [
            ValueValidationError(PathHolder(), actual_value, expected_value)
        ]
Example #6
0
def test_str_value_validation_error():
    with given:
        expected_value = "banana"
        actual_value = "cucumber"

    with when:
        result = validate(schema.str(expected_value), actual_value)

    with then:
        assert result.get_errors() == [
            ValueValidationError(PathHolder(), actual_value, expected_value),
        ]
Example #7
0
def test_bool_value_validation_error():
    with given:
        expected_value = True
        actual_value = False

    with when:
        result = validate(schema.bool(expected_value), actual_value)

    with then:
        assert result.get_errors() == [
            ValueValidationError(PathHolder(), actual_value, expected_value)
        ]
def test_int_type_validation_kwargs():
    with given:
        expected_value = 42
        actual_value = 43
        path = PathHolder().items[0]["key"]

    with when:
        result = validate(schema.int(expected_value), actual_value, path=path)

    with then:
        assert result.get_errors() == [
            ValueValidationError(path, actual_value, expected_value)
        ]
Example #9
0
def test_str_type_validation_kwargs():
    with given:
        expected_value = "banana"
        actual_value = "cucumber"
        path = PathHolder().items[0]["key"]

    with when:
        result = validate(schema.str(expected_value), actual_value, path=path)

    with then:
        assert result.get_errors() == [
            ValueValidationError(path, actual_value, expected_value)
        ]
Example #10
0
def test_list_contains_validation_extra_body_element_error():
    with given:
        value = [1, 0, 2]
        sch = schema.list([..., schema.int(1), schema.int(2), ...])

    with when:
        result = validate(sch, value)

    with then:
        assert result.get_errors() == [
            ValueValidationError(PathHolder()[1],
                                 actual_value=0,
                                 expected_value=2),
        ]
Example #11
0
def test_list_contains_validation_incorrect_head_element_error():
    with given:
        value = [3, 2]
        sch = schema.list([..., schema.int(1), schema.int(2), ...])

    with when:
        result = validate(sch, value)

    with then:
        assert result.get_errors() == [
            ValueValidationError(PathHolder()[0],
                                 actual_value=3,
                                 expected_value=1),
        ]
Example #12
0
def test_list_of_type_elements_value_validation_error():
    with given:
        expected_value = 42
        actual_value = 43

    with when:
        result = validate(schema.list(schema.int(expected_value)),
                          [expected_value, actual_value])

    with then:
        path = PathHolder()[1]
        assert result.get_errors() == [
            ValueValidationError(path, actual_value, expected_value)
        ]
Example #13
0
def test_list_contains_validation_missing_head_element_error():
    with given:
        value = [2]
        sch = schema.list([..., schema.int(1), schema.int(2), ...])

    with when:
        result = validate(sch, value)

    with then:
        assert result.get_errors() == [
            ValueValidationError(PathHolder()[0],
                                 actual_value=2,
                                 expected_value=1),
            MissingElementValidationError(PathHolder(),
                                          actual_value=value,
                                          index=1),
        ]