Skip to content

Commit

Permalink
Improve tests
Browse files Browse the repository at this point in the history
  • Loading branch information
yuanx749 committed Jul 20, 2024
1 parent 058303c commit ad3c14a
Show file tree
Hide file tree
Showing 2 changed files with 26 additions and 25 deletions.
22 changes: 10 additions & 12 deletions tests/test_class.py
Original file line number Diff line number Diff line change
@@ -1,4 +1,4 @@
from subprocess import CalledProcessError
from pathlib import Path

import pandas as pd
import pytest
Expand All @@ -7,6 +7,8 @@


class TestCDHIT:
cdhit_installed = Path("~/cd-hit/cd-hit-est").expanduser().exists()

@pytest.fixture(autouse=True)
def init_cdhit(self):
self.cdhit = _class.CDHIT(prog="cd-hit-est", path="~/cd-hit")
Expand All @@ -15,17 +17,16 @@ def test_invalid_name(self):
with pytest.raises(ValueError):
_class.CDHIT(prog="")

@pytest.mark.skipif(not cdhit_installed, reason="FileNotFoundError")
def test_help(self, capsys):
try:
self.cdhit.help()
assert len(capsys.readouterr().out) > 0
except FileNotFoundError:
pass
self.cdhit.help()
assert len(capsys.readouterr().out) > 0

def test_set_options(self):
self.cdhit.set_options(c=0.9, n=10)
assert self.cdhit.options == {"c": 0.9, "n": 10}

@pytest.mark.skipif(not cdhit_installed, reason="FileNotFoundError")
def test_cluster_return_type(self):
assert self.cdhit.options == {}
fasta_in = pd.DataFrame(
Expand All @@ -34,9 +35,6 @@ def test_cluster_return_type(self):
"sequence": ["ACGTA", "CGTC", "CCGCC"],
}
)
try:
fasta, clstr = self.cdhit.cluster(fasta_in)
assert isinstance(fasta, pd.DataFrame)
assert isinstance(clstr, pd.DataFrame)
except (CalledProcessError, FileNotFoundError):
pass
fasta, clstr = self.cdhit.cluster(fasta_in)
assert isinstance(fasta, pd.DataFrame)
assert isinstance(clstr, pd.DataFrame)
29 changes: 16 additions & 13 deletions tests/test_commands.py
Original file line number Diff line number Diff line change
@@ -1,6 +1,6 @@
import os
from pathlib import Path
from subprocess import CalledProcessError, CompletedProcess
from subprocess import CompletedProcess

import pytest

Expand All @@ -14,6 +14,9 @@
CCGCC"""


os.environ["CD_HIT_DIR"] = "~/cd-hit"


@pytest.fixture
def cdhit_temp_files():
test_dir = Path(__file__).resolve().parent
Expand All @@ -25,23 +28,23 @@ def cdhit_temp_files():
out_path.with_suffix(".clstr").unlink(missing_ok=True)


@pytest.mark.skipif(
not Path("~/cd-hit/cd-hit-est").expanduser().exists(),
reason="FileNotFoundError",
)
def test_cd_hit(cdhit_temp_files):
os.environ["CD_HIT_DIR"] = "~/cd-hit"
in_path, out_path = cdhit_temp_files
in_path.write_text(FASTA)
try:
res = _commands.cd_hit_est(i=in_path, o=out_path)
assert isinstance(res, CompletedProcess)
except (CalledProcessError, FileNotFoundError):
pass
res = _commands.cd_hit_est(i=in_path, o=out_path)
assert isinstance(res, CompletedProcess)


@pytest.mark.skipif(
not Path("~/cd-hit/cd-hit-div").expanduser().exists(),
reason="FileNotFoundError",
)
def test_warning(cdhit_temp_files):
os.environ["CD_HIT_DIR"] = "~/cd-hit"
in_path, out_path = cdhit_temp_files
in_path.write_text(FASTA)
try:
with pytest.warns(UserWarning, match="Warning"):
_commands.cd_hit_div(i=in_path, o=out_path, div=1)
except (CalledProcessError, FileNotFoundError):
pass
with pytest.warns(UserWarning, match="Warning"):
_commands.cd_hit_div(i=in_path, o=out_path, div=1)

0 comments on commit ad3c14a

Please sign in to comment.