def validate(config, path, input_type, output_dir, record_size): os.makedirs(output_dir, exist_ok=True) validator = Validator(record_size) t = get_transformer(get_type(path))() t.parse(path) # t = load_transformer(path, input_type) validator.validate(t.graph) for error_type, failures in validator.error_dict.items(): filename = error_type.replace(' ', '_') + '.log' with click.open_file(os.path.join(output_dir, filename), 'a+') as f: f.write('--- {} ---\n'.format(datetime.now())) for t in failures: if len(t) == 2: n, message = t if message is not None: f.write('node({}):\t{}\n'.format(n, message)) else: f.write('node({})\n'.format(n)) elif len(t) == 3: u, v, message = t if message is not None: f.write('edge({}, {}):\t{}\n'.format(u, v, message)) else: f.write('edge({}, {})\n'.format(u, v)) if validator.error_dict == {}: click.echo('No errors found') else: for key, value in validator.error_dict.items(): click.echo('{} - {}'.format(key, len(value)))
def test_validator_good(): """ A fake test to establish a success condition for validation """ G = nx.MultiDiGraph() G.add_node('UniProtKB:P123456', id='UniProtKB:P123456', name='fake', category=['Protein']) G.add_node('UBERON:0000001', id='UBERON:0000001', name='fake', category=['NamedThing']) G.add_node('UBERON:0000002', id='UBERON:0000002', name='fake', category=['NamedThing']) G.add_edge('UBERON:0000001', 'UBERON:0000002', association_id='UBERON:0000001-part_of-UBERON:0000002', relation='RO:1', edge_label='part_of', subject='UBERON:0000001', object='UBERON:0000002') validator = Validator(verbose=True) e = validator.validate(G) assert len(e) == 0
def test_validate_json(): """ Validate against a valid representative Biolink Model compliant JSON """ json_file = os.path.join(resource_dir, 'valid.json') jt = JsonTransformer() jt.parse(json_file) validator = Validator() e = validator.validate(jt.graph) assert len(e) == 0
def test_validator_bad(): """ A fake test to establish a fail condition for validation """ G = nx.MultiDiGraph() G.add_node('x', foo=3) G.add_node('ZZZ:3', nosuch=1) G.add_edge('x', 'y', baz=6) validator = Validator(verbose=True) e = validator.validate(G) assert len(e) > 0
def test_validator_bad(): """ fake test """ G = nx.MultiDiGraph() G.add_node('x', foo=3) G.add_node('ZZZ:3', nosuch=1) G.add_edge('x', 'y', baz=6) validator = Validator() validator.validate(G) write_errors(validator) assert not validator.ok()
def test_validator_rdf(): """ use test files """ cwd = os.path.abspath(os.path.dirname(__file__)) resdir = os.path.join(cwd, 'resources') src_path = os.path.join(resdir, 'monarch', 'biogrid_test.ttl') t = ObanRdfTransformer() t.parse(src_path, input_format="turtle") validator = Validator() validator.validate(t.graph) write_errors(validator)
def test_validator_bad(): """ fake test """ G = nx.MultiDiGraph() G.add_node('x', foo=3) G.add_node('ZZZ:3', nosuch=1) G.add_edge('x', 'y', baz=6) validator = Validator() validator.validate(G) write_errors(validator) # TODO: status is True when it should be False assert not validator.ok()
def test_validator_good(): """ fake test """ print("Creating fake test graph...") G = nx.MultiDiGraph() G.add_node('UniProtKB:P123456', name='fake') G.add_edge('UBERON:0000001', 'UBERON:0000002', relation='RO:1', edge_label='part_of') validator = Validator() #print("PM={}".format(validator.prefix_manager.prefixmap)) validator.validate(G) write_errors(validator) assert validator.ok() == 0
def test_validate_edge_properties(query): required_properties = Validator.get_required_edge_properties() e = Validator.validate_edge_properties(query[0], query[1], query[2], required_properties) assert (len(e) == 0) == query[3]
def test_get_all_prefixes(prefix): prefixes = Validator.get_all_prefixes() assert prefix in prefixes
def test_validate_edge_label(query): e = Validator.validate_edge_label(query[0], query[1], query[2]) assert (len(e) == 0) == query[3]
def test_validate_categories(query): e = Validator.validate_categories(query[0], query[1]) assert (len(e) == 0) == query[2]
def test_validate_edge_property_values(query): e = Validator.validate_edge_property_values(query[0], query[1], query[2]) assert (len(e) == 0) == query[3]
def test_get_required_edge_properties(property): properties = Validator.get_required_edge_properties() assert property in properties
def test_validate_node_property_types(query): e = Validator.validate_node_property_types(query[0], query[1]) assert (len(e) == 0) == query[2]