Skip to content

Commit

Permalink
Check fast-tests coverage
Browse files Browse the repository at this point in the history
And speed up CI by splitting the work further
  • Loading branch information
Zac-HD committed Dec 15, 2021
1 parent 466c013 commit 8071952
Show file tree
Hide file tree
Showing 4 changed files with 49 additions and 7 deletions.
24 changes: 23 additions & 1 deletion .github/workflows/ci.yml
Original file line number Diff line number Diff line change
Expand Up @@ -38,7 +38,29 @@ jobs:
run: python -m pip install --upgrade pip setuptools tox
- name: Run tests
# Disable coverage on PyPy
run: python -m tox --recreate -e test $(${{ startsWith(matrix.python-version, 'pypy') }} && echo '-- -n auto --no-cov')
run: |
python -m tox --recreate -e test \
-- -n auto --durations=10 -k "not test_can_generate_for_real_large_schema" \
$(${{ startsWith(matrix.python-version, 'pypy') }} && echo '--no-cov')
test-slow:
runs-on: ubuntu-latest
strategy:
matrix:
python-version: ["3.7", "3.8", "3.9", "3.10", "pypy-3.7", "pypy-3.8"]
fail-fast: false
steps:
- uses: actions/checkout@v2
- name: Set up Python ${{ matrix.python-version }}
uses: actions/setup-python@v2
with:
python-version: ${{ matrix.python-version }}
- name: Install dependencies
run: python -m pip install --upgrade pip setuptools tox
- name: Run slow tests
run: |
python -m tox --recreate -e test \
-- -n auto --durations=10 --no-cov -k test_can_generate_for_real_large_schema
release:
runs-on: ubuntu-latest
Expand Down
6 changes: 3 additions & 3 deletions src/hypothesis_jsonschema/_from_schema.py
Original file line number Diff line number Diff line change
Expand Up @@ -155,13 +155,13 @@ def __from_schema(
return st.nothing()
if schema == TRUTHY:
return JSON_STRATEGY
assert isinstance(schema, dict)
if schema.get("$schema") == "http://json-schema.org/draft-03/schema#":
raise InvalidArgument("Draft-03 schemas are not supported")
# Only check if declared, lest we error on inner non-latest-draft schemata.
if "$schema" in schema:
jsonschema.validators.validator_for(schema).check_schema(schema)
if schema["$schema"] == "http://json-schema.org/draft-03/schema#":
raise InvalidArgument("Draft-03 schemas are not supported")

assert isinstance(schema, dict)
# Now we handle as many validation keywords as we can...
# Applying subschemata with boolean logic
if "not" in schema:
Expand Down
4 changes: 4 additions & 0 deletions tests/test_canonicalise.py
Original file line number Diff line number Diff line change
Expand Up @@ -157,6 +157,10 @@ def test_canonicalises_to_empty(schema):
({"type": "integer", "multipleOf": 1 / 32}, {"type": "integer"}),
({"type": "number", "multipleOf": 1.0}, {"type": "integer"}),
({"type": "number", "multipleOf": -3.0}, {"type": "integer", "multipleOf": 3}),
(
{"type": "number", "multipleOf": 0.75, "not": {"multipleOf": 1.25}},
{"type": "number", "multipleOf": 0.75, "not": {"multipleOf": 1.25}},
),
(
{"type": "array", "items": [True, False, True]},
{"type": "array", "items": [{}], "maxItems": 1},
Expand Down
22 changes: 19 additions & 3 deletions tests/test_from_schema.py
Original file line number Diff line number Diff line change
Expand Up @@ -66,6 +66,11 @@ def test_boolean_true_is_valid_schema_and_resolvable(_):
{"type": "an unknown type"},
{"allOf": [{"type": "boolean"}, {"const": None}]},
{"allOf": [{"type": "boolean"}, {"enum": [None]}]},
{
"$schema": "http://json-schema.org/draft-07/schema#",
"maximum": 10,
"exclusiveMaximum": True,
},
],
)
def test_invalid_schemas_raise(schema):
Expand All @@ -88,6 +93,19 @@ def test_invalid_regex_emit_warning(schema):
from_schema(schema).validate()


@given(
from_schema(
{
"$schema": "http://json-schema.org/draft-04/schema#",
"maximum": 10,
"exclusiveMaximum": True,
}
)
)
def test_can_generate_with_explicit_schema_version(_):
pass


INVALID_SCHEMAS = {
# Empty list for requires, which is invalid
"Release Drafter configuration file",
Expand Down Expand Up @@ -205,10 +223,8 @@ def to_name_params(corpus):
continue
if n in UNSUPPORTED_SCHEMAS:
continue
elif n in SLOW_SCHEMAS:
elif n in SLOW_SCHEMAS | FLAKY_SCHEMAS:
yield pytest.param(n, marks=pytest.mark.skip)
elif n in FLAKY_SCHEMAS:
yield pytest.param(n, marks=pytest.mark.xfail(strict=False))
else:
if isinstance(corpus[n], dict) and "$schema" in corpus[n]:
jsonschema.validators.validator_for(corpus[n]).check_schema(corpus[n])
Expand Down

0 comments on commit 8071952

Please sign in to comment.