Skip to content

Commit

Permalink
Add tests for CLI to verify return code of failing commands
Browse files Browse the repository at this point in the history
  • Loading branch information
althonos committed Jun 16, 2020
1 parent ad240fb commit e1af287
Show file tree
Hide file tree
Showing 2 changed files with 28 additions and 2 deletions.
1 change: 1 addition & 0 deletions setup.cfg
Original file line number Diff line number Diff line change
Expand Up @@ -61,6 +61,7 @@ universal = true
formats = gztar

[coverage:report]
include = orthoani/*.py
show_missing = true
exclude_lines =
pragma: no cover
Expand Down
29 changes: 27 additions & 2 deletions tests/test_cli.py
Original file line number Diff line number Diff line change
Expand Up @@ -4,7 +4,6 @@
import unittest
import subprocess
import sys
from subprocess import PIPE

from Bio.SeqIO import read

Expand All @@ -17,9 +16,35 @@ def setUpClass(cls):
cls.data = pathlib.Path(__file__).parent / "data"
cls.p1, cls.p2 = map(os.fspath, cls.data.glob("*.fna"))

def shell(self, args):
return subprocess.run(
args,
stdout=subprocess.PIPE,
stderr=subprocess.DEVNULL,
cwd=self.data.parent.parent,
)

def test_orthoani_cli(self):
# check the score we get is the same as the OrthoANI Java implementation
args = [sys.executable, "-m", "orthoani", "-q", self.p1, "-r", self.p2]
proc = subprocess.run(args, stdout=PIPE, cwd=self.data.parent.parent)
proc = self.shell(args)
proc.check_returncode()
self.assertEqual(proc.stdout, b"0.5725\n")

def test_return_code(self):
args = [sys.executable, "-m", "orthoani", "-q", self.data, "-r", self.p2]
proc = self.shell(args)
self.assertEqual(proc.returncode, 21) # IsADirectoryError

args = [sys.executable, "-m", "orthoani", "-q", "_", "-r", self.p2]
proc = self.shell(args)
self.assertEqual(proc.returncode, 2) # FileNotFoundError

def test_return_code_traceback(self):
args = [sys.executable, "-m", "orthoani", "-T", "-q", self.data, "-r", self.p2]
proc = self.shell(args)
self.assertEqual(proc.returncode, 21) # IsADirectoryError

args = [sys.executable, "-m", "orthoani", "-T", "-q", "_", "-r", self.p2]
proc = self.shell(args)
self.assertEqual(proc.returncode, 2) # FileNotFoundError

0 comments on commit e1af287

Please sign in to comment.