2016-03-07 00:08:57 +00:00
|
|
|
# -*- coding: utf-8 -*-
|
2014-01-05 15:50:57 +00:00
|
|
|
# Copyright (C) 2013-2014 Bastian Kleineidam
|
2016-03-07 00:08:57 +00:00
|
|
|
# Copyright (C) 2016 Tobias Gruetzmacher
|
|
|
|
|
2013-03-04 18:10:27 +00:00
|
|
|
import os
|
2013-03-26 20:12:02 +00:00
|
|
|
import pytest
|
2016-03-07 00:08:57 +00:00
|
|
|
import shutil
|
|
|
|
import subprocess
|
|
|
|
import tempfile
|
2013-03-04 18:10:27 +00:00
|
|
|
|
|
|
|
basedir = os.path.dirname(__file__)
|
|
|
|
dosage_cmd = os.path.join(os.path.dirname(basedir), "dosage")
|
2013-03-12 20:07:32 +00:00
|
|
|
|
2013-03-04 18:10:27 +00:00
|
|
|
|
2016-03-07 00:08:57 +00:00
|
|
|
def run(cmd, verbosity=0, **kwargs):
|
2013-03-04 18:10:27 +00:00
|
|
|
"""Run command without error checking.
|
|
|
|
@return: command return code"""
|
|
|
|
if kwargs.get("shell"):
|
|
|
|
# for shell calls the command must be a string
|
|
|
|
cmd = " ".join(cmd)
|
|
|
|
return subprocess.call(cmd, **kwargs)
|
|
|
|
|
|
|
|
|
2016-03-07 00:08:57 +00:00
|
|
|
def run_checked(cmd, ret_ok=(0,), **kwargs):
|
2013-03-04 18:10:27 +00:00
|
|
|
"""Run command and raise OSError on error."""
|
|
|
|
retcode = run(cmd, **kwargs)
|
|
|
|
if retcode not in ret_ok:
|
|
|
|
msg = "Command `%s' returned non-zero exit status %d" % (cmd, retcode)
|
|
|
|
raise OSError(msg)
|
|
|
|
return retcode
|
2013-03-26 20:12:02 +00:00
|
|
|
|
|
|
|
|
2016-03-07 00:08:57 +00:00
|
|
|
@pytest.yield_fixture
|
|
|
|
def tmpdir():
|
|
|
|
tmpdir = tempfile.mkdtemp()
|
|
|
|
yield tmpdir
|
|
|
|
shutil.rmtree(tmpdir)
|