File: test_exceptions.py

package info (click to toggle)
python-fastjsonschema 2.21.1-1
  • links: PTS, VCS
  • area: main
  • in suites: forky, sid, trixie
  • size: 4,780 kB
  • sloc: python: 3,343; makefile: 88; sh: 18
file content (30 lines) | stat: -rw-r--r-- 1,045 bytes parent folder | download | duplicates (2)
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
import pytest

from fastjsonschema import JsonSchemaValueException


@pytest.mark.parametrize('value, expected', [
    ('data', ['data']),
    ('data[0]', ['data', '0']),
    ('data.foo', ['data', 'foo']),
    ('data[1].bar', ['data', '1', 'bar']),
    ('data.foo[2]', ['data', 'foo', '2']),
    ('data.foo.bar[1][2]', ['data', 'foo', 'bar', '1', '2']),
    ('data[1][2].foo.bar', ['data', '1', '2', 'foo', 'bar']),
])
def test_exception_variable_path(value, expected):
    exc = JsonSchemaValueException('msg', name=value)
    assert exc.path == expected


@pytest.mark.parametrize('definition, rule, expected_rule_definition', [
    (None, None, None),
    ({}, None, None),
    ({'type': 'string'}, None, None),
    ({'type': 'string'}, 'unique', None),
    ({'type': 'string'}, 'type', 'string'),
    (None, 'type', None),
])
def test_exception_rule_definition(definition, rule, expected_rule_definition):
    exc = JsonSchemaValueException('msg', definition=definition, rule=rule)
    assert exc.rule_definition == expected_rule_definition