Skip to content

Commit

Permalink
Ensure run_and_print prints in one case
Browse files Browse the repository at this point in the history
Convert some run_and_print calls to run since we're not using nose anymore
  • Loading branch information
yesimon committed Sep 25, 2016
1 parent a090edd commit 9abde09
Show file tree
Hide file tree
Showing 6 changed files with 26 additions and 19 deletions.
2 changes: 1 addition & 1 deletion test/integration/snake.py
Expand Up @@ -123,4 +123,4 @@ def run(self, rules=None):
cmd = ['snakemake', '--verbose', '--reason', '--printshellcmds']
if rules:
cmd.extend(rules)
res = util.misc.run_and_print(cmd, check=True, cwd=self.workdir)
res = util.misc.run(cmd, check=True, cwd=self.workdir)
3 changes: 0 additions & 3 deletions test/unit/test_tools_kraken.py
Expand Up @@ -17,9 +17,6 @@ class TestToolKrakenMocked(TestCaseWithTmp):
def setUp(self):
super().setUp()

patcher = mock.patch('util.misc.run_and_print', autospec=True)
self.addCleanup(patcher.stop)
self.mock_run_and_print = patcher.start()
patcher = mock.patch('util.misc.run', autospec=True)
self.addCleanup(patcher.stop)
self.mock_run = patcher.start()
Expand Down
2 changes: 1 addition & 1 deletion test/unit/test_tools_krona.py
Expand Up @@ -17,7 +17,7 @@ def setUp(self):
self.krona = tools.krona.Krona()
self.krona.install()

patcher = patch('util.misc.run_and_print', autospec=True)
patcher = patch('subprocess.check_call', autospec=True)
self.addCleanup(patcher.stop)
self.mock_run = patcher.start()

Expand Down
15 changes: 7 additions & 8 deletions tools/kraken.py
Expand Up @@ -53,7 +53,7 @@ def build(self, db, options=None, option_string=None):
'''
self.execute('kraken-build', db, db, options=options,
option_string=option_string)

def classify(self, inBam, db, outReads, numThreads=None):
"""Classify input reads (bam)
Expand Down Expand Up @@ -88,13 +88,13 @@ def classify(self, inBam, db, outReads, numThreads=None):
res = self.execute('kraken', db, outReads, args=[tmp_fastq1, tmp_fastq2], options=opts)
os.unlink(tmp_fastq1)
os.unlink(tmp_fastq2)

def filter(self, inReads, db, outReads, filterThreshold):
"""Filter Kraken hits
"""
self.execute('kraken-filter', db, outReads, args=[inReads],
options={'--threshold': filterThreshold})

def report(self, inReads, db, outReport):
"""Convert Kraken read-based output to summary reports
"""
Expand Down Expand Up @@ -133,13 +133,12 @@ def execute(self, command, db, output, args=None, options=None,
elif command == 'kraken-build':
jellyfish_path = Jellyfish().install_and_get_path()
env = os.environ.copy()
env['PATH'] = ':'.join([os.path.dirname(jellyfish_path),
env['PATH']])
util.misc.run_and_print(cmd, env=env, check=True, silent=False)
env['PATH'] = ':'.join([os.path.dirname(jellyfish_path), env['PATH']])
subprocess.check_call(cmd, env=env)
else:
with util.file.open_or_gzopen(output, 'w') as of:
util.misc.run(cmd, stdout=of, stderr=subprocess.PIPE,
check=True)
util.misc.run(cmd, stdout=of, stderr=subprocess.PIPE, check=True)


@tools.skip_install_test(condition=tools.is_osx())
class Jellyfish(Kraken):
Expand Down
5 changes: 2 additions & 3 deletions tools/krona.py
Expand Up @@ -2,7 +2,6 @@
import os.path
import subprocess
from os.path import join
import util.misc
from builtins import super

TOOL_NAME = 'krona'
Expand Down Expand Up @@ -55,7 +54,7 @@ def import_taxonomy(self,
cmd.append('-k')
cmd.extend(input_tsvs)

util.misc.run_and_print(cmd, env=env, check=True)
subprocess.check_call(cmd, env=env, check=True)

def create_db(self, db_dir):
"""Caution - this deletes the original .dmp files."""
Expand All @@ -65,4 +64,4 @@ def create_db(self, db_dir):

sh = join(self.opt, 'updateTaxonomy.sh')
cmd = [sh, '--only-build', os.path.abspath(db_dir)]
util.misc.run_and_print(cmd, env=env, check=True)
subprocess.check_call(cmd, env=env, check=True)
18 changes: 15 additions & 3 deletions util/misc.py
Expand Up @@ -209,9 +209,21 @@ def run_and_print(args, stdout=None, stderr=None,
if not buffered:
if check and not silent:
try:
result = run(args, stdin=stdin, stdout=subprocess.PIPE,
stderr=subprocess.STDOUT, env=env, cwd=cwd,
timeout=timeout, check=check)
result = run(
args,
stdin=stdin,
stdout=subprocess.PIPE,
stderr=subprocess.STDOUT,
env=env,
cwd=cwd,
timeout=timeout,
check=check
)
print(result.stdout.decode('utf-8'))
try:
print(result.stderr.decode('utf-8'))
except AttributeError:
pass
except subprocess.CalledProcessError as e:
if loglevel:
try:
Expand Down

0 comments on commit 9abde09

Please sign in to comment.