""" # Flag for tracking the exit status of validate() calls status_flag = True os.chdir('../json_schema') pwd = subprocess.check_output('pwd').decode("utf-8").rstrip() print('pwd: %s' % pwd) base_uri = "file://" + pwd + "/" print('base URI: %s' % base_uri) # Specific JSON file example tests # Testing valid project JSON example print('\nValidating type/project/project.json schema') sv = get_validator('type/project/project.json', base_uri) print('Validating project/test_pass_project_0.json JSON against schema') p1 = get_json_from_file( '../schema_test_files/project/test_pass_project_0.json') if not validate(sv, p1): status_flag = False # Testing invalid project JSON example # It is missing required project_shortname field print('\nValidating type/project/project.json schema') sv = get_validator('type/project/project.json', base_uri) print( 'Validating project/test_fail_project_0.json JSON against schema\n(This should fail, missing project_shortname)' ) p1 = get_json_from_file( '../schema_test_files/project/test_fail_project_0.json')
""" Sample test: Are JSON files that are in the schema_test* folders valid JSON schema? """ # Flag for tracking the exit status of validate() calls status_flag = True os.chdir('../json_schema') pwd = subprocess.check_output('pwd').decode("utf-8").rstrip() base_uri = "file://" + pwd + "/" print(base_uri) print('\nValidating sample.json') sv = get_validator('sample.json', base_uri) # Specific schema tests follow print('\nValidating schema_test_files/10x_pbmc8k_donor_0.json') dt1 = get_json_from_file('../schema_test_files/10x_pbmc8k_donor_0.json') if not validate(sv, dt1): # will return False if fails (show return value) status_flag = False print('\nValidating schema_test_files/10x_pbmc8k_sample_0.json') sfo1 = get_json_from_file('../schema_test_files/10x_pbmc8k_sample_0.json') if not validate(sv, sfo1): status_flag = False print('\nValidating schema_tests/sample/fail/sample-test-current.json\n(This should fail)') sf1 = get_json_from_file('../schema_tests/sample/fail/sample-test-current.json')
def positive_tests(self): v = get_validator('sample.json', self.base_uri) validate(v, {}) return
from schema_test_suite import get_validator import os """ schemas_are_valid_json: This code tests whether JSON schemas that are in the json_schema/* directory are valid JSON schema. """ schema_path = '../json_schema' schemas = [ os.path.join(dirpath, f) for dirpath, dirnames, files in os.walk(schema_path) for f in files if f.endswith('.json') ] print("Checking %d schemas" % len(schemas)) for s in schemas: print('Checking %s' % s) get_validator(s)