-
Notifications
You must be signed in to change notification settings - Fork 10
Commit
This commit does not belong to any branch on this repository, and may belong to a fork outside of the repository.
- Loading branch information
1 parent
b00b2da
commit 5578e5b
Showing
5 changed files
with
228 additions
and
40 deletions.
There are no files selected for viewing
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,132 @@ | ||
{ | ||
"$schema": "http://json-schema.org/draft-07/schema#", | ||
"type": "object", | ||
"properties": { | ||
"@context": { | ||
"type": "string", | ||
"format": "uri" | ||
}, | ||
"@graph": { | ||
"type": "array", | ||
"items": { | ||
"type": "object", | ||
"properties": { | ||
"@id": { | ||
"type": "string" | ||
}, | ||
"@type": { | ||
"type": "string" | ||
}, | ||
"about": { | ||
"type": "object", | ||
"properties": { | ||
"@id": { | ||
"type": "string" | ||
} | ||
} | ||
}, | ||
"conformsTo": { | ||
"type": "object", | ||
"properties": { | ||
"@id": { | ||
"type": "string", | ||
"format": "uri" | ||
} | ||
} | ||
}, | ||
"dateCreated": { | ||
"type": "string", | ||
"format": "date-time" | ||
}, | ||
"sdPublisher": { | ||
"type": "object", | ||
"properties": { | ||
"@id": { | ||
"type": "string" | ||
} | ||
} | ||
}, | ||
"version": { | ||
"type": "string" | ||
}, | ||
"author": { | ||
"type": "object", | ||
"properties": { | ||
"@id": { | ||
"type": "string" | ||
} | ||
} | ||
}, | ||
"dateModified": { | ||
"type": "string", | ||
"format": "date-time" | ||
}, | ||
"name": { | ||
"type": "string" | ||
}, | ||
"encodingFormat": { | ||
"type": "string" | ||
}, | ||
"url": { | ||
"type": "string", | ||
"format": "uri" | ||
}, | ||
"genre": { | ||
"type": "string" | ||
}, | ||
"creativeWorkStatus": { | ||
"type": "string" | ||
}, | ||
"identifier": { | ||
"type": "string" | ||
}, | ||
"keywords": { | ||
"type": "string" | ||
}, | ||
"hasPart": { | ||
"type": "array", | ||
"items": { | ||
"type": "object", | ||
"properties": { | ||
"@id": { | ||
"type": "string" | ||
} | ||
} | ||
} | ||
}, | ||
"comment": { | ||
"type": "array", | ||
"items": { | ||
"type": "object", | ||
"properties": { | ||
"@id": { | ||
"type": "string" | ||
}, | ||
"@type": { | ||
"type": "string" | ||
}, | ||
"dateCreated": { | ||
"type": "string", | ||
"format": "date-time" | ||
}, | ||
"text": { | ||
"type": "string" | ||
}, | ||
"author": { | ||
"type": "object", | ||
"properties": { | ||
"@id": { | ||
"type": "string" | ||
} | ||
} | ||
} | ||
} | ||
} | ||
} | ||
}, | ||
"required": ["@id", "@type"] | ||
} | ||
} | ||
}, | ||
"required": ["@context", "@graph"] | ||
} |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,49 @@ | ||
#!/usr/bin/python3 | ||
""" | ||
Validate if rocrate of pypi can open and parse it. This is a test if we follow general ro-crate guidelines. | ||
https://pypi.org/project/rocrate/ | ||
""" | ||
import os | ||
import json | ||
import unittest | ||
from pathlib import Path | ||
from zipfile import ZIP_DEFLATED | ||
from zipfile import ZipFile | ||
from jsonschema import Draft202012Validator | ||
|
||
LABEL = 'schema' | ||
METADATA_FILE = 'ro-crate-metadata.json' | ||
|
||
class Test_1(unittest.TestCase): | ||
""" | ||
derived class for this test | ||
""" | ||
def test_main(self): | ||
""" | ||
main function | ||
""" | ||
# log-file | ||
if Path('tests/logging.json').exists(): | ||
logJson = json.load(open('tests/logging.json')) | ||
else: | ||
logJson = {} | ||
|
||
schema = json.load(open('tests/schema.json', 'r', encoding='utf-8')) | ||
validator = Draft202012Validator(schema=schema) | ||
validator.check_schema(schema=schema) | ||
success = True | ||
for root, _, files in os.walk(".", topdown=False): | ||
for name in files: | ||
if not name.endswith('.eln'): | ||
continue | ||
fileName = os.path.join(root, name) | ||
print(f'\nInspect: {name}') | ||
with ZipFile(fileName, 'r', compression=ZIP_DEFLATED) as elnFile: | ||
metadataJsonFile = [i for i in elnFile.namelist() if i.endswith(METADATA_FILE)][0] | ||
metadataContent = json.loads(elnFile.read(metadataJsonFile)) | ||
for error in sorted(validator.iter_errors(metadataContent), key=str): | ||
print(f'- {error.message}') | ||
success = False | ||
logJson[fileName] = logJson.get(fileName,{}) | {LABEL: success} | ||
json.dump(logJson, open('tests/logging.json', 'w')) | ||
assert success |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters