Example #1
0
def test_json_schema_and_merge_not():
    s = And(Not(int), Not(str))
    assert s.json_schema() == {'not': {'anyOf': [
        {'type': 'integer'},
        {'type': 'string'},
    ]}}
    s = And(str, Not('test'))
    assert s.json_schema() == {
        'allOf': [
            {'type': 'string'},
        ],
        'not': {'enum': ['test']},
    }
Example #2
0
def test_json_schema_and_merge_type():
    s = And(str, Regex(r'^\w+$'))
    assert s.json_schema() == {'type': 'string', 'regex': r'^\w+$'}
    s = And(int, Regex(r'^\w+$'))
    assert s.json_schema() == {'allOf': [
        {'type': 'string', 'regex': r'^\w+$'},
        {'type': 'integer'},
    ]}
    s = And(Regex(r'^.{5,10}$'), Regex(r'^\w+$'))
    assert s.json_schema() == {'allOf': [
        {'type': 'string', 'regex': r'^.{5,10}$'},
        {'type': 'string', 'regex': r'^\w+$'},
    ]}
Example #3
0
def test_json_schema_and_merge_and():
    s = And(
        And(
            And(
                Schema(None, json_schema={'a': 'b'}),
                Schema(None, json_schema={'c': 'd'}),
            ),
            Schema(None, json_schema={'e': 'f'})
        )
    )
    assert s.json_schema() == {'allOf': [{'a': 'b'}, {'c': 'd'}, {'e': 'f'}]}
Example #4
0
def test_json_schema_and_simplify():
    s = And('test')
    assert s.json_schema() == {'enum': ['test']}