Skip to content

Commit

Permalink
Merge pull request #451 from biolink/cpath_tests
Browse files Browse the repository at this point in the history
add test for CPATH
  • Loading branch information
sierra-moxon authored May 10, 2023
2 parents 8df94f0 + 305b244 commit 5583e54
Show file tree
Hide file tree
Showing 6 changed files with 111 additions and 1 deletion.
2 changes: 1 addition & 1 deletion kgx/cli/cli_utils.py
Original file line number Diff line number Diff line change
Expand Up @@ -219,7 +219,7 @@ def validate(
}, # streaming processing throws the graph data away
# ... Second, we inject the Inspector into the transform() call,
# for the underlying Transformer.process() to use...
inspector=validator
inspector=validator,
)

if output:
Expand Down
25 changes: 25 additions & 0 deletions tests/resources/test-transform-rdf-tsv.yaml
Original file line number Diff line number Diff line change
@@ -0,0 +1,25 @@
configuration:
output_directory: ../target
checkpoint: false
transform:
source:
test_graph:
name: "Test Graph"
input:
format: nt
filename:
- test-transform-rdf.nt
output:
format: tsv
filename:
- test-transform-rdf
valid_graph:
name: "Valid JSON Graph"
input:
format: json
filename:
- valid.json
output:
format: tsv
filename:
- valid_graph
15 changes: 15 additions & 0 deletions tests/resources/test-transform-rdf.nt
Original file line number Diff line number Diff line change
@@ -0,0 +1,15 @@
<http://identifiers.org/ensembl/ENSG0000000000001> <http://www.w3.org/1999/02/22-rdf-syntax-ns#type> <http://purl.obolibrary.org/obo/SO_0000704> .
<http://identifiers.org/ensembl/ENSG0000000000001> <https://w3id.org/biolink/vocab/category> <https://w3id.org/biolink/vocab/Gene> .
<http://identifiers.org/ensembl/ENSG0000000000001> <https://w3id.org/biolink/vocab/category> <https://w3id.org/biolink/vocab/GenomicEntity> .
<http://identifiers.org/ensembl/ENSG0000000000001> <https://w3id.org/biolink/vocab/category> <https://w3id.org/biolink/vocab/MolecularEntity> .
<http://identifiers.org/ensembl/ENSG0000000000001> <https://w3id.org/biolink/vocab/name> "Test Gene 123" .
<http://identifiers.org/ensembl/ENSG0000000000001> <https://w3id.org/biolink/vocab/description> "This is a Test Gene 123" .
<http://identifiers.org/ensembl/ENSG0000000000001> <https://w3id.org/biolink/vocab/provided_by> "Test Dataset" .
<http://identifiers.org/ensembl/ENSG0000000000002> <http://www.w3.org/1999/02/22-rdf-syntax-ns#type> <http://purl.obolibrary.org/obo/SO_0000704> .
<http://identifiers.org/ensembl/ENSG0000000000002> <https://w3id.org/biolink/vocab/category> <https://w3id.org/biolink/vocab/Gene> .
<http://identifiers.org/ensembl/ENSG0000000000002> <https://w3id.org/biolink/vocab/category> <https://w3id.org/biolink/vocab/GenomicEntity> .
<http://identifiers.org/ensembl/ENSG0000000000002> <https://w3id.org/biolink/vocab/category> <https://w3id.org/biolink/vocab/MolecularEntity> .
<http://identifiers.org/ensembl/ENSG0000000000002> <https://w3id.org/biolink/vocab/name> "Test Gene 456" .
<http://identifiers.org/ensembl/ENSG0000000000002> <https://w3id.org/biolink/vocab/description> "This is a Test Gene 456" .
<http://identifiers.org/ensembl/ENSG0000000000002> <https://w3id.org/biolink/vocab/provided_by> "Test Dataset" .
<http://identifiers.org/ensembl/ENSG0000000000001> <https://w3id.org/biolink/vocab/interacts_with> <http://identifiers.org/ensembl/ENSG0000000000002> .
26 changes: 26 additions & 0 deletions tests/resources/test-transform-tsv-rdf.yaml
Original file line number Diff line number Diff line change
@@ -0,0 +1,26 @@
configuration:
output_directory: ../target
checkpoint: false
transform:
source:
test_graph:
name: "Test Graph"
input:
format: tsv
filename:
- test2_nodes.tsv
- test2_edges.tsv
output:
format: nt
filename:
- test-tranform-tsv-rdf.nt
valid_graph:
name: "Valid JSON Graph"
input:
format: json
filename:
- valid.json
output:
format: tsv
filename:
- valid_graph
19 changes: 19 additions & 0 deletions tests/unit/test_cli_utils.py
Original file line number Diff line number Diff line change
Expand Up @@ -866,6 +866,25 @@ def test_transform2():
assert os.path.exists(os.path.join(RESOURCE_DIR, "graph_edges.tsv"))


def test_transform_rdf_to_tsv():
"""
Transform from a test transform YAML.
"""
transform_config = os.path.join(RESOURCE_DIR, "test-transform-rdf-tsv.yaml")
transform(inputs=None, transform_config=transform_config)
assert os.path.exists(os.path.join(TARGET_DIR, "test-transform-rdf_edges.tsv"))
assert os.path.exists(os.path.join(TARGET_DIR, "test-transform-rdf_nodes.tsv"))


def test_transform_tsv_to_rdf():
"""
Transform from a test transform YAML.
"""
transform_config = os.path.join(RESOURCE_DIR, "test-transform-tsv-rdf.yaml")
transform(inputs=None, transform_config=transform_config)
assert os.path.exists(os.path.join(TARGET_DIR, "test-tranform-tsv-rdf.nt"))


def test_merge1():
"""
Transform from test merge YAML.
Expand Down
25 changes: 25 additions & 0 deletions tests/unit/test_source/test_json_source.py
Original file line number Diff line number Diff line change
Expand Up @@ -40,6 +40,31 @@ def test_read_json1():
assert e["relation"] == "RO:0004013"


def test_read_json_filter():
"""
Read from a JSON using JsonSource.
"""
t = Transformer()
s = JsonSource(t)
filters = {
"category": {"biolink:Disease"}
}
s.set_node_filters(filters)
g = s.parse(os.path.join(RESOURCE_DIR, "valid.json"))
nodes = {}
edges = {}
for rec in g:
if rec:
if len(rec) == 4:
edges[(rec[0], rec[1])] = rec[3]
else:
nodes[rec[0]] = rec[1]

for node in nodes:
n = nodes[node]
assert n["category"] == ["biolink:Disease"]


def test_read_json2():
"""
Read from a JSON using JsonSource.
Expand Down

0 comments on commit 5583e54

Please sign in to comment.