Skip to content

Commit

Permalink
Fix tests, add cli tests and fix some broken cli elements
Browse files Browse the repository at this point in the history
Fix tests, add cli tests and fix some broken cli elements
  • Loading branch information
hmacdope authored Jul 3, 2024
2 parents 1ddbc4f + 1228c6d commit 2f72178
Show file tree
Hide file tree
Showing 5 changed files with 86 additions and 16 deletions.
8 changes: 7 additions & 1 deletion .gitignore
Original file line number Diff line number Diff line change
Expand Up @@ -140,4 +140,10 @@ ENV/

# docs
docs/_build/
docs/API/_autosummary/
docs/API/_autosummary/

# pyc files
*.pyc

# pycache files
__pycache__/
8 changes: 5 additions & 3 deletions choppa/cli/cli.py
Original file line number Diff line number Diff line change
Expand Up @@ -6,7 +6,7 @@
from choppa.align import AlignFactory
from choppa.render import PublicationView, InteractiveView
from choppa.cli.utils import SpecialHelpOrder

from pathlib import Path

@click.group(
cls=SpecialHelpOrder,
Expand Down Expand Up @@ -111,9 +111,11 @@ def render(
confidence_column: Optional[str] = None,
):

if not outfile_publication[-4:] == ".pse":
# check extensions
if not Path(outfile_publication).suffix == ".pse":
raise ValueError("--op/--outfile-publication should end in '.pse'.")
elif not outfile_interactive[-5:] == ".html":

if not Path(outfile_interactive).suffix == ".html":
raise ValueError("--oi/--outfile-interactive should end in '.html'.")

fitness_dict = FitnessFactory(
Expand Down
Binary file not shown.
39 changes: 27 additions & 12 deletions choppa/tests/test_choppa.py
Original file line number Diff line number Diff line change
Expand Up @@ -28,7 +28,7 @@ def test_choppa_imported():
from choppa import render


def test_choppa_render_toy_mac1_sectioned():
def test_choppa_render_toy_mac1_sectioned(tmp_path):
"""Tests that `choppa` is able to render views on a fitness dataset that
has poor (fractioned) overlap with a toy PDB file."""

Expand All @@ -50,18 +50,22 @@ def test_choppa_render_toy_mac1_sectioned():
assert "".join([val["aa"] for val in alignment[6:25]]) == "KLTDNVYIKNADIVEEAKK"

render.PublicationView(
filled_aligned_fitness_dict, complex, complex_rdkit, fitness_threshold=0.7
filled_aligned_fitness_dict, complex, complex_rdkit, fitness_threshold=0.7, output_session_file=tmp_path/"test.pse"
).render()

render.InteractiveView(
filled_aligned_fitness_dict, complex, complex_rdkit, fitness_threshold=0.7
filled_aligned_fitness_dict, complex, complex_rdkit, fitness_threshold=0.7, output_session_file=tmp_path/"test.html"
).render()

# we know the intended output, test on this.
assert len(filled_aligned_fitness_dict) == 164
assert 4 not in filled_aligned_fitness_dict
assert 5 in filled_aligned_fitness_dict

# check files exist
assert (tmp_path / "test.pse").exists()
assert (tmp_path / "test.html").exists()


def test_choppa_correct_custom_columns():
"""Tests that `choppa` is able to read in correct columns in input fitness data."""
Expand Down Expand Up @@ -89,7 +93,7 @@ def test_choppa_incorrect_custom_columns():
).get_fitness_basedict()


def test_choppa_render_toy_mac1_sectioned_noconf():
def test_choppa_render_toy_mac1_sectioned_noconf(tmp_path):
"""Tests that `choppa` is able to render views on a fitness dataset that
has poor (fractioned) overlap with a toy PDB file, while not adding confidence."""

Expand All @@ -100,17 +104,21 @@ def test_choppa_render_toy_mac1_sectioned_noconf():
filled_aligned_fitness_dict = AlignFactory(fitness_dict, complex).align_fitness()

render.PublicationView(
filled_aligned_fitness_dict, complex, complex_rdkit, fitness_threshold=0.7
filled_aligned_fitness_dict, complex, complex_rdkit, fitness_threshold=0.7, output_session_file=tmp_path/"test.pse"
).render()

render.InteractiveView(
filled_aligned_fitness_dict, complex, complex_rdkit, fitness_threshold=0.7
filled_aligned_fitness_dict, complex, complex_rdkit, fitness_threshold=0.7, output_session_file=tmp_path/"test.html"
).render()

assert len(filled_aligned_fitness_dict) == 164

# check files exist
assert (tmp_path / "test.pse").exists()
assert (tmp_path / "test.html").exists()


def test_choppa_render_toy_mac1_full():
def test_choppa_render_toy_mac1_full(tmp_path):
"""Tests that `choppa` is able to render views on a fitness dataset that
has complete overlap with a toy PDB file."""

Expand All @@ -123,17 +131,20 @@ def test_choppa_render_toy_mac1_full():
filled_aligned_fitness_dict = AlignFactory(fitness_dict, complex).align_fitness()

render.PublicationView(
filled_aligned_fitness_dict, complex, complex_rdkit, fitness_threshold=0.7
filled_aligned_fitness_dict, complex, complex_rdkit, fitness_threshold=0.7, output_session_file=tmp_path/"test.pse"
).render()

render.InteractiveView(
filled_aligned_fitness_dict, complex, complex_rdkit, fitness_threshold=0.7
filled_aligned_fitness_dict, complex, complex_rdkit, fitness_threshold=0.7, output_session_file=tmp_path/"test.html"
).render()

assert len(filled_aligned_fitness_dict) == 164

# check files exist
assert (tmp_path / "test.pse").exists()
assert (tmp_path / "test.html").exists()

def test_choppa_render_toy_mac1_truncated():
def test_choppa_render_toy_mac1_truncated(tmp_path):
"""Tests that `choppa` is able to render views on a fitness dataset that
has decenr (trunacted at either end) overlap with a toy PDB file."""

Expand All @@ -146,11 +157,15 @@ def test_choppa_render_toy_mac1_truncated():
filled_aligned_fitness_dict = AlignFactory(fitness_dict, complex).align_fitness()

render.PublicationView(
filled_aligned_fitness_dict, complex, complex_rdkit, fitness_threshold=0.7
filled_aligned_fitness_dict, complex, complex_rdkit, fitness_threshold=0.7, output_session_file=tmp_path/"test.pse"
).render()

render.InteractiveView(
filled_aligned_fitness_dict, complex, complex_rdkit, fitness_threshold=0.7
filled_aligned_fitness_dict, complex, complex_rdkit, fitness_threshold=0.7, output_session_file=tmp_path/"test.html"
).render()

assert len(filled_aligned_fitness_dict) == 164

# check files exist
assert (tmp_path / "test.pse").exists()
assert (tmp_path / "test.html").exists()
47 changes: 47 additions & 0 deletions choppa/tests/test_cli.py
Original file line number Diff line number Diff line change
@@ -0,0 +1,47 @@
from click.testing import CliRunner
import traceback
import pytest


def click_success(result):
if result.exit_code != 0: # -no-cov- (only occurs on test error)
print(result.output)
traceback.print_tb(result.exc_info[2])
print(result.exc_info[0], result.exc_info[1])
return result.exit_code == 0


from choppa.cli.cli import cli
from choppa.data.toy_data.resources import (
TOY_COMPLEX,
TOY_FITNESS_DATA_COMPLETE,
TOY_FITNESS_DATA_TRUNCATED,
)
from choppa.data.toy_data.resources import (
TOY_FITNESS_DATA_SECTIONED,
TOY_FITNESS_DATA_COMPLETE_NOCONF,
)

def test_choppa_cli_help():
runner = CliRunner()
result = runner.invoke(cli, ["--help"])
assert click_success(result)


def test_choppa_cli_render(tmp_path):
runner = CliRunner()
result = runner.invoke(cli, ["render",
"--pdb-file", TOY_COMPLEX,
"--fitness-file", TOY_FITNESS_DATA_SECTIONED,
"--fitness-threshold", 0.7,
"--outfile-publication", tmp_path / "out.pse",
"--outfile-interactive", tmp_path / "out.html",
])
assert click_success(result)
# check the files exist
assert (tmp_path / "out.pse").exists()
assert (tmp_path / "out.html").exists()




0 comments on commit 2f72178

Please sign in to comment.