Skip to content

Commit

Permalink
Fix more tests
Browse files Browse the repository at this point in the history
  • Loading branch information
dmontagu committed Aug 14, 2023
1 parent a3aaa48 commit fd1746c
Show file tree
Hide file tree
Showing 6 changed files with 24 additions and 16 deletions.
4 changes: 2 additions & 2 deletions tests/test_typing.py
Expand Up @@ -73,9 +73,9 @@ def test_schema_typing() -> None:
SchemaValidator(schema)
schema: CoreSchema = {'type': 'set', 'items_schema': {'type': 'str'}, 'max_length': 3}
SchemaValidator(schema)
schema: CoreSchema = {'type': 'tuple-variable', 'items_schema': {'type': 'str'}, 'max_length': 3}
schema: CoreSchema = {'type': 'tuple', 'items_schema': [{'type': 'str'}], 'variadic_item_index': 0, 'max_length': 3}
SchemaValidator(schema)
schema: CoreSchema = {'type': 'tuple-positional', 'items_schema': [{'type': 'str'}, {'type': 'int'}]}
schema: CoreSchema = {'type': 'tuple', 'items_schema': [{'type': 'str'}, {'type': 'int'}]}
SchemaValidator(schema)
schema: CoreSchema = {'type': 'frozenset', 'items_schema': {'type': 'str'}, 'max_length': 3}
SchemaValidator(schema)
Expand Down
6 changes: 3 additions & 3 deletions tests/validators/test_definitions_recursive.py
Expand Up @@ -317,7 +317,7 @@ def test_outside_parent():
'tuple1': {
'type': 'typed-dict-field',
'schema': {
'type': 'tuple-positional',
'type': 'tuple',
'items_schema': [{'type': 'int'}, {'type': 'int'}, {'type': 'str'}],
'ref': 'tuple-iis',
},
Expand Down Expand Up @@ -454,7 +454,7 @@ def multiple_tuple_schema() -> SchemaValidator:
'f1': {
'type': 'typed-dict-field',
'schema': {
'type': 'tuple-positional',
'type': 'tuple',
'items_schema': [
{'type': 'int'},
{'type': 'nullable', 'schema': {'type': 'definition-ref', 'schema_ref': 't'}},
Expand Down Expand Up @@ -559,7 +559,7 @@ def wrap_func(input_value, validator, info):
'ref': 'wrapper',
'function': {'type': 'general', 'function': wrap_func},
'schema': {
'type': 'tuple-positional',
'type': 'tuple',
'items_schema': [
{'type': 'int'},
{'type': 'nullable', 'schema': {'type': 'definition-ref', 'schema_ref': 'wrapper'}},
Expand Down
4 changes: 2 additions & 2 deletions tests/validators/test_frozenset.py
Expand Up @@ -276,13 +276,13 @@ def gen(error: bool):
[
pytest.param(
{1: 10, 2: 20, '3': '30'}.items(),
{'type': 'tuple-variable', 'items_schema': {'type': 'any'}},
{'type': 'tuple', 'items_schema': [{'type': 'any'}], 'variadic_item_index': 0},
frozenset(((1, 10), (2, 20), ('3', '30'))),
id='Tuple[Any, Any]',
),
pytest.param(
{1: 10, 2: 20, '3': '30'}.items(),
{'type': 'tuple-variable', 'items_schema': {'type': 'int'}},
{'type': 'tuple', 'items_schema': [{'type': 'int'}], 'variadic_item_index': 0},
frozenset(((1, 10), (2, 20), (3, 30))),
id='Tuple[int, int]',
),
Expand Down
4 changes: 2 additions & 2 deletions tests/validators/test_list.py
Expand Up @@ -306,13 +306,13 @@ def gen(error: bool):
[
pytest.param(
{1: 10, 2: 20, '3': '30'}.items(),
{'type': 'tuple-variable', 'items_schema': {'type': 'any'}},
{'type': 'tuple', 'items_schema': [{'type': 'any'}], 'variadic_item_index': 0},
[(1, 10), (2, 20), ('3', '30')],
id='Tuple[Any, Any]',
),
pytest.param(
{1: 10, 2: 20, '3': '30'}.items(),
{'type': 'tuple-variable', 'items_schema': {'type': 'int'}},
{'type': 'tuple', 'items_schema': [{'type': 'int'}], 'variadic_item_index': 0},
[(1, 10), (2, 20), (3, 30)],
id='Tuple[int, int]',
),
Expand Down
4 changes: 2 additions & 2 deletions tests/validators/test_set.py
Expand Up @@ -242,13 +242,13 @@ def gen(error: bool):
[
pytest.param(
{1: 10, 2: 20, '3': '30'}.items(),
{'type': 'tuple-variable', 'items_schema': {'type': 'any'}},
{'type': 'tuple', 'items_schema': [{'type': 'any'}], 'variadic_item_index': 0},
{(1, 10), (2, 20), ('3', '30')},
id='Tuple[Any, Any]',
),
pytest.param(
{1: 10, 2: 20, '3': '30'}.items(),
{'type': 'tuple-variable', 'items_schema': {'type': 'int'}},
{'type': 'tuple', 'items_schema': [{'type': 'int'}], 'variadic_item_index': 0},
{(1, 10), (2, 20), (3, 30)},
id='Tuple[int, int]',
),
Expand Down
18 changes: 13 additions & 5 deletions tests/validators/test_with_default.py
Expand Up @@ -164,7 +164,11 @@ def test_dict_keys():

def test_tuple_variable(py_and_json: PyAndJson):
v = py_and_json(
{'type': 'tuple-variable', 'items_schema': {'type': 'default', 'schema': {'type': 'int'}, 'on_error': 'omit'}}
{
'type': 'tuple',
'items_schema': [{'type': 'default', 'schema': {'type': 'int'}, 'on_error': 'omit'}],
'variadic_item_index': 0,
}
)
assert v.validate_python((1, 2, 3)) == (1, 2, 3)
assert v.validate_python([1, '2', 3]) == (1, 2, 3)
Expand All @@ -174,7 +178,7 @@ def test_tuple_variable(py_and_json: PyAndJson):
def test_tuple_positional():
v = SchemaValidator(
{
'type': 'tuple-positional',
'type': 'tuple',
'items_schema': [{'type': 'int'}, {'type': 'default', 'schema': {'type': 'int'}, 'default': 42}],
}
)
Expand All @@ -187,9 +191,13 @@ def test_tuple_positional():
def test_tuple_positional_omit():
v = SchemaValidator(
{
'type': 'tuple-positional',
'items_schema': [{'type': 'int'}, {'type': 'int'}],
'extra_schema': {'type': 'default', 'schema': {'type': 'int'}, 'on_error': 'omit'},
'type': 'tuple',
'items_schema': [
{'type': 'int'},
{'type': 'int'},
{'type': 'default', 'schema': {'type': 'int'}, 'on_error': 'omit'},
],
'variadic_item_index': 2,
}
)
assert v.validate_python((1, '2')) == (1, 2)
Expand Down

0 comments on commit fd1746c

Please sign in to comment.