Secure your code as it's written. Use Snyk Code to scan source code in minutes - no build needed - and fix issues immediately.
def test_vagrant(self, makegateway, tmpdir, monkeypatch):
vagrant = py.path.local.sysfind("vagrant")
if vagrant is None:
pytest.skip("Vagrant binary not in PATH")
monkeypatch.chdir(tmpdir)
subprocess.check_call("vagrant init hashicorp/precise32", shell=True)
subprocess.check_call("vagrant up --provider virtualbox", shell=True)
gw = makegateway("vagrant_ssh=default")
rinfo = gw._rinfo()
rinfo.cwd == "/home/vagrant"
rinfo.executable == "/usr/bin/python"
subprocess.check_call("vagrant halt", shell=True)
def test_create_crontab_empty(tmpdir, monkeypatch):
def sysexec_raise(x, y):
raise py.process.cmdexec.Error(1, 2, x, "", "")
monkeypatch.setattr(py.path.local, "sysexec", sysexec_raise)
tw = py.io.TerminalWriter()
path = tmpdir.join("devpi-ctl")
if py.path.local.sysfind("crontab"):
cron = gendeploy.create_crontab(tw, tmpdir, path)
assert cron
expect = "crontab %s" % tmpdir.join("crontab")
assert expect in cron
assert "@reboot" in tmpdir.join("crontab").read()
else:
pytest.skip('crontab not installed')
def test_sysfind_in_currentdir(self, path1):
cmd = py.path.local.sysfind('cmd')
root = cmd.new(dirname='', basename='') # c:\ in most installations
with root.as_cwd():
x = py.path.local.sysfind(cmd.relto(root))
assert x.check(file=1)
def test_create_crontab(tmpdir, monkeypatch):
monkeypatch.setattr(py.path.local, "sysexec", lambda x, y: "")
tw = py.io.TerminalWriter()
path = tmpdir.join("devpi-ctl")
if py.path.local.sysfind("crontab"):
cron = gendeploy.create_crontab(tw, tmpdir, path)
assert cron
expect = "crontab %s" % tmpdir.join("crontab")
assert expect in cron
assert "@reboot" in tmpdir.join("crontab").read()
else:
pytest.skip('crontab not installed')
def getexecutable(name, cache={}):
try:
return cache[name]
except KeyError:
executable = py.path.local.sysfind(name)
if executable:
import subprocess
popen = subprocess.Popen(
[str(executable), "--version"],
universal_newlines=True,
stderr=subprocess.PIPE,
)
out, err = popen.communicate()
if name == "jython":
if not err or "2.5" not in err:
executable = None
if "2.5.2" in err:
executable = None # http://bugs.jython.org/issue1790
elif popen.returncode != 0:
# handle pyenv's 127
def setup_module(mod):
py.test.importorskip("docutils")
if not py.path.local.sysfind("gs") or \
not py.path.local.sysfind("dot") or \
not py.path.local.sysfind("latex"):
py.test.skip("ghostscript, graphviz and latex needed")
mod.datadir = getdata()
def popen_output(self, args, cwd=None, report=True):
if isinstance(args, str):
args = shlex.split(args)
assert args[0], args
args = [str(x) for x in args]
if cwd == None:
cwd = self.cwd
cmd = py.path.local.sysfind(args[0])
if not cmd:
self.fatal("command not found: %s" % args[0])
args[0] = str(cmd)
if report:
self.report_popen(args, cwd)
return subprocess.check_output(args, cwd=str(cwd)).decode('utf-8')
def which(program, path):
"""Finds the full path to an executable."""
full_path = None
if path:
full_path = py.path.local.sysfind(program, paths=[path])
if full_path:
return full_path.strpath
full_path = py.path.local.sysfind(program)
if full_path:
return full_path.strpath
logger.error("Program {} not found.".format(program))
raise CommandFailed("Program {} not found".format(program))
def _cmake_needed():
"""Determine if a ``cmake`` binary is needed.
This will check if ``cmake`` is on the path so it can be used if needed.
Installing ``cmake`` into the ``nox``-managed virtual environment can be
forced by setting the ``NOX_INSTALL_CMAKE`` environment variable.
"""
if "NOX_INSTALL_CMAKE" in os.environ:
return True
return py.path.local.sysfind("cmake") is None
def _check_helper(cls, helper):
if py.path.local.sysfind(helper) is None:
py.test.skip("%s is not on your path." % helper)
else:
return helper
_check_helper = classmethod(_check_helper)