Skip to content

Commit f50a6e6

Browse files
committed
Some tests fixed; one test issue outstanding #591
1 parent f8f941e commit f50a6e6

24 files changed

+80
-37
lines changed

isatools/convert/isatab2cedar.py

Lines changed: 17 additions & 4 deletions
Original file line numberDiff line numberDiff line change
@@ -8,9 +8,10 @@
88
import os
99
from os import listdir
1010
from os.path import isdir, join
11+
from pathlib import Path
1112
from uuid import uuid4
1213

13-
from jsonschema import Draft4Validator
14+
from jsonschema import Draft4Validator, FormatChecker
1415
from referencing.jsonschema import DRAFT4
1516
from referencing import Registry
1617

@@ -43,9 +44,21 @@ def createCEDARjson(self, work_dir, json_dir, inv_identifier):
4344
investigation_schema = json.load(json_fp)
4445
if investigation_schema is None:
4546
raise IOError("Could not load schema from {}".format(join(CEDAR_SCHEMA_PATH, schema_file)))
46-
schema = DRAFT4.create_resource(investigation_schema)
47-
registry = Registry.with_resource(investigation_schema['id'], schema)
48-
validator = Draft4Validator(investigation_schema, registry=registry)
47+
48+
resources = []
49+
schemas_dir = Path(CEDAR_SCHEMA_PATH)
50+
investigation_schema_path = Path(join(CEDAR_SCHEMA_PATH, schema_file))
51+
52+
for p in sorted(schemas_dir.glob("*.json")):
53+
contents = json.loads(p.read_text(encoding="utf-8"))
54+
resource = DRAFT4.create_resource(contents)
55+
resources.append((p.resolve().as_uri(), resource))
56+
57+
registry = Registry().with_resources(resources)
58+
main_uri = investigation_schema_path.resolve().as_uri()
59+
print(registry.contents(main_uri))
60+
schema_ref = {"$ref": main_uri, "$schema": "http://json-schema.org/draft-04/schema"}
61+
validator = Draft4Validator(schema_ref, registry=registry, format_checker=FormatChecker())
4962

5063
isa_tab = isatab_parser.parse(work_dir)
5164

isatools/convert/isatab2json.py

Lines changed: 23 additions & 6 deletions
Original file line numberDiff line numberDiff line change
@@ -8,11 +8,12 @@
88
import re
99
from enum import Enum
1010
from os.path import join
11+
from pathlib import Path
1112
from uuid import uuid4
1213

13-
from jsonschema import Draft4Validator
14+
from jsonschema import Draft202012Validator, FormatChecker
1415
from referencing import Registry
15-
from referencing.jsonschema import DRAFT4
16+
from referencing.jsonschema import DRAFT202012
1617

1718
from isatools import isatab
1819
from isatools.io.isatab_parser import parse
@@ -141,10 +142,26 @@ def convert(self, work_dir):
141142

142143
# validate json
143144
with open(join(SCHEMAS_PATH, INVESTIGATION_SCHEMA)) as json_fp:
144-
investigation_schema = json.load(json_fp)
145-
schema = DRAFT4.create_resource(investigation_schema)
146-
registry = Registry.with_resource(investigation_schema['id'], schema)
147-
validator = Draft4Validator(investigation_schema, registry=registry)
145+
#investigation_schema = json.load(json_fp)
146+
#schema = DRAFT4.create_resource(investigation_schema)
147+
#registry = Registry.with_resource(investigation_schema['id'], schema)
148+
#validator = Draft4Validator(investigation_schema, registry=registry)
149+
#validator.validate(isa_json)
150+
151+
resources = []
152+
schemas_dir = Path(SCHEMAS_PATH)
153+
investigation_schema_path = Path(join(SCHEMAS_PATH, INVESTIGATION_SCHEMA))
154+
155+
for p in sorted(schemas_dir.glob("*.json")):
156+
contents = json.loads(p.read_text(encoding="utf-8"))
157+
resource = DRAFT202012.create_resource(contents)
158+
resources.append((p.resolve().as_uri(), resource))
159+
160+
registry = Registry().with_resources(resources)
161+
main_uri = investigation_schema_path.resolve().as_uri()
162+
print(registry.contents(main_uri))
163+
schema_ref = {"$ref": main_uri, "$schema": "https://json-schema.org/draft/2020-12/schema"}
164+
validator = Draft202012Validator(schema_ref, registry=registry, format_checker=FormatChecker())
148165
validator.validate(isa_json)
149166

150167
log.info("Conversion finished")

isatools/isajson/validate.py

Lines changed: 19 additions & 6 deletions
Original file line numberDiff line numberDiff line change
@@ -13,10 +13,11 @@
1313
import os
1414
import re
1515
from io import StringIO
16+
from pathlib import Path
1617

17-
from jsonschema import Draft4Validator, ValidationError
18+
from jsonschema import Draft4Validator, ValidationError, Draft202012Validator, FormatChecker
1819
from referencing import Registry
19-
from referencing.jsonschema import DRAFT4
20+
from referencing.jsonschema import DRAFT4, DRAFT202012
2021

2122
from isatools.isajson.load import load
2223

@@ -545,15 +546,27 @@ def check_utf8(fp):
545546
raise SystemError()
546547

547548

549+
548550
def check_isa_schemas(isa_json, investigation_schema_path):
549551
"""Used for rule 0003 and 4003"""
550552
try:
551553
with open(investigation_schema_path) as fp:
552-
investigation_schema = json.load(fp)
553-
schema = DRAFT4.create_resource(investigation_schema)
554-
registry = Registry.with_resource(investigation_schema['id'], schema)
555-
validator = Draft4Validator(investigation_schema, registry=registry)
554+
resources = []
555+
investigation_schema_path = Path(investigation_schema_path)
556+
schemas_dir = investigation_schema_path.parent
557+
558+
for p in sorted(schemas_dir.glob("*.json")):
559+
contents = json.loads(p.read_text(encoding="utf-8"))
560+
resource = DRAFT202012.create_resource(contents)
561+
resources.append((p.resolve().as_uri(), resource))
562+
563+
registry = Registry().with_resources(resources)
564+
main_uri = investigation_schema_path.resolve().as_uri()
565+
print(registry.contents(main_uri))
566+
schema_ref = {"$ref": main_uri, "$schema": "https://json-schema.org/draft/2020-12/schema"}
567+
validator = Draft202012Validator(schema_ref, registry=registry, format_checker=FormatChecker())
556568
validator.validate(isa_json)
569+
557570
except ValidationError as ve:
558571
errors.append({"message": "Invalid JSON against ISA-JSON schemas", "supplemental": str(ve), "code": 3})
559572
log.fatal("(F) The JSON does not validate against the provided ISA-JSON schemas!")

isatools/resources/schemas/isa_model_version_1_0_schemas/core/assay_schema.json

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -1,5 +1,5 @@
11
{
2-
"id": "https://raw.githubusercontent.com/ISA-tools/isa-api/master/isatools/resources/schemas/isa_model_version_1_0_schemas/core/assay_schema.json",
2+
"$id": "https://raw.githubusercontent.com/ISA-tools/isa-api/master/isatools/resources/schemas/isa_model_version_1_0_schemas/core/assay_schema.json",
33
"$schema": "https://json-schema.org/draft/2020-12/schema",
44
"title": "ISA Assay JSON Schema",
55
"name": "ISA Assay JSON Schema",

isatools/resources/schemas/isa_model_version_1_0_schemas/core/comment_schema.json

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -1,5 +1,5 @@
11
{
2-
"id": "https://raw.githubusercontent.com/ISA-tools/isa-api/master/isatools/resources/schemas/isa_model_version_1_0_schemas/core/comment_schema.json",
2+
"$id": "https://raw.githubusercontent.com/ISA-tools/isa-api/master/isatools/resources/schemas/isa_model_version_1_0_schemas/core/comment_schema.json",
33
"$schema": "https://json-schema.org/draft/2020-12/schema",
44
"title": "ISA Comment schema - it corresponds to ISA Comment[] construct",
55
"name" : "ISA Comment schema",

isatools/resources/schemas/isa_model_version_1_0_schemas/core/data_schema.json

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -1,5 +1,5 @@
11
{
2-
"id": "https://raw.githubusercontent.com/ISA-tools/isa-api/master/isatools/resources/schemas/isa_model_version_1_0_schemas/core/data_schema.json",
2+
"$id": "https://raw.githubusercontent.com/ISA-tools/isa-api/master/isatools/resources/schemas/isa_model_version_1_0_schemas/core/data_schema.json",
33
"$schema": "https://json-schema.org/draft/2020-12/schema",
44
"title": "ISA Data schema",
55
"name" : "ISA Data schema",

isatools/resources/schemas/isa_model_version_1_0_schemas/core/factor_schema.json

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -1,5 +1,5 @@
11
{
2-
"id": "https://raw.githubusercontent.com/ISA-tools/isa-api/master/isatools/resources/schemas/isa_model_version_1_0_schemas/core/factor_schema.json",
2+
"$id": "https://raw.githubusercontent.com/ISA-tools/isa-api/master/isatools/resources/schemas/isa_model_version_1_0_schemas/core/factor_schema.json",
33
"$schema": "https://json-schema.org/draft/2020-12/schema",
44
"title": "ISA Factor schema",
55
"name": "ISA Factor schema",

isatools/resources/schemas/isa_model_version_1_0_schemas/core/factor_value_schema.json

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -1,5 +1,5 @@
11
{
2-
"id": "https://raw.githubusercontent.com/ISA-tools/isa-api/master/isatools/resources/schemas/isa_model_version_1_0_schemas/core/factor_value_schema.json",
2+
"$id": "https://raw.githubusercontent.com/ISA-tools/isa-api/master/isatools/resources/schemas/isa_model_version_1_0_schemas/core/factor_value_schema.json",
33
"$schema": "https://json-schema.org/draft/2020-12/schema",
44
"title": "ISA Factor Value schema",
55
"name": "ISA Factor Value schema",

isatools/resources/schemas/isa_model_version_1_0_schemas/core/investigation_schema.json

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -1,5 +1,5 @@
11
{
2-
"id": "https://raw.githubusercontent.com/ISA-tools/isa-api/master/isatools/resources/schemas/isa_model_version_1_0_schemas/core/investigation_schema.json",
2+
"$id": "https://raw.githubusercontent.com/ISA-tools/isa-api/master/isatools/resources/schemas/isa_model_version_1_0_schemas/core/investigation_schema.json",
33
"$schema": "https://json-schema.org/draft/2020-12/schema",
44
"title" : "ISA investigation schema",
55
"name" : "ISA Investigation schema",

isatools/resources/schemas/isa_model_version_1_0_schemas/core/material_attribute_schema.json

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -1,5 +1,5 @@
11
{
2-
"id": "https://raw.githubusercontent.com/ISA-tools/isa-api/master/isatools/resources/schemas/isa_model_version_1_0_schemas/core/material_attribute_schema.json",
2+
"$id": "https://raw.githubusercontent.com/ISA-tools/isa-api/master/isatools/resources/schemas/isa_model_version_1_0_schemas/core/material_attribute_schema.json",
33
"$schema": "https://json-schema.org/draft/2020-12/schema",
44
"title" : "ISA material attribute schema",
55
"name" : "ISA Material Attribute schema",

0 commit comments

Comments
 (0)