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_popen(tmpdir):
directory = tmpdir.mkdir("tmp")
dirpath = str(directory)
string = "Hello, World!"
code, out, err = popen("echo %s" % string,
output = True)
assert code == 0
assert out == string
assert not err
env = dict({ "FOOBAR": "foobar" })
code, out, err = popen("echo $FOOBAR; echo $PATH",
output = True, env = env)
assert code == 0
assert out == "%s\n%s" % (env["FOOBAR"], os.environ["PATH"])
assert not err
with pytest.raises(sp.CalledProcessError):
code = popen("exit 42")
errstr = "foobar"
with pytest.raises(sp.CalledProcessError):
code = popen("exit 42")
errstr = "foobar"
code, out, err = popen('python -c "raise Exception("%s")"' % errstr,
output = True, raise_err = False)
assert code == 1
assert not out
assert errstr in err
filename = "foobar.txt"
popen("touch %s" % filename, cwd = dirpath)
assert osp.exists(osp.join(dirpath, filename))
code = popen("echo $FOOBAR; echo $PATH", quiet = True)
assert code == 0
assert code == 0
assert out == "%s\n%s" % (env["FOOBAR"], os.environ["PATH"])
assert not err
with pytest.raises(sp.CalledProcessError):
code = popen("exit 42")
errstr = "foobar"
code, out, err = popen('python -c "raise Exception("%s")"' % errstr,
output = True, raise_err = False)
assert code == 1
assert not out
assert errstr in err
filename = "foobar.txt"
popen("touch %s" % filename, cwd = dirpath)
assert osp.exists(osp.join(dirpath, filename))
code = popen("echo $FOOBAR; echo $PATH", quiet = True)
assert code == 0
assert code == 0
assert out == string
assert not err
env = dict({ "FOOBAR": "foobar" })
code, out, err = popen("echo $FOOBAR; echo $PATH",
output = True, env = env)
assert code == 0
assert out == "%s\n%s" % (env["FOOBAR"], os.environ["PATH"])
assert not err
with pytest.raises(sp.CalledProcessError):
code = popen("exit 42")
errstr = "foobar"
code, out, err = popen('python -c "raise Exception("%s")"' % errstr,
output = True, raise_err = False)
assert code == 1
assert not out
assert errstr in err
filename = "foobar.txt"
popen("touch %s" % filename, cwd = dirpath)
assert osp.exists(osp.join(dirpath, filename))
code = popen("echo $FOOBAR; echo $PATH", quiet = True)
assert code == 0
code, out, err = popen("echo %s" % string,
output = True)
assert code == 0
assert out == string
assert not err
env = dict({ "FOOBAR": "foobar" })
code, out, err = popen("echo $FOOBAR; echo $PATH",
output = True, env = env)
assert code == 0
assert out == "%s\n%s" % (env["FOOBAR"], os.environ["PATH"])
assert not err
with pytest.raises(sp.CalledProcessError):
code = popen("exit 42")
errstr = "foobar"
code, out, err = popen('python -c "raise Exception("%s")"' % errstr,
output = True, raise_err = False)
assert code == 1
assert not out
assert errstr in err
filename = "foobar.txt"
popen("touch %s" % filename, cwd = dirpath)
assert osp.exists(osp.join(dirpath, filename))
code = popen("echo $FOOBAR; echo $PATH", quiet = True)
assert code == 0
cli.echo(cli_format("Pipfiles upto date.", cli.GREEN),
file = file_)
if project and pull_request:
errstr = '%s not found. Use %s or the environment variable "%s" to set value.'
if not git_username:
raise ValueError(errstr % ("Git Username", "--git-username", getenvvar("GIT_USERNAME")))
if not git_email:
raise ValueError(errstr % ("Git Email", "--git-email", getenvvar("GIT_EMAIL")))
for p in project:
popen("git config user.name %s" % git_username, cwd = p.path)
popen("git config user.email %s" % git_email, cwd = p.path)
_, output, _ = popen("git status -s", output = True,
cwd = p.path)
if output:
branch = get_timestamp_str(format_ = "%Y%m%d%H%M%S")
popen("git checkout -B %s" % branch, quiet = not verbose,
cwd = p.path
)
title = "fix(dependencies): Update dependencies to latest"
body = ""
# TODO: cross-check with "git add" ?
files = p.requirements + [p.pipfile]
popen("git add %s" % " ".join(files), quiet = not verbose,
cwd = p.path)
popen("git commit -m '%s'" % title, quiet = not verbose,
_, output, _ = popen("git status -s", output = True,
cwd = p.path)
if output:
branch = get_timestamp_str(format_ = "%Y%m%d%H%M%S")
popen("git checkout -B %s" % branch, quiet = not verbose,
cwd = p.path
)
title = "fix(dependencies): Update dependencies to latest"
body = ""
# TODO: cross-check with "git add" ?
files = p.requirements + [p.pipfile]
popen("git add %s" % " ".join(files), quiet = not verbose,
cwd = p.path)
popen("git commit -m '%s'" % title, quiet = not verbose,
cwd = p.path)
popen("git push origin %s" % branch, quiet = not verbose,
cwd = p.path)
if not github_reponame:
raise ValueError(errstr % ("GitHub Reponame", "--github-reponame", getenvvar("GITHUB_REPONAME")))
if not github_username:
raise ValueError(errstr % ("GitHub Username", "--github-username", getenvvar("GITHUB_USERNAME")))
url = "/".join(["https://api.github.com", "repos", github_username, github_reponame, "pulls"])
headers = dict({
"Content-Type": "application/json",
"Authorization": "token %s" % github_access_token
raise_err = kwargs.pop("raise_err", None) or True
params = sequencify(pip_exec) + sequencify(args)
for flag, value in iteritems(kwargs):
if value != False:
flag = "--%s" % kebab_case(flag, delimiter = "_")
params.append(flag)
if not isinstance(value, bool):
value = value_to_envval(value)
params.append(value)
output = output or quiet
output = popen(*params, output = output, raise_err = raise_err)
return output
realpath = osp.realpath(pipfile)
basepath = osp.dirname(realpath)
logger.info("Searching for `pipenv`...")
pipenv = which("pipenv")
if not pipenv:
logger.info("Attempting to install pipenv...")
_pip.call("install", "pipenv")
pipenv = which("pipenv", raise_err = True)
logger.info("`pipenv` found.")
code = popen("%s update" % pipenv, quiet = not verbose, cwd = basepath)
return code == 0
)
if builtins.all(results):
cli.echo(cli_format("Pipfiles upto date.", cli.GREEN),
file = file_)
if project and pull_request:
errstr = '%s not found. Use %s or the environment variable "%s" to set value.'
if not git_username:
raise ValueError(errstr % ("Git Username", "--git-username", getenvvar("GIT_USERNAME")))
if not git_email:
raise ValueError(errstr % ("Git Email", "--git-email", getenvvar("GIT_EMAIL")))
for p in project:
popen("git config user.name %s" % git_username, cwd = p.path)
popen("git config user.email %s" % git_email, cwd = p.path)
_, output, _ = popen("git status -s", output = True,
cwd = p.path)
if output:
branch = get_timestamp_str(format_ = "%Y%m%d%H%M%S")
popen("git checkout -B %s" % branch, quiet = not verbose,
cwd = p.path
)
title = "fix(dependencies): Update dependencies to latest"
body = ""
# TODO: cross-check with "git add" ?
files = p.requirements + [p.pipfile]