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_exit_code(initproj, cmd, exit_code, mocker):
""" Check for correct InvocationError, with exit code,
except for zero exit code """
import tox.exception
mocker.spy(tox.exception, "exit_code_str")
tox_ini_content = "[testenv:foo]\ncommands=python -c 'import sys; sys.exit({:d})'".format(
exit_code
)
initproj("foo", filedefs={"tox.ini": tox_ini_content})
cmd()
if exit_code:
# need mocker.spy above
assert tox.exception.exit_code_str.call_count == 1
(args, kwargs) = tox.exception.exit_code_str.call_args
assert kwargs == {}
(call_error_name, call_command, call_exit_code) = args
assert call_error_name == "InvocationError"
# quotes are removed in result.out
# do not include "python" as it is changed to python.EXE by appveyor
expected_command_arg = " -c 'import sys; sys.exit({:d})'".format(exit_code)
assert expected_command_arg in call_command
cmd()
if exit_code:
# need mocker.spy above
assert tox.exception.exit_code_str.call_count == 1
(args, kwargs) = tox.exception.exit_code_str.call_args
assert kwargs == {}
(call_error_name, call_command, call_exit_code) = args
assert call_error_name == "InvocationError"
# quotes are removed in result.out
# do not include "python" as it is changed to python.EXE by appveyor
expected_command_arg = " -c 'import sys; sys.exit({:d})'".format(exit_code)
assert expected_command_arg in call_command
assert call_exit_code == exit_code
else:
# need mocker.spy above
assert tox.exception.exit_code_str.call_count == 0
def main(args):
setup_reporter(args)
try:
config = load_config(args)
config.logdir.ensure(dir=1)
with set_os_env_var(str("TOX_WORK_DIR"), config.toxworkdir):
session = build_session(config)
exit_code = session.runcommand()
if exit_code is None:
exit_code = 0
raise SystemExit(exit_code)
except tox.exception.BadRequirement:
raise SystemExit(1)
except KeyboardInterrupt:
raise SystemExit(2)
def _replace(self, value, name=None, section_name=None, crossonly=False):
if "{" not in value:
return value
section_name = section_name if section_name else self.section_name
self._subststack.append((section_name, name))
try:
replaced = Replacer(self, crossonly=crossonly).do_replace(value)
assert self._subststack.pop() == (section_name, name)
except tox.exception.MissingSubstitution:
if not section_name.startswith(testenvprefix):
raise tox.exception.ConfigError(
"substitution env:{!r}: unknown or recursive definition in"
" section {!r}.".format(value, section_name)
)
raise
return replaced
def getsupportedinterpreter(self):
if tox.INFO.IS_WIN and self.basepython and "jython" in self.basepython:
raise tox.exception.UnsupportedInterpreter(
"Jython/Windows does not support installing scripts"
)
info = self.config.interpreters.get_info(envconfig=self)
if not info.executable:
raise tox.exception.InterpreterNotFound(self.basepython)
if not info.version_info:
raise tox.exception.InvocationError(
"Failed to get version_info for {}: {}".format(info.name, info.err)
)
return info.executable
else:
live_config = self._getliveconfig()
deps_subset_match = getattr(self.envconfig, "deps_matches_subset", False)
outcome, reason = rconfig.matches_with_reason(live_config, deps_subset_match)
if reason is None:
action.info("reusing", self.envconfig.envdir)
return
action.info("cannot reuse", reason)
if rconfig is None:
action.setactivity("create", self.envconfig.envdir)
else:
action.setactivity("recreate", self.envconfig.envdir)
try:
self.hook.tox_testenv_create(action=action, venv=self)
self.just_created = True
except tox.exception.UnsupportedInterpreter as exception:
return exception
try:
self.hook.tox_testenv_install_deps(action=action, venv=self)
except tox.exception.InvocationError as exception:
return "could not install deps {}; v = {!r}".format(self.envconfig.deps, exception)
else:
live_config = self._getliveconfig()
deps_subset_match = getattr(self.envconfig, "deps_matches_subset", False)
outcome, reason = rconfig.matches_with_reason(live_config, deps_subset_match)
if reason is None:
action.info("reusing", self.envconfig.envdir)
return
action.info("cannot reuse", reason)
if rconfig is None:
action.setactivity("create", self.envconfig.envdir)
else:
action.setactivity("recreate", self.envconfig.envdir)
try:
self.hook.tox_testenv_create(action=action, venv=self)
self.just_created = True
except tox.exception.UnsupportedInterpreter as exception:
return exception
try:
self.hook.tox_testenv_install_deps(action=action, venv=self)
except tox.exception.InvocationError as exception:
return "could not install deps {}; v = {!r}".format(self.envconfig.deps, exception)