This repository has been archived by the owner on Dec 13, 2019. It is now read-only.
-
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.
Merge pull request #64 from harryhoch/master
basic validation test
- Loading branch information
Showing
6 changed files
with
111 additions
and
22 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 |
---|---|---|
@@ -1,3 +1,4 @@ | ||
__pycache__ | ||
.gitignore | ||
*~ | ||
*~ | ||
*# |
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 |
---|---|---|
@@ -1,25 +1,6 @@ | ||
language: python | ||
python: | ||
- "3.4" | ||
|
||
before_script: | ||
- mkdir -p bin | ||
- export PATH=$PATH:$PWD/bin | ||
- wget http:https://build.berkeleybop.org/userContent/owltools/owltools -O bin/owltools | ||
- wget http:https://build.berkeleybop.org/userContent/owltools/ontology-release-runner -O bin/ontology-release-runner | ||
- wget http:https://build.berkeleybop.org/userContent/owltools/owltools-runner-all.jar -O bin/owltools-runner-all.jar | ||
- wget http:https://build.berkeleybop.org/userContent/owltools/owltools-oort-all.jar -O bin/owltools-oort-all.jar | ||
- chmod +x bin/* | ||
|
||
# command to run tests | ||
script: make test | ||
|
||
# whitelist | ||
branches: | ||
only: | ||
- master | ||
|
||
notifications: | ||
email: | ||
- [email protected] | ||
install: "pip install -r requirements.txt" | ||
script: sh test/scriptrunner.sh | ||
|
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,2 @@ | ||
jsonschema | ||
python_jsonschema_objects |
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,36 @@ | ||
import unittest | ||
import os | ||
import json | ||
from jsonschema import validate, ValidationError, SchemaError,Draft4Validator | ||
import python_jsonschema_objects as jsonobjects | ||
from python_jsonschema_objects import ValidationError as ValidationException | ||
|
||
|
||
|
||
class ValidatorTestCase(unittest.TestCase): | ||
""" | ||
Test various json validators, jsonschema seems to be a popular | ||
lib, warlock and python-jsonschema-objects are build off | ||
of jsonschema and also include json to python object mappers | ||
The goal of this is to experiment with library options but these | ||
could eventually be integrated into the phenopacket python api | ||
As a first pass, testing that the journal example is incorrect | ||
and the rest are correct. These could be expanded in the future | ||
as appropriate | ||
""" | ||
|
||
def test_valid_schema(self): | ||
|
||
schema_path = "../schema/phenopacket-schema.json" | ||
|
||
schema_fh = open(os.path.join(os.path.dirname(__file__), schema_path), 'r') | ||
schema = json.load(schema_fh) | ||
schema_fh.close() | ||
|
||
## call validator | ||
Draft4Validator.check_schema(schema) | ||
|
||
if __name__ == '__main__': | ||
unittest.main() |
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,67 @@ | ||
import unittest | ||
import os | ||
import json | ||
from jsonschema import validate, ValidationError, SchemaError | ||
import python_jsonschema_objects as jsonobjects | ||
import getopt,sys | ||
|
||
|
||
|
||
def main(): | ||
|
||
schema_path = "../schema/phenopacket-schema.json" | ||
|
||
try: | ||
opts,args = getopt.getopt(sys.argv[1:],"s:",["schema="]) | ||
except getopt.GetoptError as err: | ||
usage() | ||
sys.exit(2) | ||
|
||
for o,a in opts: | ||
if o in ("-s","--schema"): | ||
schema_path=a | ||
else: | ||
assert False, "unhandled option" | ||
exfile = args[0] | ||
|
||
# try: | ||
schema_fh = open(os.path.join(os.path.dirname(__file__), schema_path), 'r') | ||
schema = json.load(schema_fh) | ||
schema_fh.close() | ||
# except json.decoder.JSONDecodeError: | ||
# print("Schema file ", schema_path, " does not contain a valid JSON file") | ||
# sys.exit(1) | ||
|
||
|
||
try: | ||
file_fh = open(exfile,'r') | ||
data = json.load(file_fh) | ||
file_fh.close() | ||
except IOError: | ||
print ("Could not read phenopacket file ",exfile) | ||
sys.exit(2) | ||
except json.decoder.JSONDecodeError: | ||
print("Phenopacket file ", exfile, " does not contain a valid JSON file") | ||
sys.exit(3) | ||
|
||
|
||
# http:https://python-jsonschema.readthedocs.org/en/latest/errors/ | ||
try: | ||
print("running validator"); | ||
validate(data,schema) | ||
print("Valid phenopacket") | ||
except SchemaError as s: | ||
print ("Schema error in schema ", schema_path) | ||
print (s.message) | ||
except ValidationError as e: | ||
print("Invalid phenopacket found in ",exfile) | ||
print(e.message) | ||
|
||
|
||
|
||
def usage(): | ||
print('Usage: '+sys.argv[0]+' -s <schemafile> [option]') | ||
print(' '+sys.argv[0]+' --schema=<schemafile> [option]') | ||
|
||
if __name__ == '__main__': | ||
main() |
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,2 @@ | ||
#!/bin/sh | ||
python ./test/json_validation_test.py |