generated from usnistgov/opensource-repo
-
Notifications
You must be signed in to change notification settings - Fork 3
Commit
This commit does not belong to any branch on this repository, and may belong to a fork outside of the repository.
first stab at specific DAP review test
- Loading branch information
Showing
5 changed files
with
309 additions
and
0 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,5 @@ | ||
""" | ||
A module for reviewing the completeness of a draft NERDm record. | ||
""" |
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,13 @@ | ||
""" | ||
Base definitions and implementations for review tests and infrastructure | ||
This module reuses the testing infrastructure from :py:mod:`nistoar.pdr.preserve.bagit.validate`. | ||
""" | ||
from nistoar.pdr.utils.validate import ( | ||
Validator, ValidatorBase, ValidationResults, ValidationIssue, AggregatedValidator, | ||
ERROR, WARN, REC, ALL, PROB | ||
) | ||
|
||
__all__ = [ "Validator", "ValidatorBase", "ValidationResults", "ValidationIssue", "AggregatedValidator", | ||
"ERROR", "WARN", "REC", "ALL", "PROB" ] | ||
|
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,30 @@ | ||
""" | ||
NERDm tests for the minimum required elements | ||
""" | ||
from .base import ValidatorBase, ValidationResults, ALL | ||
|
||
class DAPNERDmValidator(ValidatorBase): | ||
""" | ||
a validator that examines the content of the NERDm data for completeness and syntactic correctness. | ||
""" | ||
profile = ("NERDm-DAP", "0.7") | ||
|
||
def __init__(self, config=None): | ||
super(DAPNERDmValidator, self).__init__(config) | ||
|
||
def _target_name(self, nerd): | ||
return nerd.get("@id", "mds:unkn") | ||
|
||
def test_simple_props(self, nerd, want=ALL, out=None, **kw): | ||
""" | ||
Test that we have values for the simple user-supplied properties required by a NERDm publication | ||
""" | ||
if not out: | ||
out = ValidationResults(self._target_name(nerd), want) | ||
|
||
for prop in "title description keyword".split(): | ||
t = self._err(f"1.1#{prop}", f"A value for {prop} is required") | ||
t = out._add_applied(t, bool(nerd.get(prop))) | ||
|
||
return out | ||
|
217 changes: 217 additions & 0 deletions
217
python/tests/nistoar/midas/dap/data/mdssip/mdst:1491/nerdm.json
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,217 @@ | ||
{ | ||
"@context": "https://data.nist.gov/od/dm/nerdm-pub-context.jsonld", | ||
"_schema": "https://data.nist.gov/od/dm/nerdm-schema/v0.7#", | ||
"_extensionSchemas": [ | ||
"https://data.nist.gov/od/dm/nerdm-schema/pub/v0.2#/definitions/PublicDataResource" | ||
], | ||
"@type": [ | ||
"nrdp:PublicDataResource", | ||
"dcat:Resource" | ||
], | ||
"@id": "ark:/88434/mdst-1491", | ||
"doi": "doi:10.18434/mdst-1491", | ||
"title": "OptSortSph: Sorting Spherical Dielectric Particles in a Standing-Wave Interference Field", | ||
"version": "1.0.0", | ||
"contactPoint": { | ||
"fn": "Zachary Levine", | ||
"hasEmail": "mailto:[email protected]" | ||
}, | ||
"description": [ | ||
"Software to predict the optical sorting of particles in a standing-wave laser interference field" | ||
], | ||
"keyword": [ | ||
"optical sorting", | ||
"laser interference field", | ||
"nanoparticles", | ||
"convection of fluid" | ||
], | ||
"topic": [ | ||
{ | ||
"@type": "Concept", | ||
"scheme": "https://data.nist.gov/od/dm/nist-themes/v1.1", | ||
"tag": "Physics: Optical physics" | ||
} | ||
], | ||
"references": [ | ||
{ | ||
"@type": [ | ||
"deo:BibliographicReference" | ||
], | ||
"@id": "#ref:10.1364/OE.24.014100", | ||
"refType": "IsReferencedBy", | ||
"location": "https://doi.org/10.1364/OE.24.014100", | ||
"_extensionSchemas": [ | ||
"https://data.nist.gov/od/dm/nerdm-schema/v0.2#/definitions/DCiteReference" | ||
] | ||
} | ||
], | ||
"accessLevel": "public", | ||
"components": [ | ||
{ | ||
"accessURL": "https://doi.org/10.18434/T4SW26", | ||
"description": "Software to predict the optical sorting of particles in a standing-wave laser interference field", | ||
"format": "Digital Object Identifier, a persistent identifier", | ||
"mediaType": "application/zip", | ||
"title": "DOI access for OptSortSph: Sorting Spherical Dielectric Particles in a Standing-Wave Interference Field", | ||
"@type": [ | ||
"nrd:Hidden", | ||
"dcat:Distribution" | ||
], | ||
"@id": "#doi:10.18434/T4SW26" | ||
}, | ||
{ | ||
"description": "First trial of experiment", | ||
"filepath": "trial1.json", | ||
"checksum": { | ||
"hash": "d155d99281ace123351a311084cd8e34edda6a9afcddd76eb039bad479595ec9", | ||
"algorithm": { | ||
"tag": "sha256", | ||
"@type": "Thing" | ||
} | ||
}, | ||
"title": "JSON version of the Mathematica notebook", | ||
"mediaType": "application/json", | ||
"downloadURL": "https://data.nist.gov/od/ds/3A1EE2F169DD3B8CE0531A570681DB5D1491/trial1.json", | ||
"size": 69, | ||
"@id": "cmps/trial1.json", | ||
"@type": [ | ||
"nrdp:DataFile", | ||
"nrdp:DownloadableFile", | ||
"dcat:Distribution" | ||
], | ||
"_extensionSchemas": [ | ||
"https://data.nist.gov/od/dm/nerdm-schema/pub/v0.2#/definitions/DataFile" | ||
] | ||
}, | ||
{ | ||
"description": "Second trial of experiment", | ||
"filepath": "trial2.json", | ||
"checksum": { | ||
"hash": "d5eed5092f409bce7e88d057eb98b376534b372f9f6b7c14e57744b259c65d35", | ||
"algorithm": { | ||
"tag": "sha256", | ||
"@type": "Thing" | ||
} | ||
}, | ||
"title": "JSON version of the Mathematica notebook", | ||
"mediaType": "application/json", | ||
"downloadURL": "https://data.nist.gov/od/ds/3A1EE2F169DD3B8CE0531A570681DB5D1491/trial2.json", | ||
"size": 69, | ||
"@id": "cmps/trial2.json", | ||
"@type": [ | ||
"nrdp:DataFile", | ||
"nrdp:DownloadableFile", | ||
"dcat:Distribution" | ||
], | ||
"_extensionSchemas": [ | ||
"https://data.nist.gov/od/dm/nerdm-schema/pub/v0.2#/definitions/DataFile" | ||
] | ||
}, | ||
{ | ||
"description": "SHA-256 checksum value for trial1.json", | ||
"@id": "cmps/trial1.json.sha256", | ||
"_extensionSchemas": [ | ||
"https://data.nist.gov/od/dm/nerdm-schema/pub/v0.2#/definitions/ChecksumFile" | ||
], | ||
"algorithm": { | ||
"tag": "sha256", | ||
"@type": "Thing" | ||
}, | ||
"filepath": "trial1.json.sha256", | ||
"checksum": { | ||
"hash": "6379ac00d41f4b3340420cc5a8e17a10427f9afef2ee6355f9502507e6f6f647", | ||
"algorithm": { | ||
"tag": "sha256", | ||
"@type": "Thing" | ||
} | ||
}, | ||
"mediaType": "application/octet-stream", | ||
"downloadURL": "https://data.nist.gov/od/ds/3A1EE2F169DD3B8CE0531A570681DB5D1491/trial1.json.sha256", | ||
"describes": "cmps/trial1.json", | ||
"size": 90, | ||
"@type": [ | ||
"nrdp:ChecksumFile", | ||
"nrdp:DownloadableFile", | ||
"dcat:Distribution" | ||
], | ||
"valid": true | ||
}, | ||
{ | ||
"filepath": "trial3", | ||
"@id": "cmps/trial3", | ||
"@type": [ | ||
"nrdp:Subcollection" | ||
], | ||
"_extensionSchemas": [ | ||
"https://data.nist.gov/od/dm/nerdm-schema/pub/v0.2#/definitions/Subcollection" | ||
] | ||
}, | ||
{ | ||
"filepath": "trial3/trial3a.json", | ||
"checksum": { | ||
"hash": "7b58010c841b7748a48a7ac6366258d5b5a8d23d756951b6059c0e80daad516b", | ||
"algorithm": { | ||
"tag": "sha256", | ||
"@type": "Thing" | ||
} | ||
}, | ||
"mediaType": "application/json", | ||
"downloadURL": "https://data.nist.gov/od/ds/3A1EE2F169DD3B8CE0531A570681DB5D1491/trial3/trial3a.json", | ||
"size": 70, | ||
"@id": "cmps/trial3/trial3a.json", | ||
"@type": [ | ||
"nrdp:DataFile", | ||
"nrdp:DownloadableFile", | ||
"dcat:Distribution" | ||
], | ||
"_extensionSchemas": [ | ||
"https://data.nist.gov/od/dm/nerdm-schema/pub/v0.2#/definitions/DataFile" | ||
] | ||
}, | ||
{ | ||
"description": "SHA-256 checksum value for trial3a.json", | ||
"@id": "cmps/trial3/trial3a.json.sha256", | ||
"_extensionSchemas": [ | ||
"https://data.nist.gov/od/dm/nerdm-schema/pub/v0.2#/definitions/ChecksumFile" | ||
], | ||
"algorithm": { | ||
"tag": "sha256", | ||
"@type": "Thing" | ||
}, | ||
"filepath": "trial3/trial3a.json.sha256", | ||
"checksum": { | ||
"hash": "997bd4d709aae76996934e0d507e647598cc160ffeafc8938b2d8519a2f95931", | ||
"algorithm": { | ||
"tag": "sha256", | ||
"@type": "Thing" | ||
} | ||
}, | ||
"mediaType": "application/octet-stream", | ||
"downloadURL": "https://data.nist.gov/od/ds/3A1EE2F169DD3B8CE0531A570681DB5D1491/trial3/trial3a.json.sha256", | ||
"describes": "cmps/trial3/trial3a.json", | ||
"size": 65, | ||
"@type": [ | ||
"nrdp:ChecksumFile", | ||
"nrdp:DownloadableFile", | ||
"dcat:Distribution" | ||
], | ||
"valid": false | ||
}, | ||
{ | ||
"description": "Simulation of experiment", | ||
"filepath": "sim++.json", | ||
"title": "JSON version of the Mathematica notebook", | ||
"mediaType": "application/json", | ||
"downloadURL": "https://s3.amazonaws.com/nist-midas/1491/sim%2B%2B.json", | ||
"@id": "cmps/sim++.json", | ||
"@type": [ | ||
"nrdp:DataFile", | ||
"nrdp:DownloadableFile", | ||
"dcat:Distribution" | ||
], | ||
"_extensionSchemas": [ | ||
"https://data.nist.gov/od/dm/nerdm-schema/pub/v0.2#/definitions/DataFile" | ||
] | ||
} | ||
] | ||
} |
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,44 @@ | ||
import os, sys, pdb, json | ||
import unittest as test | ||
from pathlib import Path | ||
|
||
import nistoar.midas.dap.review.nerdm as rev | ||
import nistoar.pdr.utils.validate as base | ||
from nistoar.pdr.utils.io import read_nerd | ||
|
||
testdir = Path(__file__).parent | ||
datadir = testdir.parent / "data" | ||
sipdir = datadir / "mdssip"/"mdst:1491" | ||
|
||
class TestDAPNERDmValidator(test.TestCase): | ||
|
||
def setUp(self): | ||
self.nerd = read_nerd(sipdir/"nerdm.json") | ||
self.val = rev.DAPNERDmValidator() | ||
|
||
def test_test_simple_props(self): | ||
res = self.val.test_simple_props(self.nerd) | ||
self.assertEqual(res.count_applied(), 3) | ||
self.assertEqual(res.count_passed(), 3) | ||
|
||
self.nerd["description"] = "" | ||
del self.nerd["keyword"] | ||
|
||
res = self.val.test_simple_props(self.nerd) | ||
self.assertEqual(res.count_applied(), 3) | ||
self.assertEqual(res.count_passed(), 1) | ||
self.assertIn("#title", res.passed()[0].label) | ||
self.assertEqual(res.count_failed(), 2) | ||
|
||
|
||
|
||
|
||
|
||
|
||
|
||
|
||
if __name__ == '__main__': | ||
test.main() | ||
|
||
|
||
|