File: test_const.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 (24 lines) | stat: -rw-r--r-- 657 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
import pytest

from fastjsonschema import JsonSchemaValueException


@pytest.mark.parametrize('value, testError', (
    ('foo', False),
    (42, False),
    (False, False),
    ([1, 2, 3], False),
    ('\'"', False),
    ('foo', True),
    ('\'"', False),
))
def test_const(asserter, value, testError):
    const = expected = value
    if testError:
        const = 'x'
        expected = JsonSchemaValueException('data must be same as const definition: x', value='{data}', name='data', definition='{definition}', rule='const')
    
    asserter({
        '$schema': 'http://json-schema.org/draft-06/schema',
        'const': const,
    }, value, expected)