Skip to content

Commit

Permalink
Merge remote-tracking branch 'upstream/master' into max_dict_nesting
Browse files Browse the repository at this point in the history
merge branch master into max_dict_nesting
  • Loading branch information
shafiq-muhammad committed Mar 6, 2024
2 parents 39a8359 + 5214606 commit db0a963
Show file tree
Hide file tree
Showing 7 changed files with 44 additions and 16 deletions.
2 changes: 1 addition & 1 deletion setup.py
Original file line number Diff line number Diff line change
Expand Up @@ -14,7 +14,7 @@
zip_safe=False,
include_package_data=True,
install_requires=[
"jsonschema[format]>=3.2.0",
"jsonschema[format]>=4.21.0",
"python-slugify",
],
extras_require={
Expand Down
2 changes: 1 addition & 1 deletion spidermon/contrib/pytest/plugins/filter_monitors.py
Original file line number Diff line number Diff line change
Expand Up @@ -7,7 +7,7 @@ def pytest_report_header(config):
return "Spidermon monitor filtering"


@pytest.mark.trylast
@pytest.hookimpl(trylast=True)
def pytest_collection_modifyitems(session, config, items):
items[:] = [
item
Expand Down
1 change: 1 addition & 0 deletions spidermon/contrib/validation/jsonschema/translator.py
Original file line number Diff line number Diff line change
Expand Up @@ -38,6 +38,7 @@ class JSONSchemaMessageTranslator(MessageTranslator):
r"^.* is not allowed for .*$": messages.NOT_ALLOWED_VALUE,
r"^.+ is too short$": messages.FIELD_TOO_SHORT,
r"^.+ is too long$": messages.FIELD_TOO_LONG,
r"^.+ should be non-empty$": messages.SHOULD_BE_NON_EMPTY,
r"^.+ does not match .*$": messages.REGEX_NOT_MATCHED,
r"^.+ has non-unique elements$": messages.NOT_UNIQUE,
}
1 change: 1 addition & 0 deletions spidermon/contrib/validation/messages.py
Original file line number Diff line number Diff line change
Expand Up @@ -44,3 +44,4 @@
NOT_MULTIPLE_OF = "Not multiple of"
NOT_ALLOWED_VALUE = "Not allowed value"
NOT_UNIQUE = "Not unique"
SHOULD_BE_NON_EMPTY = "should be non-empty"
8 changes: 4 additions & 4 deletions tests/contrib/scrapy/test_pipelines.py
Original file line number Diff line number Diff line change
Expand Up @@ -88,7 +88,7 @@ class PipelineJSONSchemaValidator(PipelineTest):
settings={SETTING_SCHEMAS: [test_schema]},
cases=[
f"'{STATS_ITEM_ERRORS}' not in {{stats}}",
f"{{stats}}['{STATS_AMOUNTS}'] is 1",
f"{{stats}}['{STATS_AMOUNTS}'] == 1",
assert_type_in_stats(Item),
],
),
Expand Down Expand Up @@ -183,8 +183,8 @@ class PipelineJSONSchemaValidator(PipelineTest):
item=TestItem(),
settings={SETTING_SCHEMAS: {TestItem: [test_schema, tree_schema]}},
cases=[
f"{{stats}}['{STATS_AMOUNTS}'] is 2",
f"{{stats}}['{STATS_ITEM_ERRORS}'] is 2",
f"{{stats}}['{STATS_AMOUNTS}'] == 2",
f"{{stats}}['{STATS_ITEM_ERRORS}'] == 2",
],
),
DataTest(
Expand All @@ -198,7 +198,7 @@ class PipelineJSONSchemaValidator(PipelineTest):
item=TreeItem(),
settings={SETTING_SCHEMAS: {TestItem: test_schema, TreeItem: tree_schema}},
cases=[
f"{{stats}}['{STATS_MISSINGS}'] is 1",
f"{{stats}}['{STATS_MISSINGS}'] == 1",
assert_type_in_stats(TestItem),
assert_type_in_stats(TreeItem),
],
Expand Down
42 changes: 34 additions & 8 deletions tests/test_validators_jsonschema.py
Original file line number Diff line number Diff line change
Expand Up @@ -907,35 +907,61 @@ class Maximum(SchemaTest):


class MinItems(SchemaTest):
schema = {"minItems": 1}
schema = {"minItems": 2}
data_tests = [
DataTest(name="longer is valid", data=[1, 2], valid=True),
DataTest(name="exact length is valid", data=[1], valid=True),
DataTest(name="longer is valid", data=[1, 2, 3], valid=True),
DataTest(name="exact length is valid", data=[1, 2], valid=True),
DataTest(
name="too short is invalid",
data=[],
data=[1],
valid=False,
expected_errors={"": [messages.FIELD_TOO_SHORT]},
),
DataTest(name="ignores non-arrays", data="", valid=True),
]


class EmptyItems(SchemaTest):
schema = {"minItems": 1}
data_tests = [
DataTest(
name="empty is invalid",
data=list(),
valid=False,
expected_errors={"": [messages.SHOULD_BE_NON_EMPTY]},
)
]


class MinProperties(SchemaTest):
schema = {"minProperties": 1}
schema = {"minProperties": 2}
data_tests = [
DataTest(name="longer is valid", data={"foo": 1, "bar": 2}, valid=True),
DataTest(name="exact length is valid", data={"foo": 1}, valid=True),
DataTest(
name="longer is valid", data={"foo": 1, "bar": 2, "foobar": 3}, valid=True
),
DataTest(name="exact length is valid", data={"foo": 1, "bar": 2}, valid=True),
DataTest(
name="too short is invalid",
data={},
data={"foo": 1},
valid=False,
expected_errors={"": [messages.NOT_ENOUGH_PROPERTIES]},
),
DataTest(name="ignores non-objects", data="", valid=True),
]


class EmptyProperties(SchemaTest):
schema = {"minProperties": 1}
data_tests = [
DataTest(
name="empty is invalid",
data=dict(),
valid=False,
expected_errors={"": [messages.SHOULD_BE_NON_EMPTY]},
)
]


class Minimum(SchemaTest):
# exclusiveMinimum behaviour changed from draft-04 to draft-06
# http://json-schema.org/draft-06/json-schema-release-notes.html#backwards-incompatible-changes
Expand Down
4 changes: 2 additions & 2 deletions tox.ini
Original file line number Diff line number Diff line change
Expand Up @@ -22,10 +22,10 @@ commands = pytest -s --ignore=./tests/contrib --ignore=./tests/utils/test_zyte.p
basepython = python3.8
deps =
{[testenv]deps}
jsonschema[format]==3.2.0
jsonschema[format]==4.21.0

[testenv:docs]
deps =
deps =
-r {toxinidir}/docs/requirements-docs.txt
changedir = docs
commands =
Expand Down

0 comments on commit db0a963

Please sign in to comment.