From 1ed9c95792386640707e3a78af532e054dda1bbc Mon Sep 17 00:00:00 2001 From: Sierra Taylor Moxon Date: Tue, 9 May 2023 17:51:52 -0700 Subject: [PATCH 1/4] add test for CPATH --- tests/unit/test_source/test_json_source.py | 28 ++++++++++++++++++++++ 1 file changed, 28 insertions(+) diff --git a/tests/unit/test_source/test_json_source.py b/tests/unit/test_source/test_json_source.py index 488e1a08..deed304e 100644 --- a/tests/unit/test_source/test_json_source.py +++ b/tests/unit/test_source/test_json_source.py @@ -40,6 +40,34 @@ 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: + print(node) + + print(nodes["MONDO:0017148"]) + + + + def test_read_json2(): """ Read from a JSON using JsonSource. From 801f94161d9e7745b29e30f8f457d786dab22285 Mon Sep 17 00:00:00 2001 From: Sierra Taylor Moxon Date: Tue, 9 May 2023 17:55:15 -0700 Subject: [PATCH 2/4] demonstrate filter node --- tests/unit/test_source/test_json_source.py | 7 ++----- 1 file changed, 2 insertions(+), 5 deletions(-) diff --git a/tests/unit/test_source/test_json_source.py b/tests/unit/test_source/test_json_source.py index deed304e..fc1ecc6e 100644 --- a/tests/unit/test_source/test_json_source.py +++ b/tests/unit/test_source/test_json_source.py @@ -61,11 +61,8 @@ def test_read_json_filter(): nodes[rec[0]] = rec[1] for node in nodes: - print(node) - - print(nodes["MONDO:0017148"]) - - + n = nodes[node] + assert n["category"] == ["biolink:Disease"] def test_read_json2(): From 06a9c4efdc6082bf57c204af73c8d325bee4bfb0 Mon Sep 17 00:00:00 2001 From: Sierra Taylor Moxon Date: Wed, 10 May 2023 09:26:55 -0700 Subject: [PATCH 3/4] adding tests from tsv->rdf and back again --- kgx/cli/cli_utils.py | 2 +- tests/resources/test-transform-rdf-tsv.yaml | 25 ++++++++++++++++++++ tests/resources/test-transform-rdf.nt | 15 ++++++++++++ tests/resources/test-transform-tsv-rdf.yaml | 26 +++++++++++++++++++++ tests/unit/test_cli_utils.py | 19 +++++++++++++++ 5 files changed, 86 insertions(+), 1 deletion(-) create mode 100644 tests/resources/test-transform-rdf-tsv.yaml create mode 100644 tests/resources/test-transform-rdf.nt create mode 100644 tests/resources/test-transform-tsv-rdf.yaml diff --git a/kgx/cli/cli_utils.py b/kgx/cli/cli_utils.py index 03b3479e..59b34aa5 100644 --- a/kgx/cli/cli_utils.py +++ b/kgx/cli/cli_utils.py @@ -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: diff --git a/tests/resources/test-transform-rdf-tsv.yaml b/tests/resources/test-transform-rdf-tsv.yaml new file mode 100644 index 00000000..bd91e7f7 --- /dev/null +++ b/tests/resources/test-transform-rdf-tsv.yaml @@ -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 diff --git a/tests/resources/test-transform-rdf.nt b/tests/resources/test-transform-rdf.nt new file mode 100644 index 00000000..3d566ca2 --- /dev/null +++ b/tests/resources/test-transform-rdf.nt @@ -0,0 +1,15 @@ + . + . + . + . + "Test Gene 123" . + "This is a Test Gene 123" . + "Test Dataset" . + . + . + . + . + "Test Gene 456" . + "This is a Test Gene 456" . + "Test Dataset" . + . \ No newline at end of file diff --git a/tests/resources/test-transform-tsv-rdf.yaml b/tests/resources/test-transform-tsv-rdf.yaml new file mode 100644 index 00000000..ef578793 --- /dev/null +++ b/tests/resources/test-transform-tsv-rdf.yaml @@ -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 diff --git a/tests/unit/test_cli_utils.py b/tests/unit/test_cli_utils.py index 1b4b4f92..a0cf4491 100644 --- a/tests/unit/test_cli_utils.py +++ b/tests/unit/test_cli_utils.py @@ -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. From 305b244f101d8ea8f1e9d4396a1601d96c2cd6ef Mon Sep 17 00:00:00 2001 From: Sierra Taylor Moxon Date: Wed, 10 May 2023 09:51:52 -0700 Subject: [PATCH 4/4] fixing tests --- tests/resources/test-transform-rdf-tsv.yaml | 2 +- tests/unit/test_cli_utils.py | 6 +++--- 2 files changed, 4 insertions(+), 4 deletions(-) diff --git a/tests/resources/test-transform-rdf-tsv.yaml b/tests/resources/test-transform-rdf-tsv.yaml index bd91e7f7..cb5dc01f 100644 --- a/tests/resources/test-transform-rdf-tsv.yaml +++ b/tests/resources/test-transform-rdf-tsv.yaml @@ -12,7 +12,7 @@ transform: output: format: tsv filename: - - test-tranform-rdf + - test-transform-rdf valid_graph: name: "Valid JSON Graph" input: diff --git a/tests/unit/test_cli_utils.py b/tests/unit/test_cli_utils.py index a0cf4491..47279fea 100644 --- a/tests/unit/test_cli_utils.py +++ b/tests/unit/test_cli_utils.py @@ -870,10 +870,10 @@ 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_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.tsv")) - 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_edges.tsv")) + assert os.path.exists(os.path.join(TARGET_DIR, "test-transform-rdf_nodes.tsv")) def test_transform_tsv_to_rdf():