Skip to content

Commit

Permalink
adding tests from tsv->rdf and back again
Browse files Browse the repository at this point in the history
  • Loading branch information
sierra-moxon committed May 10, 2023
1 parent 801f941 commit 06a9c4e
Show file tree
Hide file tree
Showing 5 changed files with 86 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-tranform-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-tsv-rdf.yaml")
transform(inputs=None, transform_config=transform_config)
assert os.path.exists(os.path.join(TARGET_DIR, "test-transform-rdf.tsv"))
assert os.path.exists(os.path.join(TARGET_DIR, "test-transform-rdf.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

0 comments on commit 06a9c4e

Please sign in to comment.