From 169217572a352453ceb2b4528e32c879a5c3fd3e Mon Sep 17 00:00:00 2001 From: Julian Berman Date: Sat, 29 Aug 2020 16:34:00 -0400 Subject: Update pre-commit hooks. --- .pre-commit-config.yaml | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-) diff --git a/.pre-commit-config.yaml b/.pre-commit-config.yaml index a1dc799..7b9e18c 100644 --- a/.pre-commit-config.yaml +++ b/.pre-commit-config.yaml @@ -14,7 +14,7 @@ repos: - id: end-of-file-fixer - id: trailing-whitespace - repo: https://github.com/timothycrosley/isort - rev: 5.3.2 + rev: 5.4.2 hooks: - id: isort - repo: https://github.com/myint/docformatter -- cgit v1.2.1 From b18ece38d73370446ebf290b0adb019331032c52 Mon Sep 17 00:00:00 2001 From: Julian Berman Date: Sat, 29 Aug 2020 16:34:40 -0400 Subject: Sigh, this appears to be a regex, not exact match, so it was ignoring everything. --- .pre-commit-config.yaml | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-) diff --git a/.pre-commit-config.yaml b/.pre-commit-config.yaml index 7b9e18c..ab72a6c 100644 --- a/.pre-commit-config.yaml +++ b/.pre-commit-config.yaml @@ -1,4 +1,4 @@ -exclude: json +exclude: json/ repos: - repo: https://github.com/pre-commit/pre-commit-hooks -- cgit v1.2.1 From ae4a8e04e0aa4f1e6a0b75252681fd1c0035521d Mon Sep 17 00:00:00 2001 From: Julian Berman Date: Sat, 29 Aug 2020 16:41:07 -0400 Subject: Minor doc formatting. --- jsonschema/_utils.py | 1 + jsonschema/tests/test_types.py | 8 +++++--- 2 files changed, 6 insertions(+), 3 deletions(-) diff --git a/jsonschema/_utils.py b/jsonschema/_utils.py index 780a22d..a320b2d 100644 --- a/jsonschema/_utils.py +++ b/jsonschema/_utils.py @@ -134,6 +134,7 @@ def types_msg(instance, types): def flatten(suitable_for_isinstance): """ isinstance() can accept a bunch of really annoying different types: + * a single type * a tuple of types * an arbitrary nested tree of tuples diff --git a/jsonschema/tests/test_types.py b/jsonschema/tests/test_types.py index 2280cc3..82071ca 100644 --- a/jsonschema/tests/test_types.py +++ b/jsonschema/tests/test_types.py @@ -1,7 +1,9 @@ """ -Tests on the new type interface. The actual correctness of the type checking -is handled in test_jsonschema_test_suite; these tests check that TypeChecker -functions correctly and can facilitate extensions to type checking +Tests for the `TypeChecker`-based type interface. + +The actual correctness of the type checking is handled in +`test_jsonschema_test_suite`; these tests check that TypeChecker +functions correctly at a more granular level. """ from collections import namedtuple from unittest import TestCase -- cgit v1.2.1 From 7ce8dd3e09ad43ce52e6fa8ea33adebec2434a65 Mon Sep 17 00:00:00 2001 From: Julian Berman Date: Sat, 29 Aug 2020 16:41:39 -0400 Subject: Remove docformatter, it's too unwieldy. Specifically for the moment, it's adding periods to the end of things that aren't sentences. I'm sure that's configurable but I don't immediately see where. --- .pre-commit-config.yaml | 8 -------- 1 file changed, 8 deletions(-) diff --git a/.pre-commit-config.yaml b/.pre-commit-config.yaml index ab72a6c..bd3e906 100644 --- a/.pre-commit-config.yaml +++ b/.pre-commit-config.yaml @@ -17,11 +17,3 @@ repos: rev: 5.4.2 hooks: - id: isort -- repo: https://github.com/myint/docformatter - rev: v1.3.1 - hooks: - - id: docformatter - args: - - --in-place - - --pre-summary-newline - - --make-summary-multi-line -- cgit v1.2.1 From 5173ea67423ac0c126bf79b6eff94bacd6384884 Mon Sep 17 00:00:00 2001 From: Julian Berman Date: Sat, 29 Aug 2020 17:17:50 -0400 Subject: Run pre-commit in CI. --- .github/workflows/pre-commit.yml | 13 +++++++++++++ 1 file changed, 13 insertions(+) create mode 100644 .github/workflows/pre-commit.yml diff --git a/.github/workflows/pre-commit.yml b/.github/workflows/pre-commit.yml new file mode 100644 index 0000000..306e1ad --- /dev/null +++ b/.github/workflows/pre-commit.yml @@ -0,0 +1,13 @@ +name: pre-commit + +on: + pull_request: + push: + +jobs: + pre-commit: + runs-on: ubuntu-latest + steps: + - uses: actions/checkout@v2 + - uses: actions/setup-python@v2 + - uses: pre-commit/action@v2.0.0 -- cgit v1.2.1 From 73ad46e62d8b952ac8bf1f47780b70824035f843 Mon Sep 17 00:00:00 2001 From: Julian Berman Date: Sun, 30 Aug 2020 10:01:00 -0400 Subject: Remove the Py2 coding declaration. --- docs/conf.py | 4 ---- 1 file changed, 4 deletions(-) diff --git a/docs/conf.py b/docs/conf.py index fbf6f30..73e0e1f 100644 --- a/docs/conf.py +++ b/docs/conf.py @@ -1,7 +1,3 @@ -# -*- coding: utf-8 -*- -# -# This file is execfile()d with the current directory set to its containing dir. - from textwrap import dedent import os import re -- cgit v1.2.1 From 0989e768d7b2f65b780860ab74d0b05c11945d28 Mon Sep 17 00:00:00 2001 From: Julian Berman Date: Sun, 30 Aug 2020 10:04:10 -0400 Subject: Bump doc requirements (via pip-compile) --- docs/requirements.txt | 20 ++++++++++---------- 1 file changed, 10 insertions(+), 10 deletions(-) diff --git a/docs/requirements.txt b/docs/requirements.txt index 11fbfe7..2b75db0 100644 --- a/docs/requirements.txt +++ b/docs/requirements.txt @@ -6,31 +6,31 @@ # alabaster==0.7.12 # via sphinx babel==2.8.0 # via sphinx -certifi==2020.4.5.1 # via requests +certifi==2020.6.20 # via requests chardet==3.0.4 # via requests docutils==0.16 # via sphinx -idna==2.9 # via requests +idna==2.10 # via requests imagesize==1.2.0 # via sphinx jinja2==2.11.2 # via sphinx -lxml==4.5.0 # via -r requirements.in +lxml==4.5.2 # via -r requirements.in markupsafe==1.1.1 # via jinja2 -packaging==20.3 # via sphinx -pyenchant==3.0.1 # via sphinxcontrib-spelling +packaging==20.4 # via sphinx +pyenchant==3.1.1 # via sphinxcontrib-spelling pygments==2.6.1 # via sphinx pyparsing==2.4.7 # via packaging pytz==2020.1 # via babel -requests==2.23.0 # via sphinx -six==1.14.0 # via packaging, sphinxcontrib-spelling +requests==2.24.0 # via sphinx +six==1.15.0 # via packaging snowballstemmer==2.0.0 # via sphinx -sphinx==3.0.3 # via -r requirements.in, sphinxcontrib-spelling +sphinx==3.2.1 # via -r requirements.in, sphinxcontrib-spelling sphinxcontrib-applehelp==1.0.2 # via sphinx sphinxcontrib-devhelp==1.0.2 # via sphinx sphinxcontrib-htmlhelp==1.0.3 # via sphinx sphinxcontrib-jsmath==1.0.1 # via sphinx sphinxcontrib-qthelp==1.0.3 # via sphinx sphinxcontrib-serializinghtml==1.1.4 # via sphinx -sphinxcontrib-spelling==5.0.0 # via -r requirements.in -urllib3==1.25.9 # via requests +sphinxcontrib-spelling==5.3.0 # via -r requirements.in +urllib3==1.25.10 # via requests # The following packages are considered to be unsafe in a requirements file: # setuptools -- cgit v1.2.1 From 3d5b174d70e1d6d59ffe3318a278289535340081 Mon Sep 17 00:00:00 2001 From: Julian Berman Date: Sun, 30 Aug 2020 10:04:46 -0400 Subject: Use the longer form of the CLI option for clarity. --- README.rst | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-) diff --git a/README.rst b/README.rst index dc89d72..b3e9fd5 100644 --- a/README.rst +++ b/README.rst @@ -51,7 +51,7 @@ It can also be used from console: .. code-block:: bash - $ jsonschema -i sample.json sample.schema + $ jsonschema --instance sample.json sample.schema Features -------- -- cgit v1.2.1 From a951fc780f43728f22082f338ec54f7eefd9f9a5 Mon Sep 17 00:00:00 2001 From: Julian Berman Date: Sun, 30 Aug 2020 10:05:15 -0400 Subject: Remove outdated release notes. --- README.rst | 9 --------- 1 file changed, 9 deletions(-) diff --git a/README.rst b/README.rst index b3e9fd5..2ad096e 100644 --- a/README.rst +++ b/README.rst @@ -80,15 +80,6 @@ Installation $ pip install jsonschema -Release Notes -------------- - -v3.1 brings support for ECMA 262 dialect regular expressions -throughout schemas, as recommended by the specification. Big -thanks to @Zac-HD for authoring support in a new `js-regex -`_ library. - - Running the Test Suite ---------------------- -- cgit v1.2.1 From 9f25fb301dd2804c3d596a1fb816332473abc6b2 Mon Sep 17 00:00:00 2001 From: Julian Berman Date: Sun, 30 Aug 2020 11:34:58 -0400 Subject: Be able to run coverage on all toxenvs. Shifts coverage into an optional CLI wrapper that's dropped in only when enabled via an environment variable. This means any toxenv can now be wrapped into a coverage run by running e.g. `tox -e py38-format-coverage` instead of `tox -e py38-format-tests`. Credits to @nedbat and @The-Compiler. --- .github/workflows/coverage.yml | 2 +- tox.ini | 33 ++++++++++++--------------------- 2 files changed, 13 insertions(+), 22 deletions(-) diff --git a/.github/workflows/coverage.yml b/.github/workflows/coverage.yml index b43b57a..446daf7 100644 --- a/.github/workflows/coverage.yml +++ b/.github/workflows/coverage.yml @@ -20,6 +20,6 @@ jobs: - name: Install tox run: python -m pip install tox - name: Collect & Upload Coverage - run: python -m tox -e codecov + run: python -m tox -e pypy3-format-coverage env: CODECOV_TOKEN: 2b38dae1-41c4-4435-a29d-79a1299e5617 diff --git a/tox.ini b/tox.ini index 3deb5a3..53a7e85 100644 --- a/tox.ini +++ b/tox.ini @@ -10,8 +10,14 @@ skipsdist = True [testenv] changedir = {envtmpdir} +passenv = CODECOV* CI setenv = JSON_SCHEMA_TEST_SUITE = {toxinidir}/json + + coverage,codecov: MAYBE_COVERAGE = coverage run -m + coverage,codecov: COVERAGE_RCFILE={toxinidir}/.coveragerc + coverage,codecov: COVERAGE_DEBUG_FILE={envtmpdir}/coverage-debug + coverage,codecov: COVERAGE_FILE={envtmpdir}/coverage-data whitelist_externals = mkdir commands = @@ -19,9 +25,14 @@ commands = format: {envpython} -m pip install '{toxinidir}[format]' format_nongpl: {envpython} -m pip install '{toxinidir}[format_nongpl]' - tests: {envpython} -m twisted.trial {posargs:jsonschema} + tests,coverage: {envpython} -m {env:MAYBE_COVERAGE:} twisted.trial {posargs:jsonschema} tests: {envpython} -m doctest {toxinidir}/README.rst + coverage: {envpython} -m coverage report --show-missing + coverage: {envpython} -m coverage html --directory={envtmpdir}/htmlcov + codecov: {envpython} -m coverage xml -o {envtmpdir}/coverage.xml + codecov: codecov --required --disable gcov --file {envtmpdir}/coverage.xml + perf: mkdir {envtmpdir}/benchmarks/ perf: {envpython} {toxinidir}/jsonschema/benchmarks/issue232.py --inherit-environ JSON_SCHEMA_TEST_SUITE --output {envtmpdir}/benchmarks/issue232.json perf: {envpython} {toxinidir}/jsonschema/benchmarks/json_schema_test_suite.py --inherit-environ JSON_SCHEMA_TEST_SUITE --output {envtmpdir}/benchmarks/json_schema_test_suite.json @@ -69,17 +80,6 @@ deps = commands = {envpython} -m flake8 {posargs} {toxinidir}/jsonschema {toxinidir}/docs -[testenv:coverage] -setenv = - {[testenv]setenv} - COVERAGE_DEBUG_FILE={envtmpdir}/coverage-debug - COVERAGE_FILE={envtmpdir}/coverage-data -commands = - {envpython} -m pip install '{toxinidir}[format]' - {envpython} -m coverage run --rcfile={toxinidir}/.coveragerc -m twisted.trial jsonschema - {envpython} -m coverage report --rcfile={toxinidir}/.coveragerc --show-missing - {envpython} -m coverage html --directory={envtmpdir}/htmlcov --rcfile={toxinidir}/.coveragerc {posargs} - [testenv:docs-html] basepython = pypy3 commands = {envpython} -m sphinx -b html {toxinidir}/docs/ {envtmpdir}/build {posargs:-a -n -q -T -W} @@ -115,12 +115,3 @@ deps = doc8 pygments pygments-github-lexers - -[testenv:codecov] -passenv = CODECOV* CI -setenv = {[testenv:coverage]setenv} -commands = - {envpython} -m pip install '{toxinidir}[format]' - {envpython} -m coverage run --rcfile={toxinidir}/.coveragerc -m twisted.trial jsonschema - {envpython} -m coverage xml -o {envtmpdir}/coverage.xml - codecov --required --disable gcov --file {envtmpdir}/coverage.xml -- cgit v1.2.1 From 702e9b4bf2e80923b0df6742dd3bf72cb9ef9ebb Mon Sep 17 00:00:00 2001 From: Julian Berman Date: Sun, 30 Aug 2020 18:19:50 -0400 Subject: Whoops, send coverage to codecov again. --- .github/workflows/coverage.yml | 2 +- tox.ini | 3 +-- 2 files changed, 2 insertions(+), 3 deletions(-) diff --git a/.github/workflows/coverage.yml b/.github/workflows/coverage.yml index 446daf7..0eae5c8 100644 --- a/.github/workflows/coverage.yml +++ b/.github/workflows/coverage.yml @@ -20,6 +20,6 @@ jobs: - name: Install tox run: python -m pip install tox - name: Collect & Upload Coverage - run: python -m tox -e pypy3-format-coverage + run: python -m tox -e pypy3-format-codecov env: CODECOV_TOKEN: 2b38dae1-41c4-4435-a29d-79a1299e5617 diff --git a/tox.ini b/tox.ini index 53a7e85..26a535f 100644 --- a/tox.ini +++ b/tox.ini @@ -25,7 +25,7 @@ commands = format: {envpython} -m pip install '{toxinidir}[format]' format_nongpl: {envpython} -m pip install '{toxinidir}[format_nongpl]' - tests,coverage: {envpython} -m {env:MAYBE_COVERAGE:} twisted.trial {posargs:jsonschema} + tests,coverage,codecov: {envpython} -m {env:MAYBE_COVERAGE:} twisted.trial {posargs:jsonschema} tests: {envpython} -m doctest {toxinidir}/README.rst coverage: {envpython} -m coverage report --show-missing @@ -37,7 +37,6 @@ commands = perf: {envpython} {toxinidir}/jsonschema/benchmarks/issue232.py --inherit-environ JSON_SCHEMA_TEST_SUITE --output {envtmpdir}/benchmarks/issue232.json perf: {envpython} {toxinidir}/jsonschema/benchmarks/json_schema_test_suite.py --inherit-environ JSON_SCHEMA_TEST_SUITE --output {envtmpdir}/benchmarks/json_schema_test_suite.json - # Check to make sure that releases build and install properly build: {envpython} -m pep517.check {toxinidir} deps = build: pep517 -- cgit v1.2.1 From 1a4ea00149e70383506f24648bfb52a2278fe3f7 Mon Sep 17 00:00:00 2001 From: Julian Berman Date: Sat, 5 Sep 2020 07:55:55 -0400 Subject: Squashed 'json/' changes from fce9e9b3..21555a85 21555a85 Merge pull request #431 from ChALkeR/chalker/enum 87550ad6 Merge pull request #433 from notEthan/escaped_ref_in_def 57e31b49 refactor tests of escaped pointer refs to put ref'd schemas in definitions a21e4258 Add tests for objects in enum 8a129948 Remove invalid format:regex test; the spec doesn't mandate parsing correctness git-subtree-dir: json git-subtree-split: 21555a8540584447a9f8ea659accd0ce79bd36e5 --- tests/draft2019-09/enum.json | 10 ++++++++++ tests/draft2019-09/optional/ecmascript-regex.json | 11 ----------- tests/draft3/ref.json | 14 ++++++++------ tests/draft4/enum.json | 10 ++++++++++ tests/draft4/optional/ecmascript-regex.json | 11 ----------- tests/draft4/ref.json | 14 ++++++++------ tests/draft6/enum.json | 10 ++++++++++ tests/draft6/optional/ecmascript-regex.json | 11 ----------- tests/draft6/ref.json | 14 ++++++++------ tests/draft7/enum.json | 10 ++++++++++ tests/draft7/optional/ecmascript-regex.json | 11 ----------- tests/draft7/ref.json | 14 ++++++++------ 12 files changed, 72 insertions(+), 68 deletions(-) diff --git a/tests/draft2019-09/enum.json b/tests/draft2019-09/enum.json index 6844578..f085097 100644 --- a/tests/draft2019-09/enum.json +++ b/tests/draft2019-09/enum.json @@ -33,6 +33,16 @@ "description": "objects are deep compared", "data": {"foo": false}, "valid": false + }, + { + "description": "valid object matches", + "data": {"foo": 12}, + "valid": true + }, + { + "description": "extra properties in object is invalid", + "data": {"foo": 12, "boo": 42}, + "valid": false } ] }, diff --git a/tests/draft2019-09/optional/ecmascript-regex.json b/tests/draft2019-09/optional/ecmascript-regex.json index b9412e0..6ed6cbe 100644 --- a/tests/draft2019-09/optional/ecmascript-regex.json +++ b/tests/draft2019-09/optional/ecmascript-regex.json @@ -1,15 +1,4 @@ [ - { - "description": "ECMA 262 regex non-compliance", - "schema": { "format": "regex" }, - "tests": [ - { - "description": "ECMA 262 has no support for \\Z anchor from .NET", - "data": "^\\S(|(.|\\n)*\\S)\\Z", - "valid": false - } - ] - }, { "description": "ECMA 262 regex $ does not match trailing newline", "schema": { diff --git a/tests/draft3/ref.json b/tests/draft3/ref.json index 74e963c..77b2947 100644 --- a/tests/draft3/ref.json +++ b/tests/draft3/ref.json @@ -75,13 +75,15 @@ { "description": "escaped pointer ref", "schema": { - "tilde~field": {"type": "integer"}, - "slash/field": {"type": "integer"}, - "percent%field": {"type": "integer"}, + "definitions": { + "tilde~field": {"type": "integer"}, + "slash/field": {"type": "integer"}, + "percent%field": {"type": "integer"} + }, "properties": { - "tilde": {"$ref": "#/tilde~0field"}, - "slash": {"$ref": "#/slash~1field"}, - "percent": {"$ref": "#/percent%25field"} + "tilde": {"$ref": "#/definitions/tilde~0field"}, + "slash": {"$ref": "#/definitions/slash~1field"}, + "percent": {"$ref": "#/definitions/percent%25field"} } }, "tests": [ diff --git a/tests/draft4/enum.json b/tests/draft4/enum.json index 6844578..f085097 100644 --- a/tests/draft4/enum.json +++ b/tests/draft4/enum.json @@ -33,6 +33,16 @@ "description": "objects are deep compared", "data": {"foo": false}, "valid": false + }, + { + "description": "valid object matches", + "data": {"foo": 12}, + "valid": true + }, + { + "description": "extra properties in object is invalid", + "data": {"foo": 12, "boo": 42}, + "valid": false } ] }, diff --git a/tests/draft4/optional/ecmascript-regex.json b/tests/draft4/optional/ecmascript-regex.json index b9412e0..6ed6cbe 100644 --- a/tests/draft4/optional/ecmascript-regex.json +++ b/tests/draft4/optional/ecmascript-regex.json @@ -1,15 +1,4 @@ [ - { - "description": "ECMA 262 regex non-compliance", - "schema": { "format": "regex" }, - "tests": [ - { - "description": "ECMA 262 has no support for \\Z anchor from .NET", - "data": "^\\S(|(.|\\n)*\\S)\\Z", - "valid": false - } - ] - }, { "description": "ECMA 262 regex $ does not match trailing newline", "schema": { diff --git a/tests/draft4/ref.json b/tests/draft4/ref.json index fc3e94b..f88e963 100644 --- a/tests/draft4/ref.json +++ b/tests/draft4/ref.json @@ -75,13 +75,15 @@ { "description": "escaped pointer ref", "schema": { - "tilde~field": {"type": "integer"}, - "slash/field": {"type": "integer"}, - "percent%field": {"type": "integer"}, + "definitions": { + "tilde~field": {"type": "integer"}, + "slash/field": {"type": "integer"}, + "percent%field": {"type": "integer"} + }, "properties": { - "tilde": {"$ref": "#/tilde~0field"}, - "slash": {"$ref": "#/slash~1field"}, - "percent": {"$ref": "#/percent%25field"} + "tilde": {"$ref": "#/definitions/tilde~0field"}, + "slash": {"$ref": "#/definitions/slash~1field"}, + "percent": {"$ref": "#/definitions/percent%25field"} } }, "tests": [ diff --git a/tests/draft6/enum.json b/tests/draft6/enum.json index 6844578..f085097 100644 --- a/tests/draft6/enum.json +++ b/tests/draft6/enum.json @@ -33,6 +33,16 @@ "description": "objects are deep compared", "data": {"foo": false}, "valid": false + }, + { + "description": "valid object matches", + "data": {"foo": 12}, + "valid": true + }, + { + "description": "extra properties in object is invalid", + "data": {"foo": 12, "boo": 42}, + "valid": false } ] }, diff --git a/tests/draft6/optional/ecmascript-regex.json b/tests/draft6/optional/ecmascript-regex.json index b9412e0..6ed6cbe 100644 --- a/tests/draft6/optional/ecmascript-regex.json +++ b/tests/draft6/optional/ecmascript-regex.json @@ -1,15 +1,4 @@ [ - { - "description": "ECMA 262 regex non-compliance", - "schema": { "format": "regex" }, - "tests": [ - { - "description": "ECMA 262 has no support for \\Z anchor from .NET", - "data": "^\\S(|(.|\\n)*\\S)\\Z", - "valid": false - } - ] - }, { "description": "ECMA 262 regex $ does not match trailing newline", "schema": { diff --git a/tests/draft6/ref.json b/tests/draft6/ref.json index 8eaba56..0138382 100644 --- a/tests/draft6/ref.json +++ b/tests/draft6/ref.json @@ -75,13 +75,15 @@ { "description": "escaped pointer ref", "schema": { - "tilde~field": {"type": "integer"}, - "slash/field": {"type": "integer"}, - "percent%field": {"type": "integer"}, + "definitions": { + "tilde~field": {"type": "integer"}, + "slash/field": {"type": "integer"}, + "percent%field": {"type": "integer"} + }, "properties": { - "tilde": {"$ref": "#/tilde~0field"}, - "slash": {"$ref": "#/slash~1field"}, - "percent": {"$ref": "#/percent%25field"} + "tilde": {"$ref": "#/definitions/tilde~0field"}, + "slash": {"$ref": "#/definitions/slash~1field"}, + "percent": {"$ref": "#/definitions/percent%25field"} } }, "tests": [ diff --git a/tests/draft7/enum.json b/tests/draft7/enum.json index 6844578..f085097 100644 --- a/tests/draft7/enum.json +++ b/tests/draft7/enum.json @@ -33,6 +33,16 @@ "description": "objects are deep compared", "data": {"foo": false}, "valid": false + }, + { + "description": "valid object matches", + "data": {"foo": 12}, + "valid": true + }, + { + "description": "extra properties in object is invalid", + "data": {"foo": 12, "boo": 42}, + "valid": false } ] }, diff --git a/tests/draft7/optional/ecmascript-regex.json b/tests/draft7/optional/ecmascript-regex.json index b9412e0..6ed6cbe 100644 --- a/tests/draft7/optional/ecmascript-regex.json +++ b/tests/draft7/optional/ecmascript-regex.json @@ -1,15 +1,4 @@ [ - { - "description": "ECMA 262 regex non-compliance", - "schema": { "format": "regex" }, - "tests": [ - { - "description": "ECMA 262 has no support for \\Z anchor from .NET", - "data": "^\\S(|(.|\\n)*\\S)\\Z", - "valid": false - } - ] - }, { "description": "ECMA 262 regex $ does not match trailing newline", "schema": { diff --git a/tests/draft7/ref.json b/tests/draft7/ref.json index 5a8602e..01ba9fa 100644 --- a/tests/draft7/ref.json +++ b/tests/draft7/ref.json @@ -75,13 +75,15 @@ { "description": "escaped pointer ref", "schema": { - "tilde~field": {"type": "integer"}, - "slash/field": {"type": "integer"}, - "percent%field": {"type": "integer"}, + "definitions": { + "tilde~field": {"type": "integer"}, + "slash/field": {"type": "integer"}, + "percent%field": {"type": "integer"} + }, "properties": { - "tilde": {"$ref": "#/tilde~0field"}, - "slash": {"$ref": "#/slash~1field"}, - "percent": {"$ref": "#/percent%25field"} + "tilde": {"$ref": "#/definitions/tilde~0field"}, + "slash": {"$ref": "#/definitions/slash~1field"}, + "percent": {"$ref": "#/definitions/percent%25field"} } }, "tests": [ -- cgit v1.2.1 From 918803aa556f4f87d6b952af316d47ecaf089164 Mon Sep 17 00:00:00 2001 From: Julian Berman Date: Sun, 4 Oct 2020 11:58:30 -0400 Subject: Squashed 'json/' changes from 21555a85..96742ba3 96742ba3 Merge pull request #438 from Zac-HD/overflow-with-multipleOf c5ba4ba3 Check for multipleOf overflow c12b0db8 Merge pull request #437 from gregsdennis/if-then-else-sequencing bd148eb7 copy/paste error 3ca7c419 Added if/then/else sequencing tests; resolves #436 fa73bc8d Merge pull request #435 from jviotti/unevaluated-items-typo 2d6de7cb Fix "unevaluted" typos in "unevaluatedItems" suite 2a9be81d Merge pull request #1 from json-schema-org/master git-subtree-dir: json git-subtree-split: 96742ba3c4a1eff6de45f0c50a66a975796b7c37 --- tests/draft2019-09/if-then-else.json | 30 +++++++++++++++++++++++++ tests/draft2019-09/multipleOf.json | 11 +++++++++ tests/draft2019-09/optional/float-overflow.json | 13 +++++++++++ tests/draft2019-09/unevaluatedItems.json | 30 ++++++++++++------------- tests/draft4/multipleOf.json | 11 +++++++++ tests/draft4/optional/float-overflow.json | 13 +++++++++++ tests/draft6/multipleOf.json | 11 +++++++++ tests/draft6/optional/float-overflow.json | 13 +++++++++++ tests/draft7/if-then-else.json | 30 +++++++++++++++++++++++++ tests/draft7/multipleOf.json | 11 +++++++++ tests/draft7/optional/float-overflow.json | 13 +++++++++++ 11 files changed, 171 insertions(+), 15 deletions(-) create mode 100644 tests/draft2019-09/optional/float-overflow.json create mode 100644 tests/draft4/optional/float-overflow.json create mode 100644 tests/draft6/optional/float-overflow.json create mode 100644 tests/draft7/optional/float-overflow.json diff --git a/tests/draft2019-09/if-then-else.json b/tests/draft2019-09/if-then-else.json index e0b873e..284e919 100644 --- a/tests/draft2019-09/if-then-else.json +++ b/tests/draft2019-09/if-then-else.json @@ -224,5 +224,35 @@ "valid": true } ] + }, + { + "description": "if appears at the end when serialized (keyword processing sequence)", + "schema": { + "then": { "const": "yes" }, + "else": { "const": "other" }, + "if": { "maxLength": 4 } + }, + "tests": [ + { + "description": "yes redirects to then and passes", + "data": "yes", + "valid": true + }, + { + "description": "other redirects to else and passes", + "data": "other", + "valid": true + }, + { + "description": "no redirects to then and fails", + "data": "no", + "valid": false + }, + { + "description": "invalid redirects to else and fails", + "data": "invalid", + "valid": false + } + ] } ] diff --git a/tests/draft2019-09/multipleOf.json b/tests/draft2019-09/multipleOf.json index ca3b761..faa87cf 100644 --- a/tests/draft2019-09/multipleOf.json +++ b/tests/draft2019-09/multipleOf.json @@ -56,5 +56,16 @@ "valid": false } ] + }, + { + "description": "invalid instance should not raise error when float division = inf", + "schema": {"type": "integer", "multipleOf": 0.123456789}, + "tests": [ + { + "description": "always invalid, but naive implementations may raise an overflow error", + "data": 1e308, + "valid": false + } + ] } ] diff --git a/tests/draft2019-09/optional/float-overflow.json b/tests/draft2019-09/optional/float-overflow.json new file mode 100644 index 0000000..52ff982 --- /dev/null +++ b/tests/draft2019-09/optional/float-overflow.json @@ -0,0 +1,13 @@ +[ + { + "description": "all integers are multiples of 0.5, if overflow is handled", + "schema": {"type": "integer", "multipleOf": 0.5}, + "tests": [ + { + "description": "valid if optional overflow handling is implemented", + "data": 1e308, + "valid": true + } + ] + } +] diff --git a/tests/draft2019-09/unevaluatedItems.json b/tests/draft2019-09/unevaluatedItems.json index 01c07be..32f13f8 100644 --- a/tests/draft2019-09/unevaluatedItems.json +++ b/tests/draft2019-09/unevaluatedItems.json @@ -87,12 +87,12 @@ }, "tests": [ { - "description": "with no unevaluted items", + "description": "with no unevaluated items", "data": ["foo"], "valid": true }, { - "description": "with unevaluted items", + "description": "with unevaluated items", "data": ["foo", "bar"], "valid": false } @@ -135,12 +135,12 @@ }, "tests": [ { - "description": "with no unevaluted items", + "description": "with no unevaluated items", "data": ["foo", 42], "valid": true }, { - "description": "with unevaluted items", + "description": "with unevaluated items", "data": ["foo", 42, true], "valid": false } @@ -228,22 +228,22 @@ }, "tests": [ { - "description": "when one schema matches and has no unevaluted items", + "description": "when one schema matches and has no unevaluated items", "data": ["foo", "bar"], "valid": true }, { - "description": "when one schema matches and has unevaluted items", + "description": "when one schema matches and has unevaluated items", "data": ["foo", "bar", 42], "valid": false }, { - "description": "when two schemas match and has no unevaluted items", + "description": "when two schemas match and has no unevaluated items", "data": ["foo", "bar", "baz"], "valid": true }, { - "description": "when two schemas match and has unevaluted items", + "description": "when two schemas match and has unevaluated items", "data": ["foo", "bar", "baz", 42], "valid": false } @@ -274,12 +274,12 @@ }, "tests": [ { - "description": "with no unevaluted items", + "description": "with no unevaluated items", "data": ["foo", "bar"], "valid": true }, { - "description": "with unevaluted items", + "description": "with unevaluated items", "data": ["foo", "bar", 42], "valid": false } @@ -304,7 +304,7 @@ }, "tests": [ { - "description": "with unevaluted items", + "description": "with unevaluated items", "data": ["foo", "bar"], "valid": false } @@ -342,22 +342,22 @@ }, "tests": [ { - "description": "when if matches and it has no unevaluted items", + "description": "when if matches and it has no unevaluated items", "data": ["foo", "bar", "then"], "valid": true }, { - "description": "when if matches and it has unevaluted items", + "description": "when if matches and it has unevaluated items", "data": ["foo", "bar", "then", "else"], "valid": false }, { - "description": "when if doesn't match and it has no unevaluted items", + "description": "when if doesn't match and it has no unevaluated items", "data": ["foo", 42, 42, "else"], "valid": true }, { - "description": "when if doesn't match and it has unevaluted items", + "description": "when if doesn't match and it has unevaluated items", "data": ["foo", 42, 42, "else", 42], "valid": false } diff --git a/tests/draft4/multipleOf.json b/tests/draft4/multipleOf.json index ca3b761..faa87cf 100644 --- a/tests/draft4/multipleOf.json +++ b/tests/draft4/multipleOf.json @@ -56,5 +56,16 @@ "valid": false } ] + }, + { + "description": "invalid instance should not raise error when float division = inf", + "schema": {"type": "integer", "multipleOf": 0.123456789}, + "tests": [ + { + "description": "always invalid, but naive implementations may raise an overflow error", + "data": 1e308, + "valid": false + } + ] } ] diff --git a/tests/draft4/optional/float-overflow.json b/tests/draft4/optional/float-overflow.json new file mode 100644 index 0000000..52ff982 --- /dev/null +++ b/tests/draft4/optional/float-overflow.json @@ -0,0 +1,13 @@ +[ + { + "description": "all integers are multiples of 0.5, if overflow is handled", + "schema": {"type": "integer", "multipleOf": 0.5}, + "tests": [ + { + "description": "valid if optional overflow handling is implemented", + "data": 1e308, + "valid": true + } + ] + } +] diff --git a/tests/draft6/multipleOf.json b/tests/draft6/multipleOf.json index ca3b761..faa87cf 100644 --- a/tests/draft6/multipleOf.json +++ b/tests/draft6/multipleOf.json @@ -56,5 +56,16 @@ "valid": false } ] + }, + { + "description": "invalid instance should not raise error when float division = inf", + "schema": {"type": "integer", "multipleOf": 0.123456789}, + "tests": [ + { + "description": "always invalid, but naive implementations may raise an overflow error", + "data": 1e308, + "valid": false + } + ] } ] diff --git a/tests/draft6/optional/float-overflow.json b/tests/draft6/optional/float-overflow.json new file mode 100644 index 0000000..52ff982 --- /dev/null +++ b/tests/draft6/optional/float-overflow.json @@ -0,0 +1,13 @@ +[ + { + "description": "all integers are multiples of 0.5, if overflow is handled", + "schema": {"type": "integer", "multipleOf": 0.5}, + "tests": [ + { + "description": "valid if optional overflow handling is implemented", + "data": 1e308, + "valid": true + } + ] + } +] diff --git a/tests/draft7/if-then-else.json b/tests/draft7/if-then-else.json index e0b873e..284e919 100644 --- a/tests/draft7/if-then-else.json +++ b/tests/draft7/if-then-else.json @@ -224,5 +224,35 @@ "valid": true } ] + }, + { + "description": "if appears at the end when serialized (keyword processing sequence)", + "schema": { + "then": { "const": "yes" }, + "else": { "const": "other" }, + "if": { "maxLength": 4 } + }, + "tests": [ + { + "description": "yes redirects to then and passes", + "data": "yes", + "valid": true + }, + { + "description": "other redirects to else and passes", + "data": "other", + "valid": true + }, + { + "description": "no redirects to then and fails", + "data": "no", + "valid": false + }, + { + "description": "invalid redirects to else and fails", + "data": "invalid", + "valid": false + } + ] } ] diff --git a/tests/draft7/multipleOf.json b/tests/draft7/multipleOf.json index ca3b761..faa87cf 100644 --- a/tests/draft7/multipleOf.json +++ b/tests/draft7/multipleOf.json @@ -56,5 +56,16 @@ "valid": false } ] + }, + { + "description": "invalid instance should not raise error when float division = inf", + "schema": {"type": "integer", "multipleOf": 0.123456789}, + "tests": [ + { + "description": "always invalid, but naive implementations may raise an overflow error", + "data": 1e308, + "valid": false + } + ] } ] diff --git a/tests/draft7/optional/float-overflow.json b/tests/draft7/optional/float-overflow.json new file mode 100644 index 0000000..52ff982 --- /dev/null +++ b/tests/draft7/optional/float-overflow.json @@ -0,0 +1,13 @@ +[ + { + "description": "all integers are multiples of 0.5, if overflow is handled", + "schema": {"type": "integer", "multipleOf": 0.5}, + "tests": [ + { + "description": "valid if optional overflow handling is implemented", + "data": 1e308, + "valid": true + } + ] + } +] -- cgit v1.2.1 From 5d10375ac562104e0d436db5054653efbfedab08 Mon Sep 17 00:00:00 2001 From: Julian Berman Date: Sun, 4 Oct 2020 12:00:01 -0400 Subject: Sigh, ugly, but assrtRegexpMatches is deprecated. --- jsonschema/tests/test_validators.py | 4 ++-- 1 file changed, 2 insertions(+), 2 deletions(-) diff --git a/jsonschema/tests/test_validators.py b/jsonschema/tests/test_validators.py index fc6a355..2f017b9 100644 --- a/jsonschema/tests/test_validators.py +++ b/jsonschema/tests/test_validators.py @@ -1561,7 +1561,7 @@ class TestValidate(SynchronousTestCase): def test_validation_error_message(self): with self.assertRaises(exceptions.ValidationError) as e: validators.validate(12, {"type": "string"}) - self.assertRegexpMatches( + self.assertRegex( str(e.exception), "(?s)Failed validating u?'.*' in schema.*On instance", ) @@ -1569,7 +1569,7 @@ class TestValidate(SynchronousTestCase): def test_schema_error_message(self): with self.assertRaises(exceptions.SchemaError) as e: validators.validate(12, {"type": 12}) - self.assertRegexpMatches( + self.assertRegex( str(e.exception), "(?s)Failed validating u?'.*' in metaschema.*On schema", ) -- cgit v1.2.1 From c985e0b0a9ac884ddeae8893f781a06c7c2cf0c1 Mon Sep 17 00:00:00 2001 From: Julian Berman Date: Sun, 4 Oct 2020 12:06:28 -0400 Subject: Temporarily skip the failing tests for #743. What can I say, we're naive... --- jsonschema/tests/test_jsonschema_test_suite.py | 39 ++++++++++++++++++++++++++ 1 file changed, 39 insertions(+) diff --git a/jsonschema/tests/test_jsonschema_test_suite.py b/jsonschema/tests/test_jsonschema_test_suite.py index 0f9698a..d6721b5 100644 --- a/jsonschema/tests/test_jsonschema_test_suite.py +++ b/jsonschema/tests/test_jsonschema_test_suite.py @@ -161,6 +161,7 @@ TestDraft4 = DRAFT4.to_unittest_testcase( DRAFT4.tests(), DRAFT4.format_tests(), DRAFT4.optional_tests_of(name="bignum"), + DRAFT4.optional_tests_of(name="float-overflow"), DRAFT4.optional_tests_of(name="non-bmp-regex"), DRAFT4.optional_tests_of(name="zeroTerminatedFloats"), Validator=Draft4Validator, @@ -234,6 +235,18 @@ TestDraft4 = DRAFT4.to_unittest_testcase( subject="uniqueItems", description='{"a": true} and {"a": 1} are unique', )(test) + or skip( + message=bug(743), + subject="float-overflow", + )(test) + or skip( + message=bug(743), + subject="multipleOf", + description=( + "always invalid, but naive implementations " + "may raise an overflow error" + ), + )(test) ), ) @@ -242,6 +255,7 @@ TestDraft6 = DRAFT6.to_unittest_testcase( DRAFT6.tests(), DRAFT6.format_tests(), DRAFT6.optional_tests_of(name="bignum"), + DRAFT6.optional_tests_of(name="float-overflow"), DRAFT6.optional_tests_of(name="non-bmp-regex"), Validator=Draft6Validator, format_checker=draft6_format_checker, @@ -334,6 +348,18 @@ TestDraft6 = DRAFT6.to_unittest_testcase( subject="const", case_description='const with {"a": true} does not match {"a": 1}', )(test) + or skip( + message=bug(743), + subject="float-overflow", + )(test) + or skip( + message=bug(743), + subject="multipleOf", + description=( + "always invalid, but naive implementations " + "may raise an overflow error" + ), + )(test) ), ) @@ -342,6 +368,7 @@ TestDraft7 = DRAFT7.to_unittest_testcase( DRAFT7.tests(), DRAFT7.format_tests(), DRAFT7.optional_tests_of(name="bignum"), + DRAFT7.optional_tests_of(name="float-overflow"), DRAFT7.optional_tests_of(name="content"), DRAFT7.optional_tests_of(name="non-bmp-regex"), Validator=Draft7Validator, @@ -457,6 +484,18 @@ TestDraft7 = DRAFT7.to_unittest_testcase( subject="const", case_description='const with {"a": true} does not match {"a": 1}', )(test) + or skip( + message=bug(743), + subject="float-overflow", + )(test) + or skip( + message=bug(743), + subject="multipleOf", + description=( + "always invalid, but naive implementations " + "may raise an overflow error" + ), + )(test) ), ) -- cgit v1.2.1 From 4b722512fe1fb97fc63c8591d5a47fcd3a69fac9 Mon Sep 17 00:00:00 2001 From: Julian Berman Date: Sun, 4 Oct 2020 12:20:50 -0400 Subject: pep517.build is dead or dying. --- .github/workflows/packaging.yml | 7 ++----- tox.ini | 8 ++++---- 2 files changed, 6 insertions(+), 9 deletions(-) diff --git a/.github/workflows/packaging.yml b/.github/workflows/packaging.yml index decf5f0..23178f7 100644 --- a/.github/workflows/packaging.yml +++ b/.github/workflows/packaging.yml @@ -20,12 +20,9 @@ jobs: with: python-version: ${{ matrix.python-version }} - name: Install dependencies - run: python -m pip install pep517 - - name: Evade 'pypa/pep517#74' - run: python -m pip install -U setuptools setuptools-scm pip wheel - if: startsWith(matrix.python-version, 'pypy') + run: python -m pip install build - name: Create packages - run: python -m pep517.build . + run: python -m build . - uses: actions/upload-artifact@master with: name: dist-${{ matrix.os }}-${{ matrix.python-version }} diff --git a/tox.ini b/tox.ini index 26a535f..33e98b0 100644 --- a/tox.ini +++ b/tox.ini @@ -37,9 +37,9 @@ commands = perf: {envpython} {toxinidir}/jsonschema/benchmarks/issue232.py --inherit-environ JSON_SCHEMA_TEST_SUITE --output {envtmpdir}/benchmarks/issue232.json perf: {envpython} {toxinidir}/jsonschema/benchmarks/json_schema_test_suite.py --inherit-environ JSON_SCHEMA_TEST_SUITE --output {envtmpdir}/benchmarks/json_schema_test_suite.json - build: {envpython} -m pep517.check {toxinidir} + build: {envpython} -m build {toxinidir} --outdir {envtmpdir}/dist deps = - build: pep517 + build: build perf: pyperf @@ -54,11 +54,11 @@ commands = {envbindir}/bandit --recursive {toxinidir}/jsonschema [testenv:readme] deps = + build docutils - pep517 twine commands = - {envpython} -m pep517.build --out-dir {envtmpdir}/dist {toxinidir} + {envpython} -m build --outdir {envtmpdir}/dist {toxinidir} {envpython} -m twine check {envtmpdir}/dist/* {envbindir}/rst2html5.py --halt=warning {toxinidir}/CHANGELOG.rst /dev/null -- cgit v1.2.1 From 58259e7a9fc1d8ef0602c06060bba4607c99bd90 Mon Sep 17 00:00:00 2001 From: Julian Berman Date: Sun, 4 Oct 2020 12:23:30 -0400 Subject: Don't fail when codecov.io flakes. --- .github/workflows/coverage.yml | 2 ++ 1 file changed, 2 insertions(+) diff --git a/.github/workflows/coverage.yml b/.github/workflows/coverage.yml index 0eae5c8..101000f 100644 --- a/.github/workflows/coverage.yml +++ b/.github/workflows/coverage.yml @@ -20,6 +20,8 @@ jobs: - name: Install tox run: python -m pip install tox - name: Collect & Upload Coverage + # codecov.io is too flaky to fail for this right now + continue-on-error: true run: python -m tox -e pypy3-format-codecov env: CODECOV_TOKEN: 2b38dae1-41c4-4435-a29d-79a1299e5617 -- cgit v1.2.1 From 46db62a373ccc3d75fefd36f97a5fa8fcafedac4 Mon Sep 17 00:00:00 2001 From: Zac-HD Date: Mon, 5 Oct 2020 10:35:10 +1100 Subject: Handle multipleOf overflow --- jsonschema/_validators.py | 14 ++++++++- jsonschema/tests/test_jsonschema_test_suite.py | 39 -------------------------- 2 files changed, 13 insertions(+), 40 deletions(-) diff --git a/jsonschema/_validators.py b/jsonschema/_validators.py index d7097ff..7e8c95a 100644 --- a/jsonschema/_validators.py +++ b/jsonschema/_validators.py @@ -1,3 +1,4 @@ +from fractions import Fraction import re from jsonschema._utils import ( @@ -166,7 +167,18 @@ def multipleOf(validator, dB, instance, schema): if isinstance(dB, float): quotient = instance / dB - failed = int(quotient) != quotient + try: + failed = int(quotient) != quotient + except OverflowError: + # When `instance` is large and `dB` is less than one, quotient can + # overflow to infinity; and then casting to int raises an error. + # + # In this case we fall back to Fraction logic, which is exact and + # cannot overflow. The performance is also acceptable: we try the + # fast all-float option first, and we know that fraction(dB) can have + # at most a few hundred digits in each part. The worst-case slowdown + # is therefore for already-slow enormous integers or Decimals. + failed = (Fraction(instance) / Fraction(dB)).denominator != 1 else: failed = instance % dB diff --git a/jsonschema/tests/test_jsonschema_test_suite.py b/jsonschema/tests/test_jsonschema_test_suite.py index d6721b5..0f9698a 100644 --- a/jsonschema/tests/test_jsonschema_test_suite.py +++ b/jsonschema/tests/test_jsonschema_test_suite.py @@ -161,7 +161,6 @@ TestDraft4 = DRAFT4.to_unittest_testcase( DRAFT4.tests(), DRAFT4.format_tests(), DRAFT4.optional_tests_of(name="bignum"), - DRAFT4.optional_tests_of(name="float-overflow"), DRAFT4.optional_tests_of(name="non-bmp-regex"), DRAFT4.optional_tests_of(name="zeroTerminatedFloats"), Validator=Draft4Validator, @@ -235,18 +234,6 @@ TestDraft4 = DRAFT4.to_unittest_testcase( subject="uniqueItems", description='{"a": true} and {"a": 1} are unique', )(test) - or skip( - message=bug(743), - subject="float-overflow", - )(test) - or skip( - message=bug(743), - subject="multipleOf", - description=( - "always invalid, but naive implementations " - "may raise an overflow error" - ), - )(test) ), ) @@ -255,7 +242,6 @@ TestDraft6 = DRAFT6.to_unittest_testcase( DRAFT6.tests(), DRAFT6.format_tests(), DRAFT6.optional_tests_of(name="bignum"), - DRAFT6.optional_tests_of(name="float-overflow"), DRAFT6.optional_tests_of(name="non-bmp-regex"), Validator=Draft6Validator, format_checker=draft6_format_checker, @@ -348,18 +334,6 @@ TestDraft6 = DRAFT6.to_unittest_testcase( subject="const", case_description='const with {"a": true} does not match {"a": 1}', )(test) - or skip( - message=bug(743), - subject="float-overflow", - )(test) - or skip( - message=bug(743), - subject="multipleOf", - description=( - "always invalid, but naive implementations " - "may raise an overflow error" - ), - )(test) ), ) @@ -368,7 +342,6 @@ TestDraft7 = DRAFT7.to_unittest_testcase( DRAFT7.tests(), DRAFT7.format_tests(), DRAFT7.optional_tests_of(name="bignum"), - DRAFT7.optional_tests_of(name="float-overflow"), DRAFT7.optional_tests_of(name="content"), DRAFT7.optional_tests_of(name="non-bmp-regex"), Validator=Draft7Validator, @@ -484,18 +457,6 @@ TestDraft7 = DRAFT7.to_unittest_testcase( subject="const", case_description='const with {"a": true} does not match {"a": 1}', )(test) - or skip( - message=bug(743), - subject="float-overflow", - )(test) - or skip( - message=bug(743), - subject="multipleOf", - description=( - "always invalid, but naive implementations " - "may raise an overflow error" - ), - )(test) ), ) -- cgit v1.2.1