Dive into secure and efficient coding practices with our curated list of the top 10 examples showcasing 'tox' in functional components in Python. Our advanced machine learning engine meticulously scans each line of code, cross-referencing millions of open source libraries to ensure your implementation is not just functional, but also robust and secure. Elevate your React applications to new heights by mastering the art of handling side effects, API calls, and asynchronous operations with confidence and precision.
def run_tests(self):
import tox
errno = tox.cmdline(self.tox_args)
sys.exit(errno)
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 test_sdist_latest(tmpdir, newconfig):
distshare = tmpdir.join("distshare")
config = newconfig(
[],
"""
[tox]
distshare={}
sdistsrc={{distshare}}/pkg123-*
""".format(
distshare
),
)
p = distshare.ensure("pkg123-1.4.5.zip")
distshare.ensure("pkg123-1.4.5a1.zip")
session = Session(config)
_, dist = get_package(session)
assert dist == p
def test_subcommand_test_post_hook(self, mocker):
"""It should return the same retcode, but run the hook."""
subcommand_test = mocker.patch('tox.session.Session.subcommand_test',
return_value=42)
tox_subcommand_test_post = mocker.Mock()
subcommand_test_monkeypatch(tox_subcommand_test_post)
import tox.session
session = mocker.Mock()
real_subcommand_test = tox.session.Session.subcommand_test
# Python 2 compat
real_subcommand_test = getattr(
real_subcommand_test, '__func__', real_subcommand_test)
assert real_subcommand_test(session) == 42
subcommand_test.assert_called_once_with(session)
tox_subcommand_test_post.assert_called_once_with(session.config)
commands_pre = python -c 'print("START")'
commands = python -c 'print("OK")'
- python -c 'raise SystemExit(1)'
python -c 'raise SystemExit(2)'
python -c 'print("SHOULD NOT HAPPEN")'
commands_post = python -c 'print("END")'
"""
},
)
json_path = cwd / "res.json"
result = cmd("--result-json", json_path)
result.assert_fail()
data = json.loads(json_path.read_text(encoding="utf-8"))
assert data["reportversion"] == "1"
assert data["toxversion"] == tox.__version__
for env_data in data["testenvs"].values():
for command_type in ("setup", "test"):
if command_type not in env_data:
assert False, "missing {}".format(command_type)
for command in env_data[command_type]:
assert isinstance(command["command"], list)
assert command["output"]
assert "retcode" in command
assert isinstance(command["retcode"], int)
# virtualenv, deps install, package install, freeze
assert len(env_data["setup"]) == 4
# 1 pre + 3 command + 1 post
assert len(env_data["test"]) == 5
assert isinstance(env_data["installed_packages"], list)
pyinfo = env_data["python"]
def test_log_pcall(self, mocksession):
mocksession.logging_levels(quiet=Verbosity.DEFAULT, verbose=Verbosity.INFO)
mocksession.config.logdir.ensure(dir=1)
assert not mocksession.config.logdir.listdir()
with mocksession.newaction("what", "something") as action:
action.popen(["echo"])
match = mocksession.report.getnext("logpopen")
log_name = py.path.local(match[1].split(">")[-1].strip()).relto(
mocksession.config.logdir
)
assert log_name == "what-0.log"
def test_log_pcall(self, mocksession):
mocksession.logging_levels(quiet=Verbosity.DEFAULT, verbose=Verbosity.INFO)
mocksession.config.logdir.ensure(dir=1)
assert not mocksession.config.logdir.listdir()
with mocksession.newaction("what", "something") as action:
action.popen(["echo"])
match = mocksession.report.getnext("logpopen")
log_name = py.path.local(match[1].split(">")[-1].strip()).relto(
mocksession.config.logdir
)
assert log_name == "what-0.log"
def run_tests(self):
import tox
tox.cmdline(self.test_args)
@tox.hookimpl
def tox_runtest_pre(self):
log.append("started")