Пример #1
0
def test_list_error_reporting():

    # OK: List of objects
    sch = S({'foo': [int]})
    data = {'foo': ['a', 'b']}
    assert (sch == data) is False
    assert len(sch.error.errors) == 2
    assert sch.error.errors[0].path == ['foo', 0]
    assert sch.error.errors[1].path == ['foo', 1]
    msgs = pytest_assertrepr_compare('==', sch, data)
    assert msgs == [
        "failed due to validation error(s):",
        "- foo.0: expected int (actual: 'a')",
        "- foo.1: expected int (actual: 'b')"
    ]

    sch = S({'foo': [{'id': int}]})
    data = {'foo': [{'id': 'bar'}, {'id': 'bar2'}]}
    assert (sch == data) is False
    assert len(sch.error.errors) == 1  # XXX: Until https://github.com/alecthomas/voluptuous/pull/330 gets merged
    assert sch.error.errors[0].path == ['foo', 0, 'id']
    msgs = pytest_assertrepr_compare('==', sch, data)
    assert msgs == [
        "failed due to validation error(s):",
        "- foo.0.id: expected int (actual: 'bar')"
    ]
Пример #2
0
def test_error_reporting():
    expected = S({
        'info': Partial({
            'package_url': 'http://pypi.python.org/pypi/pytest',
            'platform': 'INVALID VALUE',
            'description': Length(max=10),
            'downloads': list,
            'classifiers': dict,
        }),
        'urls': int
    })
    _ = expected == TEST_DATA
    msgs = pytest_assertrepr_compare('==', expected, TEST_DATA)
    assert S(Unordered([
        "failed due to validation error(s):",
        "- info.platform: not a valid value (actual: 'unix')",
        "- info.description: length of value must be at most 10 (actual: 'lorem ipsum lorem ipsum')",
        "- info.downloads: expected list (actual: {'last_month': 0})",
        "- info.classifiers: expected dict (actual: ['Development Status :: 6 - Mature', 'Intended Audience :: Developers'])",
        "- urls: expected int (actual: [{}, {}])",
        Any(
            "- releases: extra keys not allowed (actual: {'3.0.7': [], '3.1.3': []})",
            "- releases: extra keys not allowed (actual: {'3.1.3': [], '3.0.7': []})",
        ),
    ])) == msgs
Пример #3
0
def test_error_reporting():
    expected = S({
        'info':
        Partial({
            'package_url': 'http://pypi.python.org/pypi/pytest',
            'platform': 'INVALID VALUE',
            'description': Length(max=10),
            'downloads': list,
            'classifiers': dict,
        }),
        'urls':
        int
    })
    _ = expected == TEST_DATA
    msgs = pytest_assertrepr_compare('==', expected, TEST_DATA)
    assert S(
        Unordered([
            "failed to validation error(s):",
            "- info.platform: not a valid value for dictionary value @ data['info']['platform']",
            "- info.description: length of value must be at most 10 for dictionary value @ data['info']['description']",
            "- info.downloads: expected list for dictionary value @ data['info']['downloads']",
            "- info.classifiers: expected dict for dictionary value @ data['info']['classifiers']",
            "- urls: expected int for dictionary value @ data['urls']",
            "- releases: extra keys not allowed @ data['releases']"
        ])) == msgs
Пример #4
0
def test_unordered():
    actual = ["foobar", "barbaz", "baz"]
    expected = S(Unordered(["foo", "bar", "baz"]))
    _ = expected == actual
    msgs = pytest_assertrepr_compare('==', expected, actual)
    assert S(Unordered([
        "failed due to validation error(s):",
        "- Element #0 (foobar) is not valid against any validator",
        "- Element #1 (barbaz) is not valid against any validator",
    ])) == msgs