Example #1
0
def test_part_validation_missing():
    data = {
        "plugin": "make",
        "make-parameters": ["-C bar"],
    }

    error = r"source\s+field required"
    with pytest.raises(pydantic.ValidationError, match=error):
        validate_part(data)
Example #2
0
def test_part_validation_extra():
    data = {
        "plugin": "make",
        "source": "foo",
        "make-parameters": ["-C bar"],
        "unexpected-extra": True,
    }

    error = r"unexpected-extra\s+extra fields not permitted"
    with pytest.raises(pydantic.ValidationError, match=error):
        validate_part(data)
Example #3
0
def test_part_validation_immutable():
    data = {
        "plugin": "make",
        "source": "foo",
        "make-parameters": ["-C bar"],
    }
    data_copy = copy.deepcopy(data)

    validate_part(data)

    assert data == data_copy
Example #4
0
def test_part_validation_data_type():
    with pytest.raises(TypeError) as raised:
        validate_part("invalid data")  # type: ignore

    assert str(raised.value) == "value must be a dictionary"
Example #5
0
 def _validate_parts(cls, item):
     """Verify each part (craft-parts will re-validate this)."""
     parts_validation.validate_part(item)
     return item