Skip to content

Commit

Permalink
Merge pull request #4 from GenomicMedLab/1-implement-testing-and-benc…
Browse files Browse the repository at this point in the history
…hmarking

1-implement-testing-and-benchmarking
  • Loading branch information
rbasu101 authored Mar 18, 2024
2 parents f1a35f4 + 072d342 commit 20c832f
Show file tree
Hide file tree
Showing 4 changed files with 113 additions and 2 deletions.
7 changes: 7 additions & 0 deletions .vscode/settings.json
Original file line number Diff line number Diff line change
@@ -0,0 +1,7 @@
{
"python.testing.pytestArgs": [
"tests"
],
"python.testing.unittestEnabled": false,
"python.testing.pytestEnabled": true
}
5 changes: 3 additions & 2 deletions pyproject.toml
Original file line number Diff line number Diff line change
Expand Up @@ -28,7 +28,7 @@ dynamic = ["version"]


[project.optional-dependencies]
test = ["pytest", "pytest-cov"]
test = ["pytest", "pytest-cov","pytest-benchmark"]
dev = ["pre-commit", "ruff==0.2.0"]

docs = [
Expand Down Expand Up @@ -62,13 +62,14 @@ where = ["src"]
[tool.pytest.ini_options]
addopts = "--cov=src --cov-report term-missing"
testpaths = ["tests"]
pythonpath = ["src"]

[tool.coverage.run]
branch = true

[tool.ruff]
src = ["src"]
exclude = ["docs/source/conf.py"]
exclude = ["docs/source/conf.py","tests/test_dgidb.py","tests/test_graph_app.py"]
lint.select = [
"F", # https://docs.astral.sh/ruff/rules/#pyflakes-f
"E", "W", # https://docs.astral.sh/ruff/rules/#pycodestyle-e-w
Expand Down
94 changes: 94 additions & 0 deletions tests/test_dgidb.py
Original file line number Diff line number Diff line change
@@ -0,0 +1,94 @@
import pandas as pd
import pytest

from dgipy.dgidb import get_interactions,get_categories,get_drug


def test_get_interactions():
"""Test that interactions works correctly"""
# Search types work correctly
query = "braf"
with pytest.raises(Exception) as excinfo:
results = get_interactions(query, search="fake")
assert "Search type must be specified" in str(excinfo.value)

# Default search type functions correct as 'gene' and not 'drug'
query = "imatinib"
results = get_interactions(query)
assert len(results) == 0

# Use pandas default is correctly set to 'true'
query = "braf"
results = get_interactions(query)
assert type(results) == type(pd.DataFrame())

# Use pandas can be toggled to 'false' and returns a dictionary response object
query = "braf"
results = get_interactions(query, use_pandas=False)
assert type(results) != type(pd.DataFrame())
assert type(results) == type(dict())

# Gene search types work correctly
query = "braf"
results = get_interactions(query, search="genes")
assert results.columns[0] == "gene"

# Gene search is not grabbing drugs
query = "imatinib"
results = get_interactions(query, search="genes")
assert len(results) == 0

# Drug search types work correctly
query = "imatinib"
results = get_interactions(query, search="drugs")
assert type(results) == type(pd.DataFrame())
assert results.columns[0] == "drug"

# Drug search is not grabbing genes
query = "XPO1"
results = get_interactions(query, search="drugs")
assert len(results) == 0


def test_get_categories():
"""Test that categories works correctly"""
# Categories search builds a dataframe (with use_pandas default set to 'true')
query = "braf"
results = get_categories(query)
assert type(results) == type(pd.DataFrame())

# Categories does not return drugs data
query = "imatinib"
results = get_categories(query)
assert len(results) == 0

# Use pandas can be toggled to 'false' and returns a dictionary response object
query = "imatinib"
results = get_categories(query, use_pandas=False)
assert type(results) != type(pd.DataFrame())
assert type(results) == type(dict())


def test_get_drugs():
"""Test that drug profile works correctly"""
# Drug search builds a dataframe (with use_pandas default set to 'true')
query = "imatinib"
results = get_drug(query)
assert type(results) == type(pd.DataFrame())

# Drug search does not return gene data
query = "XPO1"
results = get_drug(query)
assert (len(results)) == 0

# Use pandas can be toggled to 'false' and returns dictionary response object
query = "imatinib"
results = get_drug(query, use_pandas=False)
assert type(results) != type(pd.DataFrame())
assert type(results) == type(dict())


def test_get_interactions_benchmark(benchmark):
query = "braf"
results = benchmark.pedantic(get_interactions, args=(query,), kwargs={"search": "genes"},rounds=10,warmup_rounds=0,iterations=1)
assert results.columns[0] == "gene"
9 changes: 9 additions & 0 deletions tests/test_graph_app.py
Original file line number Diff line number Diff line change
@@ -0,0 +1,9 @@
import pytest

from dgipy.graph_app import generate_app


def test_generate_app():
app = generate_app()
if __name__ == "__main__":
app.run_server()

0 comments on commit 20c832f

Please sign in to comment.