Example #1
0
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_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() == []
Example #3
0
def test_list_contains_head_validation_missing_element_error():
    with given:
        value = [1]
        sch = schema.list([schema.int(1), schema.int(2), ...])

    with when:
        result = validate(sch, value)

    with then:
        assert result.get_errors() == [
            MissingElementValidationError(PathHolder(),
                                          actual_value=value,
                                          index=1)
        ]
Example #4
0
def test_list_contains_validation_incorrect_order_error():
    with given:
        value = [2, 1]
        sch = schema.list([..., schema.int(1), schema.int(2), ...])

    with when:
        result = validate(sch, value)

    with then:
        assert result.get_errors() == [
            MissingElementValidationError(PathHolder(),
                                          actual_value=value,
                                          index=2),
        ]
Example #5
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 #6
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 #7
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 #8
0
def test_list_contains_tail_validation_incorrect_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=value[0],
                                 expected_value=1),
            MissingElementValidationError(PathHolder(),
                                          actual_value=value,
                                          index=1),
        ]
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_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)
        ]
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)
        ]
def test_list_heterogeneous_elements_validation():
    with given:
        value = [42, 3.14, "banana"]

    with when:
        result = validate(
            schema.list([
                schema.int(42),
                schema.float(3.14),
                schema.str("banana"),
            ]), value)

    with then:
        assert result.get_errors() == []
Example #13
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)
        ]