Skip to content

Commit

Permalink
Merge pull request #367 from biolink/update_bmt
Browse files Browse the repository at this point in the history
update bmt to get new biolink-model, fix linkml changes, add test coverage to click in order to pass sonarcloud coverage requirements
  • Loading branch information
sierra-moxon authored Jan 7, 2022
2 parents 97eb886 + 655bc00 commit 6645182
Show file tree
Hide file tree
Showing 6 changed files with 209 additions and 13 deletions.
1 change: 0 additions & 1 deletion kgx/cli/__init__.py
Original file line number Diff line number Diff line change
Expand Up @@ -555,7 +555,6 @@ def transform_wrapper(
exit(1)



@cli.command(name="merge")
@click.option("--merge-config", required=True, type=str)
@click.option(
Expand Down
3 changes: 0 additions & 3 deletions kgx/config.yml
Original file line number Diff line number Diff line change
Expand Up @@ -17,9 +17,6 @@ logging:
level: INFO
format: '[%(name)s][%(filename)s][%(funcName)20s] %(levelname)s: %(message)s'

# KGX setting for the Biolink Model is now ignored; defer to the Biolink Model Toolkit default.
# biolink-model: https://raw.githubusercontent.com/biolink/biolink-model/2.2.5/biolink-model.yaml

jsonld-context:
biolink: https://raw.githubusercontent.com/biolink/biolink-model/2.2.5/context.jsonld
monarch_context: https://raw.githubusercontent.com/prefixcommons/biocontext/master/registry/monarch_context.jsonld
Expand Down
7 changes: 4 additions & 3 deletions requirements.txt
Original file line number Diff line number Diff line change
@@ -1,8 +1,7 @@
bmt~=0.7.6
prefixcommons>=0.1.4
pip>=9.0.1
docutils==0.16.0
networkx>=2.5
networkx
SPARQLWrapper>=1.8.2
pandas>=1.0.3
pytest>=0.0
Expand All @@ -11,7 +10,6 @@ rdflib~=5.0.0
Click~=7.0
neo4jrestclient>=0.0
pyyaml>=0.0
linkml>=1.1.13
prologterms>=0.0.5
shexjsg>=0.6.5
terminaltables>=3.1.0
Expand All @@ -32,4 +30,7 @@ recommonmark>=0.7.1
tox
flake8
black
bmt>=0.8.1
tox-docker
linkml
linkml-runtime
204 changes: 202 additions & 2 deletions tests/unit/test_cli_utils.py
Original file line number Diff line number Diff line change
Expand Up @@ -7,14 +7,15 @@
from click.testing import CliRunner

from kgx.cli.cli_utils import validate, neo4j_upload, neo4j_download, transform, merge
from kgx.cli import cli, get_input_file_types, graph_summary, get_report_format_types, validate_wrapper
from kgx.cli import cli, get_input_file_types, graph_summary, get_report_format_types
from tests import RESOURCE_DIR, TARGET_DIR
from tests.unit import (
check_container,
clean_slate,
CONTAINER_NAME,
DEFAULT_NEO4J_URL,
DEFAULT_NEO4J_USERNAME,
DEFAULT_NEO4J_PASSWORD,
DEFAULT_NEO4J_PASSWORD
)


Expand All @@ -38,6 +39,117 @@ def test_get_report_format_types():
assert "json" in format_types


@pytest.mark.skipif(
not check_container(), reason=f"Container {CONTAINER_NAME} is not running"
)
def test_graph_summary_wrapper():
output = os.path.join(TARGET_DIR, "graph_stats3.yaml")

runner = CliRunner()
result = runner.invoke(
cli,
[
"graph-summary",
"-i", "tsv",
"-o", output,
os.path.join(RESOURCE_DIR, "graph_nodes.tsv")
]
)
assert result.exit_code == 0

@pytest.mark.skipif(
not check_container(), reason=f"Container {CONTAINER_NAME} is not running"
)
def test_graph_summary_wrapper_error():
inputs = [
os.path.join(RESOURCE_DIR, "graph_nodes.tsv"),
os.path.join(RESOURCE_DIR, "graph_edges.tsv"),
]
output = os.path.join(TARGET_DIR, "graph_stats3.yaml")

runner = CliRunner()
result = runner.invoke(
cli,
[
"graph-summary",
"-i", "tsv",
"-o", output,
inputs
]
)
assert result.exit_code == 1

@pytest.mark.skipif(
not check_container(), reason=f"Container {CONTAINER_NAME} is not running"
)
def test_transform_wrapper():
"""
Transform graph from TSV to JSON.
"""
inputs = [
os.path.join(RESOURCE_DIR, "graph_nodes.tsv"),
os.path.join(RESOURCE_DIR, "graph_edges.tsv"),
]
output = os.path.join(TARGET_DIR, "grapht.json")

runner = CliRunner()
result = runner.invoke(
cli,
[
"transform",
"-i", "tsv",
"-o", output,
"-f", "json",
inputs
]
)

assert result.exit_code == 1

@pytest.mark.skipif(
not check_container(), reason=f"Container {CONTAINER_NAME} is not running"
)
def test_merge_wrapper():

"""
Transform from test merge YAML.
"""
merge_config = os.path.join(RESOURCE_DIR, "test-merge.yaml")
runner = CliRunner()
result = runner.invoke(
cli,
[
"merge",
"--merge-config", merge_config
]
)

assert result.exit_code == 0
assert os.path.join(TARGET_DIR, "merged-graph_nodes.tsv")
assert os.path.join(TARGET_DIR, "merged-graph_edges.tsv")
assert os.path.join(TARGET_DIR, "merged-graph.json")


@pytest.mark.skipif(
not check_container(), reason=f"Container {CONTAINER_NAME} is not running"
)
def test_merge_wrapper_error():

"""
Transform from test merge YAML.
"""
merge_config = os.path.join(RESOURCE_DIR, "test-merge.yaml")
runner = CliRunner()
result = runner.invoke(
cli,
[
"merge"
]
)

assert result.exit_code == 2


def test_kgx_graph_summary():
"""
Test graph summary, where the output report type is kgx-map.
Expand Down Expand Up @@ -259,6 +371,94 @@ def test_neo4j_upload(clean_slate):
assert t.store.graph.number_of_edges() == 531


@pytest.mark.skipif(
not check_container(), reason=f"Container {CONTAINER_NAME} is not running"
)
def test_neo4j_download_wrapper(clean_slate):
output = os.path.join(TARGET_DIR, "neo_download2")
runner = CliRunner()
result = runner.invoke(
cli,
[
"neo4j-download",
"-l", DEFAULT_NEO4J_URL,
"-o", output,
"-f", "tsv",
"-u", DEFAULT_NEO4J_USERNAME,
"-p", DEFAULT_NEO4J_PASSWORD,
]
)

assert os.path.exists(f"{output}_nodes.tsv")
assert os.path.exists(f"{output}_edges.tsv")

assert result.exit_code == 0

@pytest.mark.skipif(
not check_container(), reason=f"Container {CONTAINER_NAME} is not running"
)
def test_download_exception_triggered_error_exit_code():
"""
Test graph download error exit code.
"""

output = os.path.join(TARGET_DIR, "neo_download")
runner = CliRunner()
result = runner.invoke(
cli,
[
"neo4j-download",
"-l", DEFAULT_NEO4J_URL,
"-o", output,
"-f", "tsv",
"-u", "not a user name",
"-p", DEFAULT_NEO4J_PASSWORD,
]
)
assert result.exit_code == 1

@pytest.mark.skipif(
not check_container(), reason=f"Container {CONTAINER_NAME} is not running"
)
def test_neo4j_upload_wrapper(clean_slate):
inputs = [
os.path.join(RESOURCE_DIR, "graph_nodes.tsv"),
os.path.join(RESOURCE_DIR, "graph_edges.tsv"),
]
runner = CliRunner()
result = runner.invoke(
cli,
[
"neo4j-upload",
"--input-format", "tsv",
"--uri", DEFAULT_NEO4J_URL,
"--username", DEFAULT_NEO4J_USERNAME,
"--password", DEFAULT_NEO4J_PASSWORD,
os.path.join(RESOURCE_DIR, "graph_nodes.tsv")
]
)

assert result.exit_code == 0


@pytest.mark.skipif(
not check_container(), reason=f"Container {CONTAINER_NAME} is not running"
)
def test_neo4j_upload_wrapper_error(clean_slate):
runner = CliRunner()
result = runner.invoke(
cli,
[
"neo4j-upload",
"-i", "tsv",
"inputs", "not_a_path"
"-u", "not a user",
"-p", DEFAULT_NEO4J_PASSWORD,
]
)

assert result.exit_code == 2

@pytest.mark.skip()
@pytest.mark.skipif(
not check_container(), reason=f"Container {CONTAINER_NAME} is not running"
Expand Down
5 changes: 2 additions & 3 deletions tests/unit/test_source/test_owl_source.py
Original file line number Diff line number Diff line change
@@ -1,5 +1,4 @@
import os
import pprint

from kgx.source import OwlSource
from tests import RESOURCE_DIR
Expand All @@ -9,11 +8,12 @@ def test_read_owl1():
"""
Read an OWL ontology using OwlSource.
"""

s = OwlSource()
g = s.parse(
os.path.join(RESOURCE_DIR, "goslim_generic.owl"),
provided_by="GO slim generic",
knowledge_source="GO slim generic",
knowledge_source="GO slim generic"
)
nodes = {}
edges = {}
Expand Down Expand Up @@ -133,7 +133,6 @@ def test_read_owl3():
nodes[rec[0]] = rec[-1]

n1 = nodes["GO:0008150"]
pprint.pprint(n1)
assert n1["name"] == "biological_process"
assert "subsets" in n1 and "GOP:goslim_generic" in n1["subsets"]
assert "synonym" in n1 and "biological process" in n1["synonym"]
Expand Down
2 changes: 1 addition & 1 deletion tests/unit/test_validator.py
Original file line number Diff line number Diff line change
Expand Up @@ -21,7 +21,7 @@ def test_get_required_node_properties(property):
assert property in properties


@pytest.mark.parametrize("property", ["subject", "object", "predicate", "relation"])
@pytest.mark.parametrize("property", ["subject", "object", "predicate"])
def test_get_required_edge_properties(property):
"""
Test get_required_edge_properties in Validator.
Expand Down

0 comments on commit 6645182

Please sign in to comment.