diff --git a/.github/workflows/ci.yml b/.github/workflows/ci.yml index 25ea148..34bf281 100644 --- a/.github/workflows/ci.yml +++ b/.github/workflows/ci.yml @@ -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 diff --git a/src/hypothesis_jsonschema/_from_schema.py b/src/hypothesis_jsonschema/_from_schema.py index b0c596e..5fc28b8 100644 --- a/src/hypothesis_jsonschema/_from_schema.py +++ b/src/hypothesis_jsonschema/_from_schema.py @@ -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: diff --git a/tests/test_canonicalise.py b/tests/test_canonicalise.py index 6ad0bf3..1a41b70 100644 --- a/tests/test_canonicalise.py +++ b/tests/test_canonicalise.py @@ -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}, diff --git a/tests/test_from_schema.py b/tests/test_from_schema.py index a7c8707..a000d6f 100644 --- a/tests/test_from_schema.py +++ b/tests/test_from_schema.py @@ -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): @@ -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", @@ -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])