Skip to content

Commit

Permalink
Merge pull request #1 from yuanx749/warning
Browse files Browse the repository at this point in the history
Issue warnings
  • Loading branch information
yuanx749 authored Jul 20, 2024
2 parents f8df5ae + 5e7b6b8 commit 833df39
Show file tree
Hide file tree
Showing 3 changed files with 17 additions and 2 deletions.
2 changes: 1 addition & 1 deletion pycdhit/__init__.py
Original file line number Diff line number Diff line change
Expand Up @@ -4,7 +4,7 @@
from ._commands import * # noqa: F403
from ._io import * # noqa: F403

VERSION = "1.0.0"
VERSION = "1.1.0"

__all__ = [ # noqa: F405
"CommandBase",
Expand Down
6 changes: 5 additions & 1 deletion pycdhit/_commands.py
Original file line number Diff line number Diff line change
Expand Up @@ -2,6 +2,7 @@

import os
import subprocess
import warnings
from itertools import chain
from pathlib import Path

Expand Down Expand Up @@ -40,7 +41,7 @@ def _format_program(name: str, path: str = None):

def _run(command):
try:
return subprocess.run(
completed_process = subprocess.run(
command,
capture_output=True,
check=True,
Expand All @@ -53,6 +54,9 @@ def _run(command):
except FileNotFoundError:
print(command)
raise
if "Warning" in completed_process.stdout:
warnings.warn(completed_process.stdout)
return completed_process


def _create_function(name: str, func_name: str, env_var: str):
Expand Down
11 changes: 11 additions & 0 deletions tests/test_commands.py
Original file line number Diff line number Diff line change
Expand Up @@ -34,3 +34,14 @@ def test_cd_hit(cdhit_temp_files):
assert isinstance(res, CompletedProcess)
except (CalledProcessError, FileNotFoundError):
pass


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

0 comments on commit 833df39

Please sign in to comment.