Skip to content

Commit

Permalink
tests: Use JSCC 0.2.2
Browse files Browse the repository at this point in the history
  • Loading branch information
duncandewhurst committed Jun 19, 2023
1 parent d16dea0 commit 068112d
Show file tree
Hide file tree
Showing 4 changed files with 33 additions and 28 deletions.
3 changes: 2 additions & 1 deletion requirements.in
Original file line number Diff line number Diff line change
Expand Up @@ -10,6 +10,7 @@ sphinx-intl
sphinx_rtd_theme
myst-parser
pytest
jscc @ git+https://github.com/OpenDataServices/jscc-2020-12@40ffef2f55dff9c3c0a1fdf8cb26d06b261c168f
jscc
ocdskit
mdformat
jsonschema
9 changes: 2 additions & 7 deletions requirements.txt
Original file line number Diff line number Diff line change
Expand Up @@ -45,7 +45,7 @@ jinja2==3.1.2
# via
# myst-parser
# sphinx
jscc @ git+https://github.com/OpenDataServices/jscc-2020-12@40ffef2f55dff9c3c0a1fdf8cb26d06b261c168f
jscc==0.2.2
# via -r requirements.in
json-merge-patch==0.2
# via
Expand All @@ -63,7 +63,7 @@ jsonref==1.0.1
# ocdsmerge
# sphinxcontrib-opendataservices-jsonschema
jsonschema==4.17.3
# via jscc
# via -r requirements.in
livereload==2.6.3
# via sphinx-autobuild
markdown-it-py==2.1.0
Expand Down Expand Up @@ -117,14 +117,9 @@ requests==2.28.1
# sphinx
requests-cache==1.0.1
# via ocdsextensionregistry
rfc3339-validator==0.1.4
# via jscc
rfc3986-validator==0.1.1
# via jscc
six==1.16.0
# via
# livereload
# rfc3339-validator
# url-normalize
snowballstemmer==2.2.0
# via sphinx
Expand Down
8 changes: 0 additions & 8 deletions tests/test_csv.py
Original file line number Diff line number Diff line change
Expand Up @@ -7,11 +7,8 @@
import pytest
import requests
from jscc.schema import is_codelist
from jscc.testing.checks import get_invalid_csv_files
from jscc.testing.filesystem import walk_csv_data
from jscc.testing.util import warn_and_assert
from jsonschema import FormatChecker
from jsonschema.validators import Draft202012Validator as validator

cwd = os.getcwd()
repo_name = os.path.basename(os.getenv('GITHUB_REPOSITORY', cwd))
Expand All @@ -25,11 +22,6 @@ def formatwarning(message, category, filename, lineno, line=None):
pytestmark = pytest.mark.filterwarnings('always')


def test_csv_valid():
warn_and_assert(get_invalid_csv_files(), '{0} is not valid CSV: {1}',
'CSV files are invalid. See warnings below.')


def test_valid():
"""
Ensures all CSV files are valid: no empty rows or columns, no leading or trailing whitespace in cells, same number
Expand Down
41 changes: 29 additions & 12 deletions tests/test_schema.py
Original file line number Diff line number Diff line change
@@ -1,17 +1,32 @@
import jsonref
import pytest
from jscc.testing.filesystem import walk_json_data
from jscc.schema import is_json_schema
from jscc.testing.util import http_get
from jscc.testing.checks import (validate_array_items, validate_codelist_enum, validate_deep_properties,
validate_items_type, validate_letter_case, validate_merge_properties,
validate_metadata_presence, validate_null_type, validate_object_id, validate_ref,
validate_schema)

import jsonref
import pytest
from jscc.testing.checks import (
validate_array_items,
validate_codelist_enum,
validate_deep_properties,
validate_items_type,
validate_letter_case,
validate_merge_properties,
validate_metadata_presence,
validate_null_type,
validate_object_id,
validate_ref,
validate_schema,
)
from jsonschema import FormatChecker
from jsonschema.validators import Draft202012Validator

schemas = [(path, name, data) for path, name, _, data in walk_json_data(top='schema') if is_json_schema(data)]
metaschema = http_get('https://json-schema.org/draft/2020-12/schema').json()

@pytest.mark.parametrize('path,name,data', schemas)
def test_schema_valid(path, name, data):
validate_json_schema(path, name, data, metaschema)

validator = Draft202012Validator(Draft202012Validator.META_SCHEMA, format_checker=FormatChecker())

@pytest.mark.parametrize('path,name,data', schemas)
def test_schema_valid(path, name, data):
Expand All @@ -21,21 +36,23 @@ def test_schema_valid(path, name, data):
def validate_json_schema(path, name, data, schema):
errors = 0

errors += validate_schema(path, data, schema)
errors += validate_schema(path, data, validator)
errors += validate_array_items(path, data)
errors += validate_items_type(path, data)

# Codelist fields are not yet implemented
# errors += validate_codelist_enum(path, data)
# RDLS does not use camelCase
# errors += validate_letter_case(path, data)

errors += validate_merge_properties(path, data)
errors += validate_ref(path, data)

# Titles and descriptions are not yet added
# errors += validate_metadata_presence(path, data)

errors += validate_object_id(path, jsonref.replace_refs(data))
errors += validate_null_type(path, data, no_null=True)
# RDLS does not disallow deep properties

# Here, we don't add to `errors`, in order to not count these warnings as errors.
# validate_deep_properties(path, data)
validate_deep_properties(path, data)

assert not errors, 'One or more JSON Schema files are invalid. See warnings below.'

0 comments on commit 068112d

Please sign in to comment.