Skip to content

Commit 7690ff2

Browse files
committed
#324 update schema validator and text_downloader
1 parent 3d76642 commit 7690ff2

2 files changed

Lines changed: 7 additions & 9 deletions

File tree

pyQuARC/code/schema_validator.py

Lines changed: 5 additions & 7 deletions
Original file line numberDiff line numberDiff line change
@@ -3,7 +3,7 @@
33
import re
44

55
from io import BytesIO
6-
from jsonschema import Draft7Validator, draft7_format_checker, RefResolver
6+
from jsonschema import Draft7Validator, RefResolver
77
from lxml import etree
88
from urllib.request import pathname2url
99

@@ -90,9 +90,7 @@ def run_json_validator(self, content_to_validate):
9090

9191
resolver = RefResolver.from_schema(schema, store=schema_store)
9292

93-
validator = Draft7Validator(
94-
schema, format_checker=draft7_format_checker, resolver=resolver
95-
)
93+
validator = Draft7Validator(schema, format_checker=Draft7Validator.FORMAT_CHECKER)
9694

9795
for error in sorted(
9896
validator.iter_errors(json.loads(content_to_validate)), key=str
@@ -136,13 +134,13 @@ def _build_errors(error_log, paths):
136134
# For DIF, because the namespace is specified in the metadata file, lxml library
137135
# provides field name concatenated with the namespace,
138136
# the following 3 lines of code removes the namespace
139-
namespaces = re.findall("(\{http[^}]*\})", line)
137+
namespaces = re.findall(r"(\{http[^}]*\})", line)
140138
for namespace in namespaces:
141139
line = line.replace(namespace, "")
142-
field_name = re.search("Element\s'(.*)':", line)[1]
140+
field_name = re.search(r"Element\s'(.*)':", line)[1]
143141
field_paths = [abs_path for abs_path in paths if field_name in abs_path]
144142
field_name = field_paths[0] if len(field_paths) == 1 else field_name
145-
message = re.search("Element\s'.+':\s(\[.*\])?(.*)", line)[2].strip()
143+
message = re.search(r"Element\s'.+':\s(\[.*\])?(.*)", line)[2].strip()
146144
errors.setdefault(field_name, {})["schema"] = {
147145
"message": [f"Error: {message}"],
148146
"valid": False,

tests/test_downloader.py

Lines changed: 2 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -9,11 +9,11 @@ class TestDownloader:
99
def setup_method(self):
1010
self.concept_ids = {
1111
"collection": {
12-
"real": "C1339230297-GES_DISC",
12+
"real": "C1000000010-CDDIS",
1313
"dummy": "C123456-LPDAAC_ECS",
1414
},
1515
"granule": {
16-
"real": "G1370895082-GES_DISC",
16+
"real": "G1001434969-CDDIS",
1717
"dummy": "G1000000002-CMR_PROV",
1818
},
1919
"invalid": "asdfasdf",

0 commit comments

Comments
 (0)