Skip to content
Merged
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
11 changes: 6 additions & 5 deletions pyQuARC/code/schema_validator.py
Original file line number Diff line number Diff line change
Expand Up @@ -3,7 +3,7 @@
import re

from io import BytesIO
from jsonschema import Draft7Validator, draft7_format_checker, RefResolver
from jsonschema import Draft7Validator, RefResolver
from lxml import etree
from urllib.request import pathname2url

Expand Down Expand Up @@ -91,7 +91,7 @@ def run_json_validator(self, content_to_validate):
resolver = RefResolver.from_schema(schema, store=schema_store)

validator = Draft7Validator(
schema, format_checker=draft7_format_checker, resolver=resolver
schema, format_checker=Draft7Validator.FORMAT_CHECKER, resolver=resolver
)

for error in sorted(
Expand Down Expand Up @@ -136,13 +136,14 @@ def _build_errors(error_log, paths):
# For DIF, because the namespace is specified in the metadata file, lxml library
# provides field name concatenated with the namespace,
# the following 3 lines of code removes the namespace
namespaces = re.findall("(\{http[^}]*\})", line)

namespaces = re.findall(r"(\{http[^}]*\})", line)
for namespace in namespaces:
line = line.replace(namespace, "")
field_name = re.search("Element\s'(.*)':", line)[1]
field_name = re.search(r"Element\s'(.*)':", line)[1]
field_paths = [abs_path for abs_path in paths if field_name in abs_path]
field_name = field_paths[0] if len(field_paths) == 1 else field_name
message = re.search("Element\s'.+':\s(\[.*\])?(.*)", line)[2].strip()
message = re.search(r"Element\s'.+':\s(\[.*\])?(.*)", line)[2].strip()
errors.setdefault(field_name, {})["schema"] = {
"message": [f"Error: {message}"],
"valid": False,
Expand Down
19 changes: 18 additions & 1 deletion pyQuARC/schemas/check_messages_override.json
Original file line number Diff line number Diff line change
@@ -1 +1,18 @@
{}
{
"processing_level_description_presence_check": {
"failure": "The Processing Level Description is missing.",
"help": {
"message": "Recommend providing a processing level description, using the EOSDIS processing level descriptions as guidance",
"url": "https://www.earthdata.nasa.gov/learn/earth-observation-data-basics/data-processing-levels"
},
"remediation": "Recommend providing a processing level description, using the EOSDIS processing level descriptions as guidance:\nhttps://www.earthdata.nasa.gov/engage/open-data-services-and-software/data-information-policy/data-levels"
},
"processing_level_description_length_check": {
"failure": "The provided description is less than 50 characters and therefore may be lacking in contextual information.",
"help": {
"message": "Use the EOSDIS Data Processing level description as guidance.",
"url": "https://www.earthdata.nasa.gov/engage/open-data-services-and-software/data-information-policy/data-levels"
},
"remediation": "Recommend providing a more detailed processing level description, using the EOSDIS processing level descriptions as guidance:\nhttps://www.earthdata.nasa.gov/engage/open-data-services-and-software/data-information-policy/data-levels"
}
}
24 changes: 23 additions & 1 deletion pyQuARC/schemas/rules_override.json
Original file line number Diff line number Diff line change
@@ -1 +1,23 @@
{}
{
"processing_level_description_presence_check": {
"rule_name": "Processing Level Description Presence Check",
"fields_to_apply": {
"echo-c": [
{
"fields": [
"Collection/ProcessingLevelDescription"
]
}
],
"umm-c": [
{
"fields": [
"ProcessingLevel/ProcessingLevelDescription"
]
}
]
},
"severity": "info",
"check_id": "one_item_presence_check"
}
}
4 changes: 2 additions & 2 deletions tests/test_downloader.py
Original file line number Diff line number Diff line change
Expand Up @@ -9,11 +9,11 @@ class TestDownloader:
def setup_method(self):
self.concept_ids = {
"collection": {
"real": "C1339230297-GES_DISC",
"real": "C1000000010-CDDIS",
"dummy": "C123456-LPDAAC_ECS",
},
"granule": {
"real": "G1370895082-GES_DISC",
"real": "G1001434969-CDDIS",
"dummy": "G1000000002-CMR_PROV",
},
"invalid": "asdfasdf",
Expand Down