From 3b5f927e981576567018146a574e82bcc3a1947a Mon Sep 17 00:00:00 2001 From: willson-chen Date: Fri, 7 Aug 2020 11:04:31 +0800 Subject: [PATCH 01/35] fix bug about hostname by import fqdn --- docs/requirements.txt | 1 + jsonschema/_format.py | 12 ++--------- .../tests/test_jsonschema_test_suite.py | 20 ------------------- setup.cfg | 2 ++ 4 files changed, 5 insertions(+), 30 deletions(-) diff --git a/docs/requirements.txt b/docs/requirements.txt index 11fbfe7c5..442c04e06 100644 --- a/docs/requirements.txt +++ b/docs/requirements.txt @@ -31,6 +31,7 @@ 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 +fqdn==1.4.0 # via requests # The following packages are considered to be unsafe in a requirements file: # setuptools diff --git a/jsonschema/_format.py b/jsonschema/_format.py index 3c1e6fec8..691055e38 100644 --- a/jsonschema/_format.py +++ b/jsonschema/_format.py @@ -4,6 +4,7 @@ import struct from jsonschema.exceptions import FormatError +from fqdn import FQDN class FormatChecker(object): @@ -209,9 +210,6 @@ def is_ipv6(instance): return socket.inet_pton(socket.AF_INET6, instance) -_host_name_re = re.compile(r"^[A-Za-z0-9][A-Za-z0-9\.\-]{1,255}$") - - @_checks_drafts( draft3="host-name", draft4="hostname", @@ -221,13 +219,7 @@ def is_ipv6(instance): def is_host_name(instance): if not isinstance(instance, str): return True - if not _host_name_re.match(instance): - return False - components = instance.split(".") - for component in components: - if len(component) > 63: - return False - return True + return FQDN(instance).is_valid try: diff --git a/jsonschema/tests/test_jsonschema_test_suite.py b/jsonschema/tests/test_jsonschema_test_suite.py index e561f3e2b..f87c0f686 100644 --- a/jsonschema/tests/test_jsonschema_test_suite.py +++ b/jsonschema/tests/test_jsonschema_test_suite.py @@ -105,11 +105,6 @@ def narrow_unicode_build(test): # pragma: no cover subject="date-time", description="case-insensitive T and Z", )(test) - or skip( - message=bug(), - subject="host-name", - description="ends with hyphen", - )(test) or skip( message=bug(686), subject="uniqueItems", @@ -180,11 +175,6 @@ def narrow_unicode_build(test): # pragma: no cover subject="date-time", description="case-insensitive T and Z", )(test) - or skip( - message=bug(), - subject="hostname", - description="ends with hyphen", - )(test) or skip( message=bug(686), subject="uniqueItems", @@ -254,11 +244,6 @@ def narrow_unicode_build(test): # pragma: no cover subject="date-time", description="case-insensitive T and Z", )(test) - or skip( - message=bug(), - subject="hostname", - description="ends with hyphen", - )(test) or skip( message=bug(686), subject="uniqueItems", @@ -329,11 +314,6 @@ def narrow_unicode_build(test): # pragma: no cover subject="date-time", description="case-insensitive T and Z", )(test) - or skip( - message=bug(), - subject="hostname", - description="ends with hyphen", - )(test) or skip( message=bug(593), subject="content", diff --git a/setup.cfg b/setup.cfg index 4b6174830..d1219912b 100644 --- a/setup.cfg +++ b/setup.cfg @@ -37,12 +37,14 @@ format = rfc3987 strict-rfc3339 webcolors + fqdn format_nongpl = idna jsonpointer>1.13 webcolors rfc3986-validator>0.1.0 rfc3339-validator + fqdn [options.entry_points] console_scripts = From 9366c824d0709599072a48fb79a0eb546a125c73 Mon Sep 17 00:00:00 2001 From: wilson chen Date: Sat, 8 Aug 2020 09:27:20 +0800 Subject: [PATCH 02/35] Modify the code based on review comments --- docs/requirements.txt | 2 +- jsonschema/_format.py | 3 ++- setup.cfg | 4 ++-- 3 files changed, 5 insertions(+), 4 deletions(-) diff --git a/docs/requirements.txt b/docs/requirements.txt index 442c04e06..a4e21dc28 100644 --- a/docs/requirements.txt +++ b/docs/requirements.txt @@ -9,6 +9,7 @@ babel==2.8.0 # via sphinx certifi==2020.4.5.1 # via requests chardet==3.0.4 # via requests docutils==0.16 # via sphinx +fqdn==1.4.0 # via requests idna==2.9 # via requests imagesize==1.2.0 # via sphinx jinja2==2.11.2 # via sphinx @@ -31,7 +32,6 @@ 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 -fqdn==1.4.0 # via requests # The following packages are considered to be unsafe in a requirements file: # setuptools diff --git a/jsonschema/_format.py b/jsonschema/_format.py index 691055e38..36bacab00 100644 --- a/jsonschema/_format.py +++ b/jsonschema/_format.py @@ -3,9 +3,10 @@ import socket import struct -from jsonschema.exceptions import FormatError from fqdn import FQDN +from jsonschema.exceptions import FormatError + class FormatChecker(object): """ diff --git a/setup.cfg b/setup.cfg index d1219912b..6464c6ea4 100644 --- a/setup.cfg +++ b/setup.cfg @@ -32,19 +32,19 @@ install_requires = [options.extras_require] format = + fqdn idna jsonpointer>1.13 rfc3987 strict-rfc3339 webcolors - fqdn format_nongpl = + fqdn idna jsonpointer>1.13 webcolors rfc3986-validator>0.1.0 rfc3339-validator - fqdn [options.entry_points] console_scripts = From e2c42f1b71868f8fcf88890cdee946e80fc422ea Mon Sep 17 00:00:00 2001 From: willson-chen Date: Mon, 10 Aug 2020 10:20:02 +0800 Subject: [PATCH 03/35] regenerated the requirements.txt --- docs/requirements.in | 1 + docs/requirements.txt | 4 +++- 2 files changed, 4 insertions(+), 1 deletion(-) diff --git a/docs/requirements.in b/docs/requirements.in index 0c4f8bca5..d280be979 100644 --- a/docs/requirements.in +++ b/docs/requirements.in @@ -1,3 +1,4 @@ +fqdn lxml sphinx sphinxcontrib-spelling diff --git a/docs/requirements.txt b/docs/requirements.txt index a4e21dc28..7e2e0ff61 100644 --- a/docs/requirements.txt +++ b/docs/requirements.txt @@ -6,10 +6,12 @@ # alabaster==0.7.12 # via sphinx babel==2.8.0 # via sphinx +cached-property==1.5.1 # via fqdn certifi==2020.4.5.1 # via requests chardet==3.0.4 # via requests +colorama==0.4.3 # via sphinx docutils==0.16 # via sphinx -fqdn==1.4.0 # via requests +fqdn==1.4.0 # via -r requirements.in idna==2.9 # via requests imagesize==1.2.0 # via sphinx jinja2==2.11.2 # via sphinx From 8a979cc30b3293096f67ffd155e033e857867a06 Mon Sep 17 00:00:00 2001 From: Julian Berman Date: Wed, 12 Aug 2020 16:52:47 -0400 Subject: [PATCH 04/35] Pick a format checker that has no external dep now that fqdn exists. --- docs/validate.rst | 6 +++--- 1 file changed, 3 insertions(+), 3 deletions(-) diff --git a/docs/validate.rst b/docs/validate.rst index 3489f20f4..dc4601797 100644 --- a/docs/validate.rst +++ b/docs/validate.rst @@ -277,15 +277,15 @@ validation can be enabled by hooking in a format-checking object into an .. doctest:: - >>> validate("localhost", {"format" : "hostname"}) + >>> validate("127.0.0.1", {"format" : "ipv4"}) >>> validate( ... instance="-12", - ... schema={"format" : "hostname"}, + ... schema={"format" : "ipv4"}, ... format_checker=draft7_format_checker, ... ) Traceback (most recent call last): ... - ValidationError: "-12" is not a "hostname" + ValidationError: "-12" is not a "ipv4" .. autoclass:: FormatChecker :members: From a646912c896e59ed0b7edc4a08132caa27127e1d Mon Sep 17 00:00:00 2001 From: Julian Berman Date: Wed, 12 Aug 2020 16:53:03 -0400 Subject: [PATCH 05/35] Run CI against all setuptools extras separately. --- .github/workflows/ci.yml | 104 +++++++++++++++++++++++++++++++-------- tox.ini | 11 +++-- 2 files changed, 90 insertions(+), 25 deletions(-) diff --git a/.github/workflows/ci.yml b/.github/workflows/ci.yml index e0cc77f83..e36c151f8 100644 --- a/.github/workflows/ci.yml +++ b/.github/workflows/ci.yml @@ -18,11 +18,17 @@ jobs: os: [macos-latest, ubuntu-latest, windows-latest] python-version: - name: pypy3 - toxenv: pypy3-build + toxenv: pypy3-noextra-build - name: pypy3 - toxenv: pypy3-tests + toxenv: pypy3-noextra-tests - name: pypy3 - toxenv: pypy3-tests_nongpl + toxenv: pypy3-format-build + - name: pypy3 + toxenv: pypy3-format-tests + - name: pypy3 + toxenv: pypy3-format_nongpl-build + - name: pypy3 + toxenv: pypy3-format_nongpl-tests - name: pypy3 toxenv: demo - name: pypy3 @@ -44,36 +50,66 @@ jobs: - name: pypy3 toxenv: docs-style - name: 3.6 - toxenv: py36-build + toxenv: py36-noextra-build + - name: 3.6 + toxenv: py36-noextra-tests + - name: 3.6 + toxenv: py36-format-build + - name: 3.6 + toxenv: py36-format-tests - name: 3.6 - toxenv: py36-tests + toxenv: py36-format_nongpl-build - name: 3.6 - toxenv: py36-tests_nongpl + toxenv: py36-format_nongpl-tests - name: 3.7 - toxenv: py37-build + toxenv: py37-noextra-build - name: 3.7 - toxenv: py37-tests + toxenv: py37-noextra-tests - name: 3.7 - toxenv: py37-tests_nongpl + toxenv: py37-format-build + - name: 3.7 + toxenv: py37-format-tests + - name: 3.7 + toxenv: py37-format_nongpl-build + - name: 3.7 + toxenv: py37-format_nongpl-tests + - name: 3.8 + toxenv: py38-noextra-build + - name: 3.8 + toxenv: py38-noextra-tests - name: 3.8 - toxenv: py38-build + toxenv: py38-format-build - name: 3.8 - toxenv: py38-tests + toxenv: py38-format-tests - name: 3.8 - toxenv: py38-tests_nongpl + toxenv: py38-format_nongpl-build + - name: 3.8 + toxenv: py38-format_nongpl-tests exclude: - os: windows-latest python-version: name: pypy3 - toxenv: pypy3-build + toxenv: pypy3-noextra-build + - os: windows-latest + python-version: + name: pypy3 + toxenv: pypy3-format-build + - os: windows-latest + python-version: + name: pypy3 + toxenv: pypy3-format_nongpl-build + - os: windows-latest + python-version: + name: pypy3 + toxenv: pypy3-noextra-tests - os: windows-latest python-version: name: pypy3 - toxenv: pypy3-tests + toxenv: pypy3-format-tests - os: windows-latest python-version: name: pypy3 - toxenv: pypy3-tests_nongpl + toxenv: pypy3-format_nongpl-tests - os: windows-latest python-version: name: pypy3 @@ -89,23 +125,51 @@ jobs: - os: windows-latest python-version: name: 3.6 - toxenv: py36-tests + toxenv: py36-noextra-build - os: windows-latest python-version: name: 3.6 - toxenv: py36-tests_nongpl + toxenv: py36-format-build - os: windows-latest python-version: name: 3.6 - toxenv: py36-build + toxenv: py36-format_nongpl-build + - os: windows-latest + python-version: + name: 3.6 + toxenv: py36-noextra-tests + - os: windows-latest + python-version: + name: 3.6 + toxenv: py36-format-tests + - os: windows-latest + python-version: + name: 3.6 + toxenv: py36-format_nongpl-tests - os: windows-latest python-version: name: 3.7 - toxenv: py37-build + toxenv: py37-noextra-tests + - os: windows-latest + python-version: + name: 3.7 + toxenv: py37-format-tests + - os: windows-latest + python-version: + name: 3.7 + toxenv: py37-format_nongpl-tests + - os: windows-latest + python-version: + name: 3.8 + toxenv: py38-noextra-tests + - os: windows-latest + python-version: + name: 3.8 + toxenv: py38-format-tests - os: windows-latest python-version: name: 3.8 - toxenv: py38-build + toxenv: py38-format_nongpl-tests - os: windows-latest python-version: name: pypy3 diff --git a/tox.ini b/tox.ini index f60161cff..a67775bec 100644 --- a/tox.ini +++ b/tox.ini @@ -1,6 +1,6 @@ [tox] envlist = - py{36,37,38,py3}-{build,tests,tests_nongpl}, + py{36,37,38,py3}-{noextra,format,format_nongpl}-{build,tests}, demo readme safety @@ -16,10 +16,11 @@ setenv = whitelist_externals = mkdir commands = - perf,tests: {envpython} -m pip install '{toxinidir}[format]' - tests_nongpl: {envpython} -m pip install '{toxinidir}[format_nongpl]' + noextra: {envpython} -m pip install {toxinidir} + format: {envpython} -m pip install '{toxinidir}[format]' + format_nongpl: {envpython} -m pip install '{toxinidir}[format_nongpl]' - tests,tests_nongpl: {envpython} -m twisted.trial {posargs:jsonschema} + tests: {envpython} -m twisted.trial {posargs:jsonschema} tests: {envpython} -m doctest {toxinidir}/README.rst perf: mkdir {envtmpdir}/benchmarks/ @@ -33,7 +34,7 @@ deps = perf: pyperf - tests,tests_nongpl,coverage,codecov: twisted + tests,coverage,codecov: twisted coverage,codecov: coverage codecov: codecov From 95f38a61ab17610c564efa3d29a4354d46c56e13 Mon Sep 17 00:00:00 2001 From: Julian Berman Date: Wed, 12 Aug 2020 16:23:23 -0400 Subject: [PATCH 06/35] Unbreak non-format-setuptools-extra-installed jsonschema. Revert the changes to the docs requirements. fqdn is *not* a doc requirement, it's part of the package's requirements, but only when format validation is installed. The docs builds were failing because they do not install the format extra. This was actually a (known bad) CI gap, that we didn't run the tests against all the configurations (i.e. against jsonschema installed with no setuptools extras, say). Fixed in the previous commit, so now we can run this. --- docs/requirements.in | 1 - docs/requirements.txt | 3 --- jsonschema/_format.py | 27 +++++++++++++++------------ 3 files changed, 15 insertions(+), 16 deletions(-) diff --git a/docs/requirements.in b/docs/requirements.in index d280be979..0c4f8bca5 100644 --- a/docs/requirements.in +++ b/docs/requirements.in @@ -1,4 +1,3 @@ -fqdn lxml sphinx sphinxcontrib-spelling diff --git a/docs/requirements.txt b/docs/requirements.txt index 7e2e0ff61..11fbfe7c5 100644 --- a/docs/requirements.txt +++ b/docs/requirements.txt @@ -6,12 +6,9 @@ # alabaster==0.7.12 # via sphinx babel==2.8.0 # via sphinx -cached-property==1.5.1 # via fqdn certifi==2020.4.5.1 # via requests chardet==3.0.4 # via requests -colorama==0.4.3 # via sphinx docutils==0.16 # via sphinx -fqdn==1.4.0 # via -r requirements.in idna==2.9 # via requests imagesize==1.2.0 # via sphinx jinja2==2.11.2 # via sphinx diff --git a/jsonschema/_format.py b/jsonschema/_format.py index 36bacab00..65e453e43 100644 --- a/jsonschema/_format.py +++ b/jsonschema/_format.py @@ -3,8 +3,6 @@ import socket import struct -from fqdn import FQDN - from jsonschema.exceptions import FormatError @@ -211,16 +209,21 @@ def is_ipv6(instance): return socket.inet_pton(socket.AF_INET6, instance) -@_checks_drafts( - draft3="host-name", - draft4="hostname", - draft6="hostname", - draft7="hostname", -) -def is_host_name(instance): - if not isinstance(instance, str): - return True - return FQDN(instance).is_valid +try: + from fqdn import FQDN +except ImportError: + pass +else: + @_checks_drafts( + draft3="host-name", + draft4="hostname", + draft6="hostname", + draft7="hostname", + ) + def is_host_name(instance): + if not isinstance(instance, str): + return True + return FQDN(instance).is_valid try: From 6e1281abc981a5ff20fc10b7dde194d7eae4f637 Mon Sep 17 00:00:00 2001 From: Julian Berman Date: Wed, 12 Aug 2020 19:40:32 -0400 Subject: [PATCH 07/35] isorted. --- docs/conf.py | 1 - docs/jsonschema_role.py | 7 ++++--- jsonschema/__init__.py | 11 ++++++++--- jsonschema/__main__.py | 1 + jsonschema/benchmarks/issue232.py | 1 - jsonschema/benchmarks/json_schema_test_suite.py | 1 - jsonschema/exceptions.py | 1 - jsonschema/tests/_helpers.py | 2 +- jsonschema/tests/test_cli.py | 2 +- jsonschema/tests/test_format.py | 3 +-- jsonschema/tests/test_jsonschema_test_suite.py | 1 - jsonschema/validators.py | 2 +- pyproject.toml | 5 +++++ 13 files changed, 22 insertions(+), 16 deletions(-) diff --git a/docs/conf.py b/docs/conf.py index 565b00a82..fbf6f3098 100644 --- a/docs/conf.py +++ b/docs/conf.py @@ -9,7 +9,6 @@ import jsonschema - # If extensions (or modules to document with autodoc) are in another directory, # add these directories to sys.path here. If the directory is relative to the # documentation root, use os.path.abspath to make it absolute, like shown here. diff --git a/docs/jsonschema_role.py b/docs/jsonschema_role.py index a63ff7242..82ccfbe6b 100644 --- a/docs/jsonschema_role.py +++ b/docs/jsonschema_role.py @@ -1,17 +1,18 @@ from datetime import datetime -from docutils import nodes import errno import os +from docutils import nodes + try: import urllib2 as urllib except ImportError: import urllib.request as urllib -import certifi -import jsonschema from lxml import html +import certifi +import jsonschema __version__ = "1.1.0" VALIDATION_SPEC = "https://json-schema.org/draft-07/json-schema-validation.html" diff --git a/jsonschema/__init__.py b/jsonschema/__init__.py index 6b630cdfb..619a7eabb 100644 --- a/jsonschema/__init__.py +++ b/jsonschema/__init__.py @@ -8,9 +8,6 @@ instance under a schema, and will create a validator for you. """ -from jsonschema.exceptions import ( - ErrorTree, FormatError, RefResolutionError, SchemaError, ValidationError -) from jsonschema._format import ( FormatChecker, draft3_format_checker, @@ -19,6 +16,13 @@ draft7_format_checker, ) from jsonschema._types import TypeChecker +from jsonschema.exceptions import ( + ErrorTree, + FormatError, + RefResolutionError, + SchemaError, + ValidationError, +) from jsonschema.validators import ( Draft3Validator, Draft4Validator, @@ -27,6 +31,7 @@ RefResolver, validate, ) + try: from importlib import metadata except ImportError: # for Python<3.8 diff --git a/jsonschema/__main__.py b/jsonschema/__main__.py index 82c29fd39..fdc21e230 100644 --- a/jsonschema/__main__.py +++ b/jsonschema/__main__.py @@ -1,2 +1,3 @@ from jsonschema.cli import main + main() diff --git a/jsonschema/benchmarks/issue232.py b/jsonschema/benchmarks/issue232.py index b1b05b2ed..e08dff955 100644 --- a/jsonschema/benchmarks/issue232.py +++ b/jsonschema/benchmarks/issue232.py @@ -12,7 +12,6 @@ from jsonschema.tests._suite import Version import jsonschema - issue232 = Version( path=Path(__file__).parent / "issue232", remotes=m(), diff --git a/jsonschema/benchmarks/json_schema_test_suite.py b/jsonschema/benchmarks/json_schema_test_suite.py index 5add5051d..4126fdc8f 100644 --- a/jsonschema/benchmarks/json_schema_test_suite.py +++ b/jsonschema/benchmarks/json_schema_test_suite.py @@ -9,6 +9,5 @@ from jsonschema.tests._suite import Suite - if __name__ == "__main__": Suite().benchmark(runner=Runner()) diff --git a/jsonschema/exceptions.py b/jsonschema/exceptions.py index 2c2ce4d57..46ffceda5 100644 --- a/jsonschema/exceptions.py +++ b/jsonschema/exceptions.py @@ -10,7 +10,6 @@ from jsonschema import _utils - WEAK_MATCHES = frozenset(["anyOf", "oneOf"]) STRONG_MATCHES = frozenset() diff --git a/jsonschema/tests/_helpers.py b/jsonschema/tests/_helpers.py index 761b40452..51fff4ff7 100644 --- a/jsonschema/tests/_helpers.py +++ b/jsonschema/tests/_helpers.py @@ -1,5 +1,5 @@ -from io import StringIO from contextlib import contextmanager +from io import StringIO import sys diff --git a/jsonschema/tests/test_cli.py b/jsonschema/tests/test_cli.py index c473e583f..7ca32fc73 100644 --- a/jsonschema/tests/test_cli.py +++ b/jsonschema/tests/test_cli.py @@ -8,7 +8,7 @@ import subprocess import sys -from jsonschema import Draft4Validator, cli, __version__ +from jsonschema import Draft4Validator, __version__, cli from jsonschema.exceptions import SchemaError, ValidationError from jsonschema.tests._helpers import captured_output from jsonschema.validators import _LATEST_VERSION, validate diff --git a/jsonschema/tests/test_format.py b/jsonschema/tests/test_format.py index 254985f61..6dba484e6 100644 --- a/jsonschema/tests/test_format.py +++ b/jsonschema/tests/test_format.py @@ -4,10 +4,9 @@ from unittest import TestCase -from jsonschema import FormatError, ValidationError, FormatChecker +from jsonschema import FormatChecker, FormatError, ValidationError from jsonschema.validators import Draft4Validator - BOOM = ValueError("Boom!") BANG = ZeroDivisionError("Bang!") diff --git a/jsonschema/tests/test_jsonschema_test_suite.py b/jsonschema/tests/test_jsonschema_test_suite.py index f87c0f686..37d45e013 100644 --- a/jsonschema/tests/test_jsonschema_test_suite.py +++ b/jsonschema/tests/test_jsonschema_test_suite.py @@ -23,7 +23,6 @@ from jsonschema.tests._suite import Suite from jsonschema.validators import _DEPRECATED_DEFAULT_TYPES, create - SUITE = Suite() DRAFT3 = SUITE.version(name="draft3") DRAFT4 = SUITE.version(name="draft4") diff --git a/jsonschema/validators.py b/jsonschema/validators.py index 2ea23ac77..d6e0a0c09 100644 --- a/jsonschema/validators.py +++ b/jsonschema/validators.py @@ -17,11 +17,11 @@ _validators, exceptions, ) - # Sigh. https://gitlab.com/pycqa/flake8/issues/280 # https://github.com/pyga/ebb-lint/issues/7 # Imported for backwards compatibility. from jsonschema.exceptions import ErrorTree + ErrorTree diff --git a/pyproject.toml b/pyproject.toml index 9cdcbf74f..477d5e673 100644 --- a/pyproject.toml +++ b/pyproject.toml @@ -8,4 +8,9 @@ requires = [ ] build-backend = "setuptools.build_meta" +[tool.isort] +from_first = true +include_trailing_comma = true +multi_line_output = 3 + [tool.setuptools_scm] From ee1bc0c31c5d8f7e8730cd476b82e88996ef69b9 Mon Sep 17 00:00:00 2001 From: Julian Berman Date: Wed, 12 Aug 2020 19:41:35 -0400 Subject: [PATCH 08/35] Kill Py2 in the sphinx role. --- docs/jsonschema_role.py | 11 +++-------- 1 file changed, 3 insertions(+), 8 deletions(-) diff --git a/docs/jsonschema_role.py b/docs/jsonschema_role.py index 82ccfbe6b..8a4feaa01 100644 --- a/docs/jsonschema_role.py +++ b/docs/jsonschema_role.py @@ -1,14 +1,9 @@ from datetime import datetime import errno import os +import urllib.request from docutils import nodes - -try: - import urllib2 as urllib -except ImportError: - import urllib.request as urllib - from lxml import html import certifi @@ -69,8 +64,8 @@ def fetch_or_load(spec_path): if error.errno != errno.ENOENT: raise - request = urllib.Request(VALIDATION_SPEC, headers=headers) - response = urllib.urlopen(request, cafile=certifi.where()) + request = urllib.request.Request(VALIDATION_SPEC, headers=headers) + response = urllib.request.urlopen(request, cafile=certifi.where()) if response.code == 200: with open(spec_path, "w+b") as spec: From 85b85098255dae226b5cf8e7279ee3f4ae328902 Mon Sep 17 00:00:00 2001 From: Julian Berman Date: Wed, 12 Aug 2020 19:56:52 -0400 Subject: [PATCH 09/35] Trailing whitespace --- CHANGELOG.rst | 4 ++-- README.rst | 2 +- 2 files changed, 3 insertions(+), 3 deletions(-) diff --git a/CHANGELOG.rst b/CHANGELOG.rst index 8f0a2700e..7c1a67e3c 100644 --- a/CHANGELOG.rst +++ b/CHANGELOG.rst @@ -43,7 +43,7 @@ v2.6.0 * Support for Python 2.6 has been dropped. * Improve a few error messages for ``uniqueItems`` (#224) and ``additionalProperties`` (#317) -* Fixed an issue with ``ErrorTree``'s handling of multiple errors (#288) +* Fixed an issue with ``ErrorTree``'s handling of multiple errors (#288) v2.5.0 ------ @@ -175,7 +175,7 @@ v0.4 In order to make this happen (and also to clean things up a bit), a number of deprecations are necessary: - * ``stop_on_error`` is deprecated in ``Validator.__init__``. Use + * ``stop_on_error`` is deprecated in ``Validator.__init__``. Use ``Validator.iter_errors()`` instead. * ``number_types`` and ``string_types`` are deprecated there as well. Use ``types={"number" : ..., "string" : ...}`` instead. diff --git a/README.rst b/README.rst index d2db17f49..d09e47508 100644 --- a/README.rst +++ b/README.rst @@ -125,7 +125,7 @@ Benchmarks ---------- ``jsonschema``'s benchmarks make use of `pyperf -`_. Running them can be done via:: +`_. Running them can be done via:: $ tox -e perf From 5bcf7a79be672bdc4a0cece088597cd51f6eccf7 Mon Sep 17 00:00:00 2001 From: Julian Berman Date: Wed, 12 Aug 2020 22:59:33 -0400 Subject: [PATCH 10/35] pre-commit setup. --- .pre-commit-config.yaml | 27 +++++++++++++++++++++++++++ 1 file changed, 27 insertions(+) create mode 100644 .pre-commit-config.yaml diff --git a/.pre-commit-config.yaml b/.pre-commit-config.yaml new file mode 100644 index 000000000..a1dc79958 --- /dev/null +++ b/.pre-commit-config.yaml @@ -0,0 +1,27 @@ +exclude: json + +repos: +- repo: https://github.com/pre-commit/pre-commit-hooks + rev: v3.2.0 + hooks: + - id: check-ast + - id: check-docstring-first + - id: check-json + - id: check-toml + - id: check-vcs-permalinks + - id: check-yaml + - id: debug-statements + - id: end-of-file-fixer + - id: trailing-whitespace +- repo: https://github.com/timothycrosley/isort + rev: 5.3.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 From 444174d607ced66d38ef31fcc279b5cf06973c4b Mon Sep 17 00:00:00 2001 From: Julian Berman Date: Wed, 12 Aug 2020 23:01:36 -0400 Subject: [PATCH 11/35] Bump the version in the notebooks.io requirements. Really this should be tested somehow. --- demo.yml | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-) diff --git a/demo.yml b/demo.yml index a2d7e46f5..0e9755f50 100644 --- a/demo.yml +++ b/demo.yml @@ -1,2 +1,2 @@ requirements: - - jsonschema==3.0.1 + - jsonschema==3.2.0 From d9c0da82ead96af579e4172abea57144fccd1a8f Mon Sep 17 00:00:00 2001 From: Hillel Arnold Date: Thu, 13 Aug 2020 17:27:44 -0400 Subject: [PATCH 12/35] improve date parsing --- jsonschema/_format.py | 5 ++++- 1 file changed, 4 insertions(+), 1 deletion(-) diff --git a/jsonschema/_format.py b/jsonschema/_format.py index 65e453e43..6b8745e3b 100644 --- a/jsonschema/_format.py +++ b/jsonschema/_format.py @@ -330,7 +330,10 @@ def is_regex(instance): def is_date(instance): if not isinstance(instance, str): return True - return datetime.datetime.strptime(instance, "%Y-%m-%d") + try: + return datetime.date.fromisoformat(instance) + except AttributeError: + return datetime.datetime.strptime(instance, "%Y-%m-%d") @_checks_drafts(draft3="time", raises=ValueError) From a57d8540bd272d913d57a37b45db3d9fe21a476b Mon Sep 17 00:00:00 2001 From: Julian Berman Date: Thu, 13 Aug 2020 18:44:47 -0400 Subject: [PATCH 13/35] Squashed 'json/' changes from ea415537..86f52b87 86f52b87 Fix a clear copy-paste error in the case names for tests from #394. ec18a7d0 Merge pull request #360 from notEthan/duplicate_uris cd9a4b9d change schemas with duplicate URIs http://localhost:1234/folder/ 43e190e0 Merge pull request #394 from rjmill/rjmill/bools-and-1s-and-0s-inside-objects-and-arrays 85f0d459 Merge pull request #419 from ChALkeR/chalker/format-uri 54436216 Merge pull request #420 from ChALkeR/chalker/format/ip6 ad47b726 Add long valid and invalid ipv6 b2ab70ec More optional ipv6 tests 37189ae6 Test that uri format scheme is validated for allowed chars 2106ed17 backport uniqueItems cases to draft3 49fc2a95 backport const test cases to draft6 79fe60c0 more tests for true != 1 and false != 0 inside objects/arrays git-subtree-dir: json git-subtree-split: 86f52b87e3d572b8f808dd074a6b95c3695ba992 --- bin/jsonschema_suite | 4 +- .../folderInteger.json | 0 .../baseUriChangeFolder/folderInteger.json | 3 + .../folderInteger.json | 3 + tests/draft2019-09/const.json | 84 +++++++++++++++++++ tests/draft2019-09/optional/format/ipv6.json | 35 ++++++++ tests/draft2019-09/optional/format/uri.json | 5 ++ tests/draft2019-09/refRemote.json | 10 +-- tests/draft2019-09/uniqueItems.json | 10 +++ tests/draft3/refRemote.json | 2 +- tests/draft3/uniqueItems.json | 10 +++ tests/draft4/optional/format/ipv6.json | 35 ++++++++ tests/draft4/optional/format/uri.json | 5 ++ tests/draft4/refRemote.json | 6 +- tests/draft4/uniqueItems.json | 10 +++ tests/draft6/const.json | 84 +++++++++++++++++++ tests/draft6/optional/format/ipv6.json | 35 ++++++++ tests/draft6/optional/format/uri.json | 5 ++ tests/draft6/refRemote.json | 6 +- tests/draft6/uniqueItems.json | 10 +++ tests/draft7/const.json | 84 +++++++++++++++++++ tests/draft7/optional/format/ipv6.json | 35 ++++++++ tests/draft7/optional/format/uri.json | 5 ++ tests/draft7/refRemote.json | 6 +- tests/draft7/uniqueItems.json | 10 +++ 25 files changed, 486 insertions(+), 16 deletions(-) rename remotes/{folder => baseUriChange}/folderInteger.json (100%) create mode 100644 remotes/baseUriChangeFolder/folderInteger.json create mode 100644 remotes/baseUriChangeFolderInSubschema/folderInteger.json diff --git a/bin/jsonschema_suite b/bin/jsonschema_suite index c8bb7ba32..5f5d133f3 100755 --- a/bin/jsonschema_suite +++ b/bin/jsonschema_suite @@ -51,7 +51,9 @@ REMOTES = { u"refToInteger": {u"$ref": u"#/$defs/integer"}, } }, - "folder/folderInteger.json": {u"type": u"integer"} + "baseUriChange/folderInteger.json": {u"type": u"integer"}, + "baseUriChangeFolder/folderInteger.json": {u"type": u"integer"}, + "baseUriChangeFolderInSubschema/folderInteger.json": {u"type": u"integer"}, } REMOTES_DIR = os.path.join(ROOT_DIR, "remotes") diff --git a/remotes/folder/folderInteger.json b/remotes/baseUriChange/folderInteger.json similarity index 100% rename from remotes/folder/folderInteger.json rename to remotes/baseUriChange/folderInteger.json diff --git a/remotes/baseUriChangeFolder/folderInteger.json b/remotes/baseUriChangeFolder/folderInteger.json new file mode 100644 index 000000000..8b50ea308 --- /dev/null +++ b/remotes/baseUriChangeFolder/folderInteger.json @@ -0,0 +1,3 @@ +{ + "type": "integer" +} diff --git a/remotes/baseUriChangeFolderInSubschema/folderInteger.json b/remotes/baseUriChangeFolderInSubschema/folderInteger.json new file mode 100644 index 000000000..8b50ea308 --- /dev/null +++ b/remotes/baseUriChangeFolderInSubschema/folderInteger.json @@ -0,0 +1,3 @@ +{ + "type": "integer" +} diff --git a/tests/draft2019-09/const.json b/tests/draft2019-09/const.json index c53d04d95..1c2cafcc1 100644 --- a/tests/draft2019-09/const.json +++ b/tests/draft2019-09/const.json @@ -125,6 +125,90 @@ } ] }, + { + "description": "const with [false] does not match [0]", + "schema": {"const": [false]}, + "tests": [ + { + "description": "[false] is valid", + "data": [false], + "valid": true + }, + { + "description": "[0] is invalid", + "data": [0], + "valid": false + }, + { + "description": "[0.0] is invalid", + "data": [0.0], + "valid": false + } + ] + }, + { + "description": "const with [true] does not match [1]", + "schema": {"const": [true]}, + "tests": [ + { + "description": "[true] is valid", + "data": [true], + "valid": true + }, + { + "description": "[1] is invalid", + "data": [1], + "valid": false + }, + { + "description": "[1.0] is invalid", + "data": [1.0], + "valid": false + } + ] + }, + { + "description": "const with {\"a\": false} does not match {\"a\": 0}", + "schema": {"const": {"a": false}}, + "tests": [ + { + "description": "{\"a\": false} is valid", + "data": {"a": false}, + "valid": true + }, + { + "description": "{\"a\": 0} is invalid", + "data": {"a": 0}, + "valid": false + }, + { + "description": "{\"a\": 0.0} is invalid", + "data": {"a": 0.0}, + "valid": false + } + ] + }, + { + "description": "const with {\"a\": true} does not match {\"a\": 1}", + "schema": {"const": {"a": true}}, + "tests": [ + { + "description": "{\"a\": true} is valid", + "data": {"a": true}, + "valid": true + }, + { + "description": "{\"a\": 1} is invalid", + "data": {"a": 1}, + "valid": false + }, + { + "description": "{\"a\": 1.0} is invalid", + "data": {"a": 1.0}, + "valid": false + } + ] + }, { "description": "const with 0 does not match other zero-like types", "schema": {"const": 0}, diff --git a/tests/draft2019-09/optional/format/ipv6.json b/tests/draft2019-09/optional/format/ipv6.json index 9b0881eeb..2a08cb46f 100644 --- a/tests/draft2019-09/optional/format/ipv6.json +++ b/tests/draft2019-09/optional/format/ipv6.json @@ -112,6 +112,41 @@ "description": "ipv4 segment must have 4 octets", "data": "1:2:3:4:1.2.3", "valid": false + }, + { + "description": "leading whitespace is invalid", + "data": " ::1", + "valid": false + }, + { + "description": "trailing whitespace is invalid", + "data": "::1 ", + "valid": false + }, + { + "description": "netmask is not a part of ipv6 address", + "data": "fe80::/64", + "valid": false + }, + { + "description": "zone id is not a part of ipv6 address", + "data": "fe80::a%eth1", + "valid": false + }, + { + "description": "a long valid ipv6", + "data": "1000:1000:1000:1000:1000:1000:255.255.255.255", + "valid": true + }, + { + "description": "a long invalid ipv6, below length limit, first", + "data": "100:100:100:100:100:100:255.255.255.255.255", + "valid": false + }, + { + "description": "a long invalid ipv6, below length limit, second", + "data": "100:100:100:100:100:100:100:255.255.255.255", + "valid": false } ] } diff --git a/tests/draft2019-09/optional/format/uri.json b/tests/draft2019-09/optional/format/uri.json index 25cc40c80..4306a686b 100644 --- a/tests/draft2019-09/optional/format/uri.json +++ b/tests/draft2019-09/optional/format/uri.json @@ -97,6 +97,11 @@ "description": "an invalid URI with spaces and missing scheme", "data": ":// should fail", "valid": false + }, + { + "description": "an invalid URI with comma in scheme", + "data": "bar,baz:foo", + "valid": false } ] } diff --git a/tests/draft2019-09/refRemote.json b/tests/draft2019-09/refRemote.json index 515263ddb..b9c6a282b 100644 --- a/tests/draft2019-09/refRemote.json +++ b/tests/draft2019-09/refRemote.json @@ -54,7 +54,7 @@ "schema": { "$id": "http://localhost:1234/", "items": { - "$id": "folder/", + "$id": "baseUriChange/", "items": {"$ref": "folderInteger.json"} } }, @@ -76,10 +76,10 @@ "schema": { "$id": "http://localhost:1234/scope_change_defs1.json", "type" : "object", - "properties": {"list": {"$ref": "folder/"}}, + "properties": {"list": {"$ref": "baseUriChangeFolder/"}}, "$defs": { "baz": { - "$id": "folder/", + "$id": "baseUriChangeFolder/", "type": "array", "items": {"$ref": "folderInteger.json"} } @@ -103,10 +103,10 @@ "schema": { "$id": "http://localhost:1234/scope_change_defs2.json", "type" : "object", - "properties": {"list": {"$ref": "folder/#/$defs/bar"}}, + "properties": {"list": {"$ref": "baseUriChangeFolderInSubschema/#/$defs/bar"}}, "$defs": { "baz": { - "$id": "folder/", + "$id": "baseUriChangeFolderInSubschema/", "$defs": { "bar": { "type": "array", diff --git a/tests/draft2019-09/uniqueItems.json b/tests/draft2019-09/uniqueItems.json index fb1ddb5c4..4846c7735 100644 --- a/tests/draft2019-09/uniqueItems.json +++ b/tests/draft2019-09/uniqueItems.json @@ -113,6 +113,16 @@ "description": "objects are non-unique despite key order", "data": [{"a": 1, "b": 2}, {"b": 2, "a": 1}], "valid": false + }, + { + "description": "{\"a\": false} and {\"a\": 0} are unique", + "data": [{"a": false}, {"a": 0}], + "valid": true + }, + { + "description": "{\"a\": true} and {\"a\": 1} are unique", + "data": [{"a": true}, {"a": 1}], + "valid": true } ] }, diff --git a/tests/draft3/refRemote.json b/tests/draft3/refRemote.json index 4ca804732..de0cb43a5 100644 --- a/tests/draft3/refRemote.json +++ b/tests/draft3/refRemote.json @@ -54,7 +54,7 @@ "schema": { "id": "http://localhost:1234/", "items": { - "id": "folder/", + "id": "baseUriChange/", "items": {"$ref": "folderInteger.json"} } }, diff --git a/tests/draft3/uniqueItems.json b/tests/draft3/uniqueItems.json index 8f8dbddcc..fd4b84974 100644 --- a/tests/draft3/uniqueItems.json +++ b/tests/draft3/uniqueItems.json @@ -93,6 +93,16 @@ "description": "non-unique heterogeneous types are invalid", "data": [{}, [1], true, null, {}, 1], "valid": false + }, + { + "description": "{\"a\": false} and {\"a\": 0} are unique", + "data": [{"a": false}, {"a": 0}], + "valid": true + }, + { + "description": "{\"a\": true} and {\"a\": 1} are unique", + "data": [{"a": true}, {"a": 1}], + "valid": true } ] }, diff --git a/tests/draft4/optional/format/ipv6.json b/tests/draft4/optional/format/ipv6.json index 9b0881eeb..2a08cb46f 100644 --- a/tests/draft4/optional/format/ipv6.json +++ b/tests/draft4/optional/format/ipv6.json @@ -112,6 +112,41 @@ "description": "ipv4 segment must have 4 octets", "data": "1:2:3:4:1.2.3", "valid": false + }, + { + "description": "leading whitespace is invalid", + "data": " ::1", + "valid": false + }, + { + "description": "trailing whitespace is invalid", + "data": "::1 ", + "valid": false + }, + { + "description": "netmask is not a part of ipv6 address", + "data": "fe80::/64", + "valid": false + }, + { + "description": "zone id is not a part of ipv6 address", + "data": "fe80::a%eth1", + "valid": false + }, + { + "description": "a long valid ipv6", + "data": "1000:1000:1000:1000:1000:1000:255.255.255.255", + "valid": true + }, + { + "description": "a long invalid ipv6, below length limit, first", + "data": "100:100:100:100:100:100:255.255.255.255.255", + "valid": false + }, + { + "description": "a long invalid ipv6, below length limit, second", + "data": "100:100:100:100:100:100:100:255.255.255.255", + "valid": false } ] } diff --git a/tests/draft4/optional/format/uri.json b/tests/draft4/optional/format/uri.json index 25cc40c80..4306a686b 100644 --- a/tests/draft4/optional/format/uri.json +++ b/tests/draft4/optional/format/uri.json @@ -97,6 +97,11 @@ "description": "an invalid URI with spaces and missing scheme", "data": ":// should fail", "valid": false + }, + { + "description": "an invalid URI with comma in scheme", + "data": "bar,baz:foo", + "valid": false } ] } diff --git a/tests/draft4/refRemote.json b/tests/draft4/refRemote.json index 8611fadc0..ce5e99a30 100644 --- a/tests/draft4/refRemote.json +++ b/tests/draft4/refRemote.json @@ -54,7 +54,7 @@ "schema": { "id": "http://localhost:1234/", "items": { - "id": "folder/", + "id": "baseUriChange/", "items": {"$ref": "folderInteger.json"} } }, @@ -81,7 +81,7 @@ }, "definitions": { "baz": { - "id": "folder/", + "id": "baseUriChangeFolder/", "type": "array", "items": {"$ref": "folderInteger.json"} } @@ -110,7 +110,7 @@ }, "definitions": { "baz": { - "id": "folder/", + "id": "baseUriChangeFolderInSubschema/", "definitions": { "bar": { "type": "array", diff --git a/tests/draft4/uniqueItems.json b/tests/draft4/uniqueItems.json index fb1ddb5c4..4846c7735 100644 --- a/tests/draft4/uniqueItems.json +++ b/tests/draft4/uniqueItems.json @@ -113,6 +113,16 @@ "description": "objects are non-unique despite key order", "data": [{"a": 1, "b": 2}, {"b": 2, "a": 1}], "valid": false + }, + { + "description": "{\"a\": false} and {\"a\": 0} are unique", + "data": [{"a": false}, {"a": 0}], + "valid": true + }, + { + "description": "{\"a\": true} and {\"a\": 1} are unique", + "data": [{"a": true}, {"a": 1}], + "valid": true } ] }, diff --git a/tests/draft6/const.json b/tests/draft6/const.json index c53d04d95..1c2cafcc1 100644 --- a/tests/draft6/const.json +++ b/tests/draft6/const.json @@ -125,6 +125,90 @@ } ] }, + { + "description": "const with [false] does not match [0]", + "schema": {"const": [false]}, + "tests": [ + { + "description": "[false] is valid", + "data": [false], + "valid": true + }, + { + "description": "[0] is invalid", + "data": [0], + "valid": false + }, + { + "description": "[0.0] is invalid", + "data": [0.0], + "valid": false + } + ] + }, + { + "description": "const with [true] does not match [1]", + "schema": {"const": [true]}, + "tests": [ + { + "description": "[true] is valid", + "data": [true], + "valid": true + }, + { + "description": "[1] is invalid", + "data": [1], + "valid": false + }, + { + "description": "[1.0] is invalid", + "data": [1.0], + "valid": false + } + ] + }, + { + "description": "const with {\"a\": false} does not match {\"a\": 0}", + "schema": {"const": {"a": false}}, + "tests": [ + { + "description": "{\"a\": false} is valid", + "data": {"a": false}, + "valid": true + }, + { + "description": "{\"a\": 0} is invalid", + "data": {"a": 0}, + "valid": false + }, + { + "description": "{\"a\": 0.0} is invalid", + "data": {"a": 0.0}, + "valid": false + } + ] + }, + { + "description": "const with {\"a\": true} does not match {\"a\": 1}", + "schema": {"const": {"a": true}}, + "tests": [ + { + "description": "{\"a\": true} is valid", + "data": {"a": true}, + "valid": true + }, + { + "description": "{\"a\": 1} is invalid", + "data": {"a": 1}, + "valid": false + }, + { + "description": "{\"a\": 1.0} is invalid", + "data": {"a": 1.0}, + "valid": false + } + ] + }, { "description": "const with 0 does not match other zero-like types", "schema": {"const": 0}, diff --git a/tests/draft6/optional/format/ipv6.json b/tests/draft6/optional/format/ipv6.json index 9b0881eeb..2a08cb46f 100644 --- a/tests/draft6/optional/format/ipv6.json +++ b/tests/draft6/optional/format/ipv6.json @@ -112,6 +112,41 @@ "description": "ipv4 segment must have 4 octets", "data": "1:2:3:4:1.2.3", "valid": false + }, + { + "description": "leading whitespace is invalid", + "data": " ::1", + "valid": false + }, + { + "description": "trailing whitespace is invalid", + "data": "::1 ", + "valid": false + }, + { + "description": "netmask is not a part of ipv6 address", + "data": "fe80::/64", + "valid": false + }, + { + "description": "zone id is not a part of ipv6 address", + "data": "fe80::a%eth1", + "valid": false + }, + { + "description": "a long valid ipv6", + "data": "1000:1000:1000:1000:1000:1000:255.255.255.255", + "valid": true + }, + { + "description": "a long invalid ipv6, below length limit, first", + "data": "100:100:100:100:100:100:255.255.255.255.255", + "valid": false + }, + { + "description": "a long invalid ipv6, below length limit, second", + "data": "100:100:100:100:100:100:100:255.255.255.255", + "valid": false } ] } diff --git a/tests/draft6/optional/format/uri.json b/tests/draft6/optional/format/uri.json index 25cc40c80..4306a686b 100644 --- a/tests/draft6/optional/format/uri.json +++ b/tests/draft6/optional/format/uri.json @@ -97,6 +97,11 @@ "description": "an invalid URI with spaces and missing scheme", "data": ":// should fail", "valid": false + }, + { + "description": "an invalid URI with comma in scheme", + "data": "bar,baz:foo", + "valid": false } ] } diff --git a/tests/draft6/refRemote.json b/tests/draft6/refRemote.json index 819d32678..74a786261 100644 --- a/tests/draft6/refRemote.json +++ b/tests/draft6/refRemote.json @@ -54,7 +54,7 @@ "schema": { "$id": "http://localhost:1234/", "items": { - "$id": "folder/", + "$id": "baseUriChange/", "items": {"$ref": "folderInteger.json"} } }, @@ -81,7 +81,7 @@ }, "definitions": { "baz": { - "$id": "folder/", + "$id": "baseUriChangeFolder/", "type": "array", "items": {"$ref": "folderInteger.json"} } @@ -110,7 +110,7 @@ }, "definitions": { "baz": { - "$id": "folder/", + "$id": "baseUriChangeFolderInSubschema/", "definitions": { "bar": { "type": "array", diff --git a/tests/draft6/uniqueItems.json b/tests/draft6/uniqueItems.json index fb1ddb5c4..4846c7735 100644 --- a/tests/draft6/uniqueItems.json +++ b/tests/draft6/uniqueItems.json @@ -113,6 +113,16 @@ "description": "objects are non-unique despite key order", "data": [{"a": 1, "b": 2}, {"b": 2, "a": 1}], "valid": false + }, + { + "description": "{\"a\": false} and {\"a\": 0} are unique", + "data": [{"a": false}, {"a": 0}], + "valid": true + }, + { + "description": "{\"a\": true} and {\"a\": 1} are unique", + "data": [{"a": true}, {"a": 1}], + "valid": true } ] }, diff --git a/tests/draft7/const.json b/tests/draft7/const.json index c53d04d95..1c2cafcc1 100644 --- a/tests/draft7/const.json +++ b/tests/draft7/const.json @@ -125,6 +125,90 @@ } ] }, + { + "description": "const with [false] does not match [0]", + "schema": {"const": [false]}, + "tests": [ + { + "description": "[false] is valid", + "data": [false], + "valid": true + }, + { + "description": "[0] is invalid", + "data": [0], + "valid": false + }, + { + "description": "[0.0] is invalid", + "data": [0.0], + "valid": false + } + ] + }, + { + "description": "const with [true] does not match [1]", + "schema": {"const": [true]}, + "tests": [ + { + "description": "[true] is valid", + "data": [true], + "valid": true + }, + { + "description": "[1] is invalid", + "data": [1], + "valid": false + }, + { + "description": "[1.0] is invalid", + "data": [1.0], + "valid": false + } + ] + }, + { + "description": "const with {\"a\": false} does not match {\"a\": 0}", + "schema": {"const": {"a": false}}, + "tests": [ + { + "description": "{\"a\": false} is valid", + "data": {"a": false}, + "valid": true + }, + { + "description": "{\"a\": 0} is invalid", + "data": {"a": 0}, + "valid": false + }, + { + "description": "{\"a\": 0.0} is invalid", + "data": {"a": 0.0}, + "valid": false + } + ] + }, + { + "description": "const with {\"a\": true} does not match {\"a\": 1}", + "schema": {"const": {"a": true}}, + "tests": [ + { + "description": "{\"a\": true} is valid", + "data": {"a": true}, + "valid": true + }, + { + "description": "{\"a\": 1} is invalid", + "data": {"a": 1}, + "valid": false + }, + { + "description": "{\"a\": 1.0} is invalid", + "data": {"a": 1.0}, + "valid": false + } + ] + }, { "description": "const with 0 does not match other zero-like types", "schema": {"const": 0}, diff --git a/tests/draft7/optional/format/ipv6.json b/tests/draft7/optional/format/ipv6.json index 9b0881eeb..2a08cb46f 100644 --- a/tests/draft7/optional/format/ipv6.json +++ b/tests/draft7/optional/format/ipv6.json @@ -112,6 +112,41 @@ "description": "ipv4 segment must have 4 octets", "data": "1:2:3:4:1.2.3", "valid": false + }, + { + "description": "leading whitespace is invalid", + "data": " ::1", + "valid": false + }, + { + "description": "trailing whitespace is invalid", + "data": "::1 ", + "valid": false + }, + { + "description": "netmask is not a part of ipv6 address", + "data": "fe80::/64", + "valid": false + }, + { + "description": "zone id is not a part of ipv6 address", + "data": "fe80::a%eth1", + "valid": false + }, + { + "description": "a long valid ipv6", + "data": "1000:1000:1000:1000:1000:1000:255.255.255.255", + "valid": true + }, + { + "description": "a long invalid ipv6, below length limit, first", + "data": "100:100:100:100:100:100:255.255.255.255.255", + "valid": false + }, + { + "description": "a long invalid ipv6, below length limit, second", + "data": "100:100:100:100:100:100:100:255.255.255.255", + "valid": false } ] } diff --git a/tests/draft7/optional/format/uri.json b/tests/draft7/optional/format/uri.json index 25cc40c80..4306a686b 100644 --- a/tests/draft7/optional/format/uri.json +++ b/tests/draft7/optional/format/uri.json @@ -97,6 +97,11 @@ "description": "an invalid URI with spaces and missing scheme", "data": ":// should fail", "valid": false + }, + { + "description": "an invalid URI with comma in scheme", + "data": "bar,baz:foo", + "valid": false } ] } diff --git a/tests/draft7/refRemote.json b/tests/draft7/refRemote.json index 819d32678..74a786261 100644 --- a/tests/draft7/refRemote.json +++ b/tests/draft7/refRemote.json @@ -54,7 +54,7 @@ "schema": { "$id": "http://localhost:1234/", "items": { - "$id": "folder/", + "$id": "baseUriChange/", "items": {"$ref": "folderInteger.json"} } }, @@ -81,7 +81,7 @@ }, "definitions": { "baz": { - "$id": "folder/", + "$id": "baseUriChangeFolder/", "type": "array", "items": {"$ref": "folderInteger.json"} } @@ -110,7 +110,7 @@ }, "definitions": { "baz": { - "$id": "folder/", + "$id": "baseUriChangeFolderInSubschema/", "definitions": { "bar": { "type": "array", diff --git a/tests/draft7/uniqueItems.json b/tests/draft7/uniqueItems.json index fb1ddb5c4..4846c7735 100644 --- a/tests/draft7/uniqueItems.json +++ b/tests/draft7/uniqueItems.json @@ -113,6 +113,16 @@ "description": "objects are non-unique despite key order", "data": [{"a": 1, "b": 2}, {"b": 2, "a": 1}], "valid": false + }, + { + "description": "{\"a\": false} and {\"a\": 0} are unique", + "data": [{"a": false}, {"a": 0}], + "valid": true + }, + { + "description": "{\"a\": true} and {\"a\": 1} are unique", + "data": [{"a": true}, {"a": 1}], + "valid": true } ] }, From 4e7870bfc6930b80214c5005e769b2b66ce93ee8 Mon Sep 17 00:00:00 2001 From: Julian Berman Date: Thu, 13 Aug 2020 19:29:00 -0400 Subject: [PATCH 14/35] Skip more tests for #686. --- .../tests/test_jsonschema_test_suite.py | 80 +++++++++++++++++++ 1 file changed, 80 insertions(+) diff --git a/jsonschema/tests/test_jsonschema_test_suite.py b/jsonschema/tests/test_jsonschema_test_suite.py index 37d45e013..8939b5c64 100644 --- a/jsonschema/tests/test_jsonschema_test_suite.py +++ b/jsonschema/tests/test_jsonschema_test_suite.py @@ -124,6 +124,16 @@ def narrow_unicode_build(test): # pragma: no cover subject="uniqueItems", description="nested [1] and [true] are unique", )(test) + or skip( + message=bug(686), + subject="uniqueItems", + description='{"a": false} and {"a": 0} are unique', + )(test) + or skip( + message=bug(686), + subject="uniqueItems", + description='{"a": true} and {"a": 1} are unique', + )(test) ), ) @@ -194,6 +204,16 @@ def narrow_unicode_build(test): # pragma: no cover subject="uniqueItems", description="nested [1] and [true] are unique", )(test) + or skip( + message=bug(686), + subject="uniqueItems", + description='{"a": false} and {"a": 0} are unique', + )(test) + or skip( + message=bug(686), + subject="uniqueItems", + description='{"a": true} and {"a": 1} are unique', + )(test) ), ) @@ -263,6 +283,36 @@ def narrow_unicode_build(test): # pragma: no cover subject="uniqueItems", description="nested [1] and [true] are unique", )(test) + or skip( + message=bug(686), + subject="uniqueItems", + description='{"a": false} and {"a": 0} are unique', + )(test) + or skip( + message=bug(686), + subject="uniqueItems", + description='{"a": true} and {"a": 1} are unique', + )(test) + or skip( + message=bug(686), + subject="const", + case_description="const with [false] does not match [0]", + )(test) + or skip( + message=bug(686), + subject="const", + case_description="const with [true] does not match [1]", + )(test) + or skip( + message=bug(686), + subject="const", + case_description='const with {"a": false} does not match {"a": 0}', + )(test) + or skip( + message=bug(686), + subject="const", + case_description='const with {"a": true} does not match {"a": 1}', + )(test) ), ) @@ -355,6 +405,36 @@ def narrow_unicode_build(test): # pragma: no cover subject="uniqueItems", description="nested [1] and [true] are unique", )(test) + or skip( + message=bug(686), + subject="uniqueItems", + description='{"a": false} and {"a": 0} are unique', + )(test) + or skip( + message=bug(686), + subject="uniqueItems", + description='{"a": true} and {"a": 1} are unique', + )(test) + or skip( + message=bug(686), + subject="const", + case_description="const with [false] does not match [0]", + )(test) + or skip( + message=bug(686), + subject="const", + case_description="const with [true] does not match [1]", + )(test) + or skip( + message=bug(686), + subject="const", + case_description='const with {"a": false} does not match {"a": 0}', + )(test) + or skip( + message=bug(686), + subject="const", + case_description='const with {"a": true} does not match {"a": 1}', + )(test) ), ) From 09bd22d3f324723d9b2ac669c907988635c73f47 Mon Sep 17 00:00:00 2001 From: Julian Berman Date: Thu, 13 Aug 2020 19:33:26 -0400 Subject: [PATCH 15/35] Validate IP addresses using the ipaddress module. --- jsonschema/_format.py | 31 ++++++++++++------------------- 1 file changed, 12 insertions(+), 19 deletions(-) diff --git a/jsonschema/_format.py b/jsonschema/_format.py index 65e453e43..fc44442dc 100644 --- a/jsonschema/_format.py +++ b/jsonschema/_format.py @@ -1,7 +1,6 @@ import datetime +import ipaddress import re -import socket -import struct from jsonschema.exceptions import FormatError @@ -183,30 +182,24 @@ def is_email(instance): return "@" in instance -_ipv4_re = re.compile(r"^\d{1,3}\.\d{1,3}\.\d{1,3}\.\d{1,3}$") - - @_checks_drafts( - draft3="ip-address", draft4="ipv4", draft6="ipv4", draft7="ipv4", + draft3="ip-address", + draft4="ipv4", + draft6="ipv4", + draft7="ipv4", + raises=ipaddress.AddressValueError, ) def is_ipv4(instance): if not isinstance(instance, str): return True - if not _ipv4_re.match(instance): - return False - return all(0 <= int(component) <= 255 for component in instance.split(".")) + return ipaddress.IPv4Address(instance) -if hasattr(socket, "inet_pton"): - # FIXME: Really this only should raise struct.error, but see the sadness - # that is https://twistedmatrix.com/trac/ticket/9409 - @_checks_drafts( - name="ipv6", raises=(socket.error, struct.error, ValueError), - ) - def is_ipv6(instance): - if not isinstance(instance, str): - return True - return socket.inet_pton(socket.AF_INET6, instance) +@_checks_drafts(name="ipv6", raises=ipaddress.AddressValueError) +def is_ipv6(instance): + if not isinstance(instance, str): + return True + return ipaddress.IPv6Address(instance) try: From b3ebd208e200797c1235c614c779f015addf1d99 Mon Sep 17 00:00:00 2001 From: Julian Berman Date: Fri, 14 Aug 2020 12:31:08 -0400 Subject: [PATCH 16/35] Squashed 'json/' changes from 86f52b87..fce9e9b3 fce9e9b3 Merge pull request #426 from helrond/padded-dates e61b6471 tests should invalidate df8f6bb9 add tests to date-time f137b811 add checks to draft3 3aa603fb adds tests for non zero-padded dates git-subtree-dir: json git-subtree-split: fce9e9b337c46fe587a42e535058d261c38241aa --- tests/draft2019-09/optional/format/date-time.json | 10 ++++++++++ tests/draft2019-09/optional/format/date.json | 10 ++++++++++ tests/draft3/optional/format/date-time.json | 10 ++++++++++ tests/draft3/optional/format/date.json | 15 +++++++++++++++ tests/draft4/optional/format/date-time.json | 10 ++++++++++ tests/draft6/optional/format/date-time.json | 12 +++++++++++- tests/draft7/optional/format/date-time.json | 10 ++++++++++ tests/draft7/optional/format/date.json | 10 ++++++++++ 8 files changed, 86 insertions(+), 1 deletion(-) diff --git a/tests/draft2019-09/optional/format/date-time.json b/tests/draft2019-09/optional/format/date-time.json index dfccee6e6..900fcb7c0 100644 --- a/tests/draft2019-09/optional/format/date-time.json +++ b/tests/draft2019-09/optional/format/date-time.json @@ -47,6 +47,16 @@ "description": "only RFC3339 not all of ISO 8601 are valid", "data": "2013-350T01:01:01", "valid": false + }, + { + "description": "invalid non-padded month dates", + "data": "1963-6-19T08:30:06.283185Z", + "valid": false + }, + { + "description": "invalid non-padded day dates", + "data": "1963-06-1T08:30:06.283185Z", + "valid": false } ] } diff --git a/tests/draft2019-09/optional/format/date.json b/tests/draft2019-09/optional/format/date.json index cd23baae3..453b51de0 100644 --- a/tests/draft2019-09/optional/format/date.json +++ b/tests/draft2019-09/optional/format/date.json @@ -17,6 +17,16 @@ "description": "only RFC3339 not all of ISO 8601 are valid", "data": "2013-350", "valid": false + }, + { + "description": "invalidates non-padded month dates", + "data": "1998-1-20", + "valid": false + }, + { + "description": "invalidates non-padded day dates", + "data": "1998-01-1", + "valid": false } ] } diff --git a/tests/draft3/optional/format/date-time.json b/tests/draft3/optional/format/date-time.json index 90279baa0..58261fad2 100644 --- a/tests/draft3/optional/format/date-time.json +++ b/tests/draft3/optional/format/date-time.json @@ -22,6 +22,16 @@ "description": "only RFC3339 not all of ISO 8601 are valid", "data": "2013-350T01:01:01", "valid": false + }, + { + "description": "invalid non-padded month dates", + "data": "1963-6-19T08:30:06.283185Z", + "valid": false + }, + { + "description": "invalid non-padded day dates", + "data": "1963-06-1T08:30:06.283185Z", + "valid": false } ] } diff --git a/tests/draft3/optional/format/date.json b/tests/draft3/optional/format/date.json index bd8304225..4842b4871 100644 --- a/tests/draft3/optional/format/date.json +++ b/tests/draft3/optional/format/date.json @@ -12,6 +12,21 @@ "description": "an invalid date string", "data": "06/19/1963", "valid": false + }, + { + "description": "only RFC3339 not all of ISO 8601 are valid", + "data": "2013-350", + "valid": false + }, + { + "description": "invalidates non-padded month dates", + "data": "1998-1-20", + "valid": false + }, + { + "description": "invalidates non-padded day dates", + "data": "1998-01-1", + "valid": false } ] } diff --git a/tests/draft4/optional/format/date-time.json b/tests/draft4/optional/format/date-time.json index dfccee6e6..900fcb7c0 100644 --- a/tests/draft4/optional/format/date-time.json +++ b/tests/draft4/optional/format/date-time.json @@ -47,6 +47,16 @@ "description": "only RFC3339 not all of ISO 8601 are valid", "data": "2013-350T01:01:01", "valid": false + }, + { + "description": "invalid non-padded month dates", + "data": "1963-6-19T08:30:06.283185Z", + "valid": false + }, + { + "description": "invalid non-padded day dates", + "data": "1963-06-1T08:30:06.283185Z", + "valid": false } ] } diff --git a/tests/draft6/optional/format/date-time.json b/tests/draft6/optional/format/date-time.json index fc949e901..a6320a90d 100644 --- a/tests/draft6/optional/format/date-time.json +++ b/tests/draft6/optional/format/date-time.json @@ -37,7 +37,7 @@ "description": "an invalid closing Z after time-zone offset", "data": "1963-06-19T08:30:06.28123+01:00Z", "valid": false - }, + }, { "description": "an invalid date-time string", "data": "06/19/1963 08:30:06 PST", @@ -52,6 +52,16 @@ "description": "only RFC3339 not all of ISO 8601 are valid", "data": "2013-350T01:01:01", "valid": false + }, + { + "description": "invalid non-padded month dates", + "data": "1963-6-19T08:30:06.283185Z", + "valid": false + }, + { + "description": "invalid non-padded day dates", + "data": "1963-06-1T08:30:06.283185Z", + "valid": false } ] } diff --git a/tests/draft7/optional/format/date-time.json b/tests/draft7/optional/format/date-time.json index dfccee6e6..900fcb7c0 100644 --- a/tests/draft7/optional/format/date-time.json +++ b/tests/draft7/optional/format/date-time.json @@ -47,6 +47,16 @@ "description": "only RFC3339 not all of ISO 8601 are valid", "data": "2013-350T01:01:01", "valid": false + }, + { + "description": "invalid non-padded month dates", + "data": "1963-6-19T08:30:06.283185Z", + "valid": false + }, + { + "description": "invalid non-padded day dates", + "data": "1963-06-1T08:30:06.283185Z", + "valid": false } ] } diff --git a/tests/draft7/optional/format/date.json b/tests/draft7/optional/format/date.json index cd23baae3..453b51de0 100644 --- a/tests/draft7/optional/format/date.json +++ b/tests/draft7/optional/format/date.json @@ -17,6 +17,16 @@ "description": "only RFC3339 not all of ISO 8601 are valid", "data": "2013-350", "valid": false + }, + { + "description": "invalidates non-padded month dates", + "data": "1998-1-20", + "valid": false + }, + { + "description": "invalidates non-padded day dates", + "data": "1998-01-1", + "valid": false } ] } From ff1ddcf0780b7e3c0851a4350f9c3c893e8eb954 Mon Sep 17 00:00:00 2001 From: Julian Berman Date: Fri, 14 Aug 2020 12:34:36 -0400 Subject: [PATCH 17/35] Temporarily skip the tests that will be unskipped by #722. --- .../tests/test_jsonschema_test_suite.py | 20 +++++++++++++++++++ 1 file changed, 20 insertions(+) diff --git a/jsonschema/tests/test_jsonschema_test_suite.py b/jsonschema/tests/test_jsonschema_test_suite.py index 8939b5c64..177d549b1 100644 --- a/jsonschema/tests/test_jsonschema_test_suite.py +++ b/jsonschema/tests/test_jsonschema_test_suite.py @@ -99,6 +99,16 @@ def narrow_unicode_build(test): # pragma: no cover narrow_unicode_build(test) or missing_format(draft3_format_checker)(test) or complex_email_validation(test) + or skip( + message=bug(685), + subject="date", + description="invalidates non-padded month dates", + )(test) + or skip( + message=bug(685), + subject="date", + description="invalidates non-padded day dates", + )(test) or skip( message="Upstream bug in strict_rfc3339", subject="date-time", @@ -358,6 +368,16 @@ def narrow_unicode_build(test): # pragma: no cover subject="refRemote", case_description="base URI change - change folder in subschema", )(test) + or skip( + message=bug(685), + subject="date", + description="invalidates non-padded month dates", + )(test) + or skip( + message=bug(685), + subject="date", + description="invalidates non-padded day dates", + )(test) or skip( message="Upstream bug in strict_rfc3339", subject="date-time", From 6bb7f9b28ca63a43ebdb304b8aa2ae009aa49d80 Mon Sep 17 00:00:00 2001 From: Hillel Arnold Date: Tue, 18 Aug 2020 15:51:10 -0400 Subject: [PATCH 18/35] unskip tests --- .../tests/test_jsonschema_test_suite.py | 20 ------------------- 1 file changed, 20 deletions(-) diff --git a/jsonschema/tests/test_jsonschema_test_suite.py b/jsonschema/tests/test_jsonschema_test_suite.py index 177d549b1..8939b5c64 100644 --- a/jsonschema/tests/test_jsonschema_test_suite.py +++ b/jsonschema/tests/test_jsonschema_test_suite.py @@ -99,16 +99,6 @@ def narrow_unicode_build(test): # pragma: no cover narrow_unicode_build(test) or missing_format(draft3_format_checker)(test) or complex_email_validation(test) - or skip( - message=bug(685), - subject="date", - description="invalidates non-padded month dates", - )(test) - or skip( - message=bug(685), - subject="date", - description="invalidates non-padded day dates", - )(test) or skip( message="Upstream bug in strict_rfc3339", subject="date-time", @@ -368,16 +358,6 @@ def narrow_unicode_build(test): # pragma: no cover subject="refRemote", case_description="base URI change - change folder in subschema", )(test) - or skip( - message=bug(685), - subject="date", - description="invalidates non-padded month dates", - )(test) - or skip( - message=bug(685), - subject="date", - description="invalidates non-padded day dates", - )(test) or skip( message="Upstream bug in strict_rfc3339", subject="date-time", From 30891433c8730692617d4eb7ee501c110c71d6cb Mon Sep 17 00:00:00 2001 From: Hillel Arnold Date: Wed, 19 Aug 2020 17:09:53 -0400 Subject: [PATCH 19/35] skip tests on python 3.6 --- .../tests/test_jsonschema_test_suite.py | 23 +++++++++++++++++++ 1 file changed, 23 insertions(+) diff --git a/jsonschema/tests/test_jsonschema_test_suite.py b/jsonschema/tests/test_jsonschema_test_suite.py index 8939b5c64..120595710 100644 --- a/jsonschema/tests/test_jsonschema_test_suite.py +++ b/jsonschema/tests/test_jsonschema_test_suite.py @@ -87,6 +87,25 @@ def narrow_unicode_build(test): # pragma: no cover return +if sys.version_info < (3, 7): + message = "Not running tests which require Python 3.7 or greater" + + def python_lt_37_build(test): + return skip( + message=bug(685), + subject="date", + description="invalidates non-padded month dates", + )(test) + or skip( + message=bug(685), + subject="date", + description="invalidates non-padded day dates", + )(test) +else: + def python_lt_37_build(test): + return + + TestDraft3 = DRAFT3.to_unittest_testcase( DRAFT3.tests(), DRAFT3.format_tests(), @@ -97,6 +116,7 @@ def narrow_unicode_build(test): # pragma: no cover format_checker=draft3_format_checker, skip=lambda test: ( narrow_unicode_build(test) + or python_lt_37_build(test) or missing_format(draft3_format_checker)(test) or complex_email_validation(test) or skip( @@ -148,6 +168,7 @@ def narrow_unicode_build(test): # pragma: no cover format_checker=draft4_format_checker, skip=lambda test: ( narrow_unicode_build(test) + or python_lt_37_build(test) or missing_format(draft4_format_checker)(test) or complex_email_validation(test) or skip( @@ -227,6 +248,7 @@ def narrow_unicode_build(test): # pragma: no cover format_checker=draft6_format_checker, skip=lambda test: ( narrow_unicode_build(test) + or python_lt_37_build(test) or missing_format(draft6_format_checker)(test) or complex_email_validation(test) or skip( @@ -327,6 +349,7 @@ def narrow_unicode_build(test): # pragma: no cover format_checker=draft7_format_checker, skip=lambda test: ( narrow_unicode_build(test) + or python_lt_37_build(test) or missing_format(draft7_format_checker)(test) or complex_email_validation(test) or skip( From b8dd5a6dc345583b09b1efaa5afc83273213fdf7 Mon Sep 17 00:00:00 2001 From: Hillel Arnold Date: Wed, 19 Aug 2020 17:16:18 -0400 Subject: [PATCH 20/35] fix formatting error --- jsonschema/tests/test_jsonschema_test_suite.py | 7 +++---- 1 file changed, 3 insertions(+), 4 deletions(-) diff --git a/jsonschema/tests/test_jsonschema_test_suite.py b/jsonschema/tests/test_jsonschema_test_suite.py index 120595710..3fc48018c 100644 --- a/jsonschema/tests/test_jsonschema_test_suite.py +++ b/jsonschema/tests/test_jsonschema_test_suite.py @@ -92,12 +92,11 @@ def narrow_unicode_build(test): # pragma: no cover def python_lt_37_build(test): return skip( - message=bug(685), + message=message, subject="date", description="invalidates non-padded month dates", - )(test) - or skip( - message=bug(685), + )(test) or skip( + message=message, subject="date", description="invalidates non-padded day dates", )(test) From 2f1d5ef2767dd7f1593240b67f7afd08eae81fc6 Mon Sep 17 00:00:00 2001 From: Hillel Arnold Date: Wed, 19 Aug 2020 19:02:25 -0400 Subject: [PATCH 21/35] better handling for Python 3.6 --- jsonschema/_format.py | 10 ++++++---- 1 file changed, 6 insertions(+), 4 deletions(-) diff --git a/jsonschema/_format.py b/jsonschema/_format.py index 202c9505c..ba324ca0e 100644 --- a/jsonschema/_format.py +++ b/jsonschema/_format.py @@ -323,10 +323,12 @@ def is_regex(instance): def is_date(instance): if not isinstance(instance, str): return True - try: - return datetime.date.fromisoformat(instance) - except AttributeError: - return datetime.datetime.strptime(instance, "%Y-%m-%d") + if hasattr(datetime.date, "fromisoformat"): + _is_date = datetime.date.fromisoformat + else: + def _is_date(instance): + return datetime.datetime.strptime(instance, "%Y-%m-%d") + return _is_date(instance) @_checks_drafts(draft3="time", raises=ValueError) From 69c68232690b80dfd0adf20190e492f90fba413e Mon Sep 17 00:00:00 2001 From: Hillel Arnold Date: Wed, 19 Aug 2020 19:02:46 -0400 Subject: [PATCH 22/35] renames message and function --- jsonschema/tests/test_jsonschema_test_suite.py | 14 +++++++------- 1 file changed, 7 insertions(+), 7 deletions(-) diff --git a/jsonschema/tests/test_jsonschema_test_suite.py b/jsonschema/tests/test_jsonschema_test_suite.py index 3fc48018c..0f9698a64 100644 --- a/jsonschema/tests/test_jsonschema_test_suite.py +++ b/jsonschema/tests/test_jsonschema_test_suite.py @@ -88,9 +88,9 @@ def narrow_unicode_build(test): # pragma: no cover if sys.version_info < (3, 7): - message = "Not running tests which require Python 3.7 or greater" + message = "datetime.date.fromisoformat is new in 3.7+" - def python_lt_37_build(test): + def missing_date_fromisoformat(test): return skip( message=message, subject="date", @@ -101,7 +101,7 @@ def python_lt_37_build(test): description="invalidates non-padded day dates", )(test) else: - def python_lt_37_build(test): + def missing_date_fromisoformat(test): return @@ -115,7 +115,7 @@ def python_lt_37_build(test): format_checker=draft3_format_checker, skip=lambda test: ( narrow_unicode_build(test) - or python_lt_37_build(test) + or missing_date_fromisoformat(test) or missing_format(draft3_format_checker)(test) or complex_email_validation(test) or skip( @@ -167,7 +167,7 @@ def python_lt_37_build(test): format_checker=draft4_format_checker, skip=lambda test: ( narrow_unicode_build(test) - or python_lt_37_build(test) + or missing_date_fromisoformat(test) or missing_format(draft4_format_checker)(test) or complex_email_validation(test) or skip( @@ -247,7 +247,7 @@ def python_lt_37_build(test): format_checker=draft6_format_checker, skip=lambda test: ( narrow_unicode_build(test) - or python_lt_37_build(test) + or missing_date_fromisoformat(test) or missing_format(draft6_format_checker)(test) or complex_email_validation(test) or skip( @@ -348,7 +348,7 @@ def python_lt_37_build(test): format_checker=draft7_format_checker, skip=lambda test: ( narrow_unicode_build(test) - or python_lt_37_build(test) + or missing_date_fromisoformat(test) or missing_format(draft7_format_checker)(test) or complex_email_validation(test) or skip( From d9d5fe1ef11ada41a81c4543db3f896745985cda Mon Sep 17 00:00:00 2001 From: Hillel Arnold Date: Wed, 19 Aug 2020 19:49:49 -0400 Subject: [PATCH 23/35] use correct format check globally --- jsonschema/_format.py | 12 +++++++----- 1 file changed, 7 insertions(+), 5 deletions(-) diff --git a/jsonschema/_format.py b/jsonschema/_format.py index ba324ca0e..ce478648f 100644 --- a/jsonschema/_format.py +++ b/jsonschema/_format.py @@ -319,15 +319,17 @@ def is_regex(instance): return re.compile(instance) +if hasattr(datetime.date, "fromisoformat"): + _is_date = datetime.date.fromisoformat +else: + def _is_date(instance): + return datetime.datetime.strptime(instance, "%Y-%m-%d") + + @_checks_drafts(draft3="date", draft7="date", raises=ValueError) def is_date(instance): if not isinstance(instance, str): return True - if hasattr(datetime.date, "fromisoformat"): - _is_date = datetime.date.fromisoformat - else: - def _is_date(instance): - return datetime.datetime.strptime(instance, "%Y-%m-%d") return _is_date(instance) From f13195f874a4ae5c2ddcf889ceea8f1e2e8fa84b Mon Sep 17 00:00:00 2001 From: willson-chen Date: Thu, 20 Aug 2020 16:04:51 +0800 Subject: [PATCH 24/35] Fix the bug of processing arguments[validator] in parse_args --- jsonschema/cli.py | 5 +++-- 1 file changed, 3 insertions(+), 2 deletions(-) diff --git a/jsonschema/cli.py b/jsonschema/cli.py index 4c2bb4f20..713193979 100644 --- a/jsonschema/cli.py +++ b/jsonschema/cli.py @@ -191,8 +191,6 @@ def _namedAnyWithDefault(name): def parse_args(args): arguments = vars(parser.parse_args(args=args or ["--help"])) - if arguments["validator"] is None: - arguments["validator"] = validator_for(arguments["schema"]) if arguments["output"] != "plain" and arguments["error_format"]: raise parser.error( "--error-format can only be used with --output plain" @@ -229,6 +227,9 @@ def run(arguments, stdout=sys.stdout, stderr=sys.stderr, stdin=sys.stdin): except _CannotLoadFile: return 1 + if arguments["validator"] is None: + arguments["validator"] = validator_for(schema) + try: arguments["validator"].check_schema(schema) except SchemaError as error: From 5680761abfd3462dcf2fe5de442d129c1350c790 Mon Sep 17 00:00:00 2001 From: willson-chen Date: Thu, 20 Aug 2020 20:26:16 +0800 Subject: [PATCH 25/35] Delete the failed test case --- jsonschema/tests/test_cli.py | 11 +---------- 1 file changed, 1 insertion(+), 10 deletions(-) diff --git a/jsonschema/tests/test_cli.py b/jsonschema/tests/test_cli.py index 7ca32fc73..441ad6fa8 100644 --- a/jsonschema/tests/test_cli.py +++ b/jsonschema/tests/test_cli.py @@ -11,7 +11,7 @@ from jsonschema import Draft4Validator, __version__, cli from jsonschema.exceptions import SchemaError, ValidationError from jsonschema.tests._helpers import captured_output -from jsonschema.validators import _LATEST_VERSION, validate +from jsonschema.validators import validate def fake_validator(*errors): @@ -717,15 +717,6 @@ def test_find_validator_in_jsonschema(self): ) self.assertIs(arguments["validator"], Draft4Validator) - def test_latest_validator_is_the_default(self): - arguments = cli.parse_args( - [ - "--instance", "mem://some/instance", - "mem://some/schema", - ] - ) - self.assertIs(arguments["validator"], _LATEST_VERSION) - def test_unknown_output(self): # Avoid the help message on stdout with captured_output() as (stdout, stderr): From dc509218ffd4e4fabb35acd27cf3fb8678be2080 Mon Sep 17 00:00:00 2001 From: willson-chen Date: Mon, 24 Aug 2020 14:09:10 +0800 Subject: [PATCH 26/35] add test case --- jsonschema/tests/test_cli.py | 53 +++++++++++++++++++++++++++++++++++- 1 file changed, 52 insertions(+), 1 deletion(-) diff --git a/jsonschema/tests/test_cli.py b/jsonschema/tests/test_cli.py index 441ad6fa8..d0ca811d3 100644 --- a/jsonschema/tests/test_cli.py +++ b/jsonschema/tests/test_cli.py @@ -11,7 +11,7 @@ from jsonschema import Draft4Validator, __version__, cli from jsonschema.exceptions import SchemaError, ValidationError from jsonschema.tests._helpers import captured_output -from jsonschema.validators import validate +from jsonschema.validators import _LATEST_VERSION, validate, validator_for def fake_validator(*errors): @@ -691,6 +691,47 @@ def test_real_validator(self): stderr="", ) + def test_draft07_check_const(self): + schema = """ + { + "$schema": "http://json-schema.org/draft-07/schema#", + "properties": { + "value": { + "type": "string", + "const": "check" + } + } + } + """ + instance = """{"value": "2"}""" + self.assertOutputs( + files=dict(some_schema=schema, some_instance=instance), + argv=["-i", "some_instance", "some_schema"], + exit_code=1, + stdout="", + stderr="2: 'check' was expected\n", + ) + + def test_draft04_not_check_const(self): + schema = """ + { + "$schema": "http://json-schema.org/draft-04/schema#", + "properties": { + "value": { + "type": "string", + "const": "check" + } + } + } + """ + instance = """{"value": "2"}""" + self.assertOutputs( + files=dict(some_schema=schema, some_instance=instance), + argv=["-i", "some_instance", "some_schema"], + stdout="", + stderr="", + ) + class TestParser(TestCase): @@ -717,6 +758,16 @@ def test_find_validator_in_jsonschema(self): ) self.assertIs(arguments["validator"], Draft4Validator) + def test_latest_validator_is_the_default(self): + arguments = cli.parse_args( + [ + "--instance", "mem://some/instance", + "mem://some/schema", + ] + ) + arguments["validator"] = validator_for(arguments["schema"]) + self.assertIs(arguments["validator"], _LATEST_VERSION) + def test_unknown_output(self): # Avoid the help message on stdout with captured_output() as (stdout, stderr): From 32b4de4810ebafdb5f28a21c3aabd29b9e2d1880 Mon Sep 17 00:00:00 2001 From: Julian Berman Date: Wed, 26 Aug 2020 08:43:09 -0400 Subject: [PATCH 27/35] Simplify the schemas in the tests for CLI validator detection. --- jsonschema/tests/test_cli.py | 46 ++++++++++++++++-------------------- 1 file changed, 21 insertions(+), 25 deletions(-) diff --git a/jsonschema/tests/test_cli.py b/jsonschema/tests/test_cli.py index d0ca811d3..12c21a38f 100644 --- a/jsonschema/tests/test_cli.py +++ b/jsonschema/tests/test_cli.py @@ -691,40 +691,36 @@ def test_real_validator(self): stderr="", ) - def test_draft07_check_const(self): + def test_it_validates_using_draft7_when_specified(self): + """ + Specifically, `const` validation applies for Draft 7. + """ schema = """ - { - "$schema": "http://json-schema.org/draft-07/schema#", - "properties": { - "value": { - "type": "string", - "const": "check" - } - } - } - """ - instance = """{"value": "2"}""" + { + "$schema": "http://json-schema.org/draft-07/schema#", + "const": "check" + } + """ + instance = '"foo"' self.assertOutputs( files=dict(some_schema=schema, some_instance=instance), argv=["-i", "some_instance", "some_schema"], exit_code=1, stdout="", - stderr="2: 'check' was expected\n", + stderr="foo: 'check' was expected\n", ) - def test_draft04_not_check_const(self): + def test_it_validates_using_draft4_when_specified(self): + """ + Specifically, `const` validation *does not* apply for Draft 4. + """ schema = """ - { - "$schema": "http://json-schema.org/draft-04/schema#", - "properties": { - "value": { - "type": "string", - "const": "check" - } - } - } - """ - instance = """{"value": "2"}""" + { + "$schema": "http://json-schema.org/draft-04/schema#", + "const": "check" + } + """ + instance = '"foo"' self.assertOutputs( files=dict(some_schema=schema, some_instance=instance), argv=["-i", "some_instance", "some_schema"], From 9c6c79a60deb48424052ba68550ec081a4e64bd0 Mon Sep 17 00:00:00 2001 From: Julian Berman Date: Wed, 26 Aug 2020 09:03:10 -0400 Subject: [PATCH 28/35] Move the latest validator CLI test to where it must go now. Checking that validator_for works correctly was not the intention of that test. For now, that means we need a guard to ensure we test a validator that only would work if the latest version was used. We can clean that up later. Also remove test_real_validator, since there's now 3 different tests using real validators. --- jsonschema/tests/test_cli.py | 32 +++++++++++++++----------------- 1 file changed, 15 insertions(+), 17 deletions(-) diff --git a/jsonschema/tests/test_cli.py b/jsonschema/tests/test_cli.py index 12c21a38f..42167599f 100644 --- a/jsonschema/tests/test_cli.py +++ b/jsonschema/tests/test_cli.py @@ -8,10 +8,10 @@ import subprocess import sys -from jsonschema import Draft4Validator, __version__, cli +from jsonschema import Draft4Validator, Draft7Validator, __version__, cli from jsonschema.exceptions import SchemaError, ValidationError from jsonschema.tests._helpers import captured_output -from jsonschema.validators import _LATEST_VERSION, validate, validator_for +from jsonschema.validators import _LATEST_VERSION, validate def fake_validator(*errors): @@ -675,7 +675,7 @@ def test_successful_validation_of_just_the_schema(self): stderr="", ) - def test_successful_validation__of_just_the_schema_pretty_output(self): + def test_successful_validation_of_just_the_schema_pretty_output(self): self.assertOutputs( files=dict(some_schema="{}", some_instance="{}"), argv=["--output", "pretty", "-i", "some_instance", "some_schema"], @@ -683,12 +683,20 @@ def test_successful_validation__of_just_the_schema_pretty_output(self): stderr="", ) - def test_real_validator(self): + def test_it_validates_using_the_latest_validator_when_unspecified(self): + # There isn't a better way now I can think of to ensure that the + # latest version was used, given that the call to validator_for + # is hidden inside the CLI, so guard that that's the case, and + # this test will have to be updated when versions change until + # we can think of a better way to ensure this behavior. + self.assertIs(Draft7Validator, _LATEST_VERSION) + self.assertOutputs( - files=dict(some_schema='{"minimum": 30}', some_instance="37"), + files=dict(some_schema='{"const": "check"}', some_instance='"a"'), argv=["-i", "some_instance", "some_schema"], + exit_code=1, stdout="", - stderr="", + stderr="a: 'check' was expected\n", ) def test_it_validates_using_draft7_when_specified(self): @@ -719,7 +727,7 @@ def test_it_validates_using_draft4_when_specified(self): "$schema": "http://json-schema.org/draft-04/schema#", "const": "check" } - """ + """ instance = '"foo"' self.assertOutputs( files=dict(some_schema=schema, some_instance=instance), @@ -754,16 +762,6 @@ def test_find_validator_in_jsonschema(self): ) self.assertIs(arguments["validator"], Draft4Validator) - def test_latest_validator_is_the_default(self): - arguments = cli.parse_args( - [ - "--instance", "mem://some/instance", - "mem://some/schema", - ] - ) - arguments["validator"] = validator_for(arguments["schema"]) - self.assertIs(arguments["validator"], _LATEST_VERSION) - def test_unknown_output(self): # Avoid the help message on stdout with captured_output() as (stdout, stderr): From 0c6faf5e6ed17e647d7c7d13a9c36cc8eb2bb788 Mon Sep 17 00:00:00 2001 From: Martin Zugnoni Date: Fri, 28 Aug 2020 16:53:32 -0300 Subject: [PATCH 29/35] Remove demo links from README file --- README.rst | 18 ------------------ 1 file changed, 18 deletions(-) diff --git a/README.rst b/README.rst index d09e47508..dc89d720a 100644 --- a/README.rst +++ b/README.rst @@ -80,24 +80,6 @@ Installation $ pip install jsonschema -Demo ----- - -Try ``jsonschema`` interactively in this online demo: - -.. image:: https://user-images.githubusercontent.com/1155573/56745335-8b158a00-6750-11e9-8776-83fa675939c4.png - :target: https://notebooks.ai/demo/gh/Julian/jsonschema - :alt: Open Live Demo - - -Online demo Notebook will look similar to this: - - -.. image:: https://user-images.githubusercontent.com/1155573/56820861-5c1c1880-6823-11e9-802a-ce01c5ec574f.gif - :alt: Open Live Demo - :width: 480 px - - Release Notes ------------- From 7d552e9ed16488e48faaca034b8645f86cff9334 Mon Sep 17 00:00:00 2001 From: Julian Berman Date: Fri, 28 Aug 2020 16:31:33 -0400 Subject: [PATCH 30/35] Remove the rest of the notebooks.ai related resources. --- DEMO.ipynb | 167 ----------------------------------------------------- demo.yml | 2 - tox.ini | 6 -- 3 files changed, 175 deletions(-) delete mode 100644 DEMO.ipynb delete mode 100644 demo.yml diff --git a/DEMO.ipynb b/DEMO.ipynb deleted file mode 100644 index f008b793f..000000000 --- a/DEMO.ipynb +++ /dev/null @@ -1,167 +0,0 @@ -{ - "cells": [ - { - "cell_type": "markdown", - "metadata": {}, - "source": [ - "# jsonschema\n", - "---" - ] - }, - { - "cell_type": "markdown", - "metadata": {}, - "source": [ - "`jsonschema` is an implementation of [JSON Schema](https://json-schema.org) for Python (supporting 2.7+ including Python 3)." - ] - }, - { - "cell_type": "markdown", - "metadata": {}, - "source": [ - "## Usage" - ] - }, - { - "cell_type": "code", - "execution_count": null, - "metadata": {}, - "outputs": [], - "source": [ - "from jsonschema import validate" - ] - }, - { - "cell_type": "code", - "execution_count": null, - "metadata": {}, - "outputs": [], - "source": [ - "# A sample schema, like what we'd get from json.load()\n", - "schema = {\n", - " \"type\" : \"object\",\n", - " \"properties\" : {\n", - " \"price\" : {\"type\" : \"number\"},\n", - " \"name\" : {\"type\" : \"string\"},\n", - " },\n", - "}" - ] - }, - { - "cell_type": "code", - "execution_count": null, - "metadata": {}, - "outputs": [], - "source": [ - "# If no exception is raised by validate(), the instance is valid.\n", - "validate(instance={\"name\" : \"Eggs\", \"price\" : 34.99}, schema=schema)" - ] - }, - { - "cell_type": "code", - "execution_count": null, - "metadata": {}, - "outputs": [ - { - "ename": "ValidationError", - "evalue": "'Invalid' is not of type 'number'\n\nFailed validating 'type' in schema['properties']['price']:\n {'type': 'number'}\n\nOn instance['price']:\n 'Invalid'", - "output_type": "error", - "traceback": [ - "\u001b[0;31m---------------------------------------------------------------------------\u001b[0m", - "\u001b[0;31mValidationError\u001b[0m Traceback (most recent call last)", - "\u001b[0;32m\u001b[0m in \u001b[0;36m\u001b[0;34m\u001b[0m\n\u001b[1;32m 1\u001b[0m validate(\n\u001b[1;32m 2\u001b[0m \u001b[0minstance\u001b[0m\u001b[0;34m=\u001b[0m\u001b[0;34m{\u001b[0m\u001b[0;34m\"name\"\u001b[0m \u001b[0;34m:\u001b[0m \u001b[0;34m\"Eggs\"\u001b[0m\u001b[0;34m,\u001b[0m \u001b[0;34m\"price\"\u001b[0m \u001b[0;34m:\u001b[0m \u001b[0;34m\"Invalid\"\u001b[0m\u001b[0;34m}\u001b[0m\u001b[0;34m,\u001b[0m\u001b[0;34m\u001b[0m\u001b[0;34m\u001b[0m\u001b[0m\n\u001b[0;32m----> 3\u001b[0;31m \u001b[0mschema\u001b[0m\u001b[0;34m=\u001b[0m\u001b[0mschema\u001b[0m\u001b[0;34m,\u001b[0m\u001b[0;34m\u001b[0m\u001b[0;34m\u001b[0m\u001b[0m\n\u001b[0m\u001b[1;32m 4\u001b[0m )\n", - "\u001b[0;32m~/Development/jsonschema/jsonschema/validators.py\u001b[0m in \u001b[0;36mvalidate\u001b[0;34m(instance, schema, cls, *args, **kwargs)\u001b[0m\n\u001b[1;32m 899\u001b[0m \u001b[0merror\u001b[0m \u001b[0;34m=\u001b[0m \u001b[0mexceptions\u001b[0m\u001b[0;34m.\u001b[0m\u001b[0mbest_match\u001b[0m\u001b[0;34m(\u001b[0m\u001b[0mvalidator\u001b[0m\u001b[0;34m.\u001b[0m\u001b[0miter_errors\u001b[0m\u001b[0;34m(\u001b[0m\u001b[0minstance\u001b[0m\u001b[0;34m)\u001b[0m\u001b[0;34m)\u001b[0m\u001b[0;34m\u001b[0m\u001b[0;34m\u001b[0m\u001b[0m\n\u001b[1;32m 900\u001b[0m \u001b[0;32mif\u001b[0m \u001b[0merror\u001b[0m \u001b[0;32mis\u001b[0m \u001b[0;32mnot\u001b[0m \u001b[0;32mNone\u001b[0m\u001b[0;34m:\u001b[0m\u001b[0;34m\u001b[0m\u001b[0;34m\u001b[0m\u001b[0m\n\u001b[0;32m--> 901\u001b[0;31m \u001b[0;32mraise\u001b[0m \u001b[0merror\u001b[0m\u001b[0;34m\u001b[0m\u001b[0;34m\u001b[0m\u001b[0m\n\u001b[0m\u001b[1;32m 902\u001b[0m \u001b[0;34m\u001b[0m\u001b[0m\n\u001b[1;32m 903\u001b[0m \u001b[0;34m\u001b[0m\u001b[0m\n", - "\u001b[0;31mValidationError\u001b[0m: 'Invalid' is not of type 'number'\n\nFailed validating 'type' in schema['properties']['price']:\n {'type': 'number'}\n\nOn instance['price']:\n 'Invalid'" - ] - } - ], - "source": [ - "validate(\n", - " instance={\"name\" : \"Eggs\", \"price\" : \"Invalid\"},\n", - " schema=schema,\n", - ")" - ] - }, - { - "cell_type": "markdown", - "metadata": {}, - "source": [ - "It can also be used from console:" - ] - }, - { - "cell_type": "code", - "execution_count": null, - "metadata": {}, - "outputs": [], - "source": [ - "!echo '{\"name\" : \"Eggs\", \"price\" : 34.99}' > /tmp/sample.json" - ] - }, - { - "cell_type": "code", - "execution_count": null, - "metadata": {}, - "outputs": [], - "source": [ - "!echo '{\"type\" : \"object\", \"properties\" : {\"price\" : {\"type\" : \"number\"}, \"name\" : {\"type\" : \"string\"}}}' > /tmp/sample.schema" - ] - }, - { - "cell_type": "code", - "execution_count": null, - "metadata": {}, - "outputs": [], - "source": [ - "!jsonschema -i /tmp/sample.json /tmp/sample.schema" - ] - }, - { - "cell_type": "markdown", - "metadata": {}, - "source": [ - "## Do your own experiments here..." - ] - }, - { - "cell_type": "markdown", - "metadata": {}, - "source": [ - "Try `jsonschema` youself by adding your code below and running your own experiments 👇" - ] - }, - { - "cell_type": "code", - "execution_count": null, - "metadata": {}, - "outputs": [], - "source": [ - "import jsonschema\n", - "\n", - "# your code here\n", - "jsonschema." - ] - } - ], - "metadata": { - "kernelspec": { - "display_name": "Python 3", - "language": "python", - "name": "python3" - }, - "language_info": { - "codemirror_mode": { - "name": "ipython", - "version": 3 - }, - "file_extension": ".py", - "mimetype": "text/x-python", - "name": "python", - "nbconvert_exporter": "python", - "pygments_lexer": "ipython3", - "version": "3.7.4" - } - }, - "nbformat": 4, - "nbformat_minor": 4 -} diff --git a/demo.yml b/demo.yml deleted file mode 100644 index 0e9755f50..000000000 --- a/demo.yml +++ /dev/null @@ -1,2 +0,0 @@ -requirements: - - jsonschema==3.2.0 diff --git a/tox.ini b/tox.ini index a67775bec..3deb5a377 100644 --- a/tox.ini +++ b/tox.ini @@ -1,7 +1,6 @@ [tox] envlist = py{36,37,38,py3}-{noextra,format,format_nongpl}-{build,tests}, - demo readme safety secrets @@ -43,11 +42,6 @@ deps = deps = bandit commands = {envbindir}/bandit --recursive {toxinidir}/jsonschema -[testenv:demo] -deps = jupyter -commands = - {envbindir}/jupyter nbconvert --output-dir {envtmpdir} {toxinidir}/DEMO.ipynb - [testenv:readme] deps = docutils From 5fc5b1450a0cdb903ce226105b18169a954dec55 Mon Sep 17 00:00:00 2001 From: Julian Berman Date: Fri, 28 Aug 2020 17:10:35 -0400 Subject: [PATCH 31/35] And two last ones... --- .github/workflows/ci.yml | 6 ------ 1 file changed, 6 deletions(-) diff --git a/.github/workflows/ci.yml b/.github/workflows/ci.yml index e36c151f8..d89d6fd81 100644 --- a/.github/workflows/ci.yml +++ b/.github/workflows/ci.yml @@ -29,8 +29,6 @@ jobs: toxenv: pypy3-format_nongpl-build - name: pypy3 toxenv: pypy3-format_nongpl-tests - - name: pypy3 - toxenv: demo - name: pypy3 toxenv: readme - name: pypy3 @@ -170,10 +168,6 @@ jobs: python-version: name: 3.8 toxenv: py38-format_nongpl-tests - - os: windows-latest - python-version: - name: pypy3 - toxenv: demo - os: windows-latest python-version: name: pypy3 From 169217572a352453ceb2b4528e32c879a5c3fd3e Mon Sep 17 00:00:00 2001 From: Julian Berman Date: Sat, 29 Aug 2020 16:34:00 -0400 Subject: [PATCH 32/35] 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 a1dc79958..7b9e18c60 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 From b18ece38d73370446ebf290b0adb019331032c52 Mon Sep 17 00:00:00 2001 From: Julian Berman Date: Sat, 29 Aug 2020 16:34:40 -0400 Subject: [PATCH 33/35] 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 7b9e18c60..ab72a6ce0 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 From ae4a8e04e0aa4f1e6a0b75252681fd1c0035521d Mon Sep 17 00:00:00 2001 From: Julian Berman Date: Sat, 29 Aug 2020 16:41:07 -0400 Subject: [PATCH 34/35] 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 780a22d8f..a320b2d39 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 2280cc395..82071ca00 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 From 7ce8dd3e09ad43ce52e6fa8ea33adebec2434a65 Mon Sep 17 00:00:00 2001 From: Julian Berman Date: Sat, 29 Aug 2020 16:41:39 -0400 Subject: [PATCH 35/35] 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 ab72a6ce0..bd3e90663 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