Skip to content

Commit

Permalink
tests: Move metaschema to this repository
Browse files Browse the repository at this point in the history
We want to make more changes to it soon, and
we may as well not be dependent on a external repository
  • Loading branch information
jarofgreen committed Nov 4, 2021
1 parent 84221d3 commit 8dffb7b
Show file tree
Hide file tree
Showing 3 changed files with 274 additions and 11 deletions.
267 changes: 267 additions & 0 deletions tests/schema/meta-schema.json
Original file line number Diff line number Diff line change
@@ -0,0 +1,267 @@
{
"id": "http://json-schema.org/draft-04/schema#",
"$schema": "http://json-schema.org/draft-04/schema#",
"description": "Core schema meta-schema",
"definitions": {
"schemaArray": {
"type": "array",
"minItems": 1,
"items": {
"$ref": "#"
}
},
"positiveInteger": {
"type": "integer",
"minimum": 0
},
"positiveIntegerDefault0": {
"allOf": [
{
"$ref": "#/definitions/positiveInteger"
},
{
"default": 0
}
]
},
"simpleTypes": {
"enum": [
"array",
"boolean",
"integer",
"null",
"number",
"object",
"string"
]
},
"stringArray": {
"type": "array",
"items": {
"type": "string"
},
"minItems": 1,
"uniqueItems": true
}
},
"type": "object",
"properties": {
"id": {
"type": "string"
},
"$schema": {
"type": "string"
},
"title": {
"type": "string"
},
"description": {
"type": "string"
},
"default": {},
"multipleOf": {
"type": "number",
"minimum": 0,
"exclusiveMinimum": true
},
"maximum": {
"type": "number"
},
"exclusiveMaximum": {
"type": "boolean",
"default": false
},
"minimum": {
"type": "number"
},
"exclusiveMinimum": {
"type": "boolean",
"default": false
},
"maxLength": {
"$ref": "#/definitions/positiveInteger"
},
"minLength": {
"$ref": "#/definitions/positiveIntegerDefault0"
},
"pattern": {
"type": "string",
"format": "regex"
},
"additionalItems": {
"anyOf": [
{
"type": "boolean"
},
{
"$ref": "#"
}
],
"default": {}
},
"items": {
"anyOf": [
{
"$ref": "#"
},
{
"$ref": "#/definitions/schemaArray"
}
],
"default": {}
},
"maxItems": {
"$ref": "#/definitions/positiveInteger"
},
"minItems": {
"$ref": "#/definitions/positiveIntegerDefault0"
},
"uniqueItems": {
"type": "boolean",
"default": false
},
"maxProperties": {
"$ref": "#/definitions/positiveInteger"
},
"minProperties": {
"$ref": "#/definitions/positiveIntegerDefault0"
},
"required": {
"$ref": "#/definitions/stringArray"
},
"additionalProperties": {
"anyOf": [
{
"type": "boolean"
},
{
"$ref": "#"
}
],
"default": {}
},
"definitions": {
"type": "object",
"additionalProperties": {
"$ref": "#"
},
"default": {}
},
"properties": {
"type": "object",
"additionalProperties": {
"$ref": "#"
},
"default": {}
},
"patternProperties": {
"type": "object",
"additionalProperties": {
"$ref": "#"
},
"default": {}
},
"dependencies": {
"type": "object",
"additionalProperties": {
"anyOf": [
{
"$ref": "#"
},
{
"$ref": "#/definitions/stringArray"
}
]
}
},
"enum": {
"type": "array",
"minItems": 1,
"uniqueItems": true
},
"type": {
"anyOf": [
{
"$ref": "#/definitions/simpleTypes"
},
{
"type": "array",
"items": {
"$ref": "#/definitions/simpleTypes"
},
"minItems": 1,
"uniqueItems": true
}
]
},
"format": {
"type": "string"
},
"allOf": {
"$ref": "#/definitions/schemaArray"
},
"anyOf": {
"$ref": "#/definitions/schemaArray"
},
"oneOf": {
"$ref": "#/definitions/schemaArray"
},
"not": {
"$ref": "#"
},
"$ref": {
"type": "string"
},
"omitWhenMerged": {
"type": "boolean",
"default": false
},
"deprecated": {
"type": "object",
"additionalProperties": false,
"required": [
"deprecatedVersion",
"description"
],
"properties": {
"deprecatedVersion": {
"type": "string"
},
"description": {
"type": "string"
}
}
},
"codelist": {
"type": "string"
},
"openCodelist": {
"type": "boolean",
"default": false
},
"wholeListMerge": {
"type": "boolean",
"default": false
},
"versionId": {
"type": "boolean",
"default": false
},
"version": {
"type": "string"
},
"propertyOrder": {
"type": "integer"
}
},
"dependencies": {
"exclusiveMaximum": [
"maximum"
],
"exclusiveMinimum": [
"minimum"
]
},
"default": {},
"additionalProperties": false
}
1 change: 1 addition & 0 deletions tests/test_data.py
Original file line number Diff line number Diff line change
Expand Up @@ -439,6 +439,7 @@ def test_all_examples_and_data_files_are_used():
files_used.extend(test_valid_statement_json_parametrize_data)
files_used.extend(test_valid_package_json_parametrize_data)
files_used.extend([a[0] for a in test_invalid_statement_json_parametrize_data])
files_used.append('schema/meta-schema.json')
for data in test_invalid_package_json_parametrize_data:
if data[0]:
files_used.append(data[0])
Expand Down
17 changes: 6 additions & 11 deletions tests/test_json.py
Original file line number Diff line number Diff line change
@@ -1,4 +1,4 @@
from bods_validate import absolute_path_to_source_schema_dir
from bods_validate import absolute_path_to_source_schema_dir, this_dir

from warnings import warn
from collections import Counter
Expand All @@ -7,9 +7,10 @@
from jscc.testing.filesystem import walk_json_data, walk_csv_data
from jscc.schema import is_json_schema
from jscc.testing.checks import validate_items_type, validate_letter_case, validate_schema
from jscc.testing.util import http_get

import pytest
import os
import json


def test_empty():
Expand All @@ -32,15 +33,9 @@ def test_invalid_json():
)


schemas = [(path, name, data) for path, name, _, data in walk_json_data() if is_json_schema(data)]
metaschema = http_get("https://standard.open-contracting.org/schema/1__1__4/meta-schema.json").json()

metaschema["properties"]["version"] = {
"type": "string",
}
metaschema["properties"]["propertyOrder"] = {
"type": "integer",
}
schemas = [(path, name, data) for path, name, _, data in walk_json_data() if is_json_schema(data) and not path.endswith('tests/schema/meta-schema.json')]
with open(os.path.join(this_dir, 'schema', 'meta-schema.json')) as fp:
metaschema = json.load(fp)


@pytest.mark.parametrize("path,name,data", schemas)
Expand Down

0 comments on commit 8dffb7b

Please sign in to comment.