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_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)
def _collect_session(result):
prev_build = tox.session.build_session
def build_session(config):
result.session = prev_build(config)
return result.session
monkeypatch.setattr(tox.session, "build_session", build_session)
def create_new_config_file_(args, source=None, plugins=(), filename="tox.ini"):
if source is None:
source = args
args = []
s = textwrap.dedent(source)
p = tmpdir.join(filename)
p.write(s)
tox.session.setup_reporter(args)
with tmpdir.as_cwd():
return parseconfig(args, plugins=plugins)
def _collect_session(result):
prev_build = tox.session.build_session
def build_session(config):
result.session = prev_build(config)
return result.session
monkeypatch.setattr(tox.session, "build_session", build_session)
def tox_testenv_create(self, action, venv):
assert isinstance(action, tox.session.Action)
assert isinstance(venv, VirtualEnv)
log.append(1)
def run(self):
prev_build = tox.session.build_session
def build_session(config):
res.session = prev_build(config)
res._popen = res.session.popen
monkeypatch.setattr(res.session, "popen", popen)
return res.session
monkeypatch.setattr(tox.session, "build_session", build_session)
def popen(cmd, **kwargs):
activity_id = _actions[-1].name
activity_name = _actions[-1].activity
ret = "NOTSET"
try:
ret = res._popen(cmd, **kwargs)
except tox.exception.InvocationError as exception:
ret = exception
finally:
res.popens.append(
(activity_id, activity_name, kwargs.get("env"), ret, cmd)
)
return ret
_actions = []
def test_provision_cli_args_ignore(cmd, initproj, monkeypatch, plugin):
import tox.config
import tox.session
prev_ensure = tox.config.ParseIni.ensure_requires_satisfied
@staticmethod
def ensure_requires_satisfied(config, requires, min_version):
result = prev_ensure(config, requires, min_version)
config.run_provision = True
return result
monkeypatch.setattr(
tox.config.ParseIni, "ensure_requires_satisfied", ensure_requires_satisfied
)
prev_get_venv = tox.session.Session.getvenv
def getvenv(self, name):
venv = prev_get_venv(self, name)
venv.envconfig.envdir = py.path.local(sys.executable).dirpath().dirpath()
venv.setupenv = lambda: True
venv.finishvenv = lambda: True
return venv
monkeypatch.setattr(tox.session.Session, "getvenv", getvenv)
initproj("test-0.1", {"tox.ini": "[tox]"})
result = cmd("-a", "--option", "b")
result.assert_success(is_run_test_env=False)
def prepare_tox(self):
toxini = os.path.join(os.path.dirname(__file__), 'tox.ini')
config = tox.session.prepare(['-c', toxini])
name = uuid.uuid4().hex
envconfig = TestenvConfig(name, config, None, None)
envconfig.envdir = local('%s/%s' % (config.toxworkdir, name))
envconfig.envlogdir = local('%s/log-%s' % (config.toxworkdir, name))
envconfig.basepython = sys.executable
envconfig.sitepackages = False
envconfig.downloadcache = False
envconfig.pip_pre = False
envconfig.setenv = []
envconfig.install_command = 'pip install {opts} {packages}'.split()
config.envconfigs[name] = envconfig
session = tox.session.Session(config)
self.venv = session.getvenv(name)
def prepare_tox(self):
toxini = os.path.join(os.path.dirname(__file__), 'tox.ini')
config = tox.session.prepare(['-c', toxini])
name = uuid.uuid4().hex
envconfig = TestenvConfig(name, config, None, None)
envconfig.envdir = local('%s/%s' % (config.toxworkdir, name))
envconfig.envlogdir = local('%s/log-%s' % (config.toxworkdir, name))
envconfig.basepython = sys.executable
envconfig.sitepackages = False
envconfig.downloadcache = False
envconfig.pip_pre = False
envconfig.setenv = []
envconfig.install_command = 'pip install {opts} {packages}'.split()
config.envconfigs[name] = envconfig
session = tox.session.Session(config)
self.venv = session.getvenv(name)
class FakeTerminalWriter(object):
'''
Redirect TerminalWriter messages to a log file
'''
hasmarkup = True
def sep(self, char, message, **kwargs):
return '-'
def line(self, msg, *args, **kargs):
retox_log.info("tox: " + msg)
class RetoxReporter(tox.session.Reporter):
'''
A custom tox reporter designed for updating a live UI
'''
screen = None
env_frames = None
def __init__(self, session):
'''
Create a new reporter
:param session: The Tox Session
:type session: :class:`tox.session.Session`
'''
super(RetoxReporter, self).__init__(session)
self._actionmayfinish = set()