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_init(self):
result = nox.sessions.Result(
session=mock.sentinel.SESSION, status=mock.sentinel.STATUS
)
assert result.session == mock.sentinel.SESSION
assert result.status == mock.sentinel.STATUS
def test_run_manifest_abort_on_first_failure():
# Set up a valid manifest.
config = _options.options.namespace(stop_on_first_error=True)
sessions_ = [
mock.Mock(spec=sessions.SessionRunner),
mock.Mock(spec=sessions.SessionRunner),
]
manifest = Manifest({}, config)
manifest._queue = copy.copy(sessions_)
# Ensure each of the mocks returns a successful result.
for mock_session in sessions_:
mock_session.execute.return_value = sessions.Result(
session=mock_session, status=sessions.Status.FAILED
)
# Run the manifest.
results = tasks.run_manifest(manifest, global_config=config)
# Verify the results look correct.
assert len(results) == 1
assert isinstance(results[0], sessions.Result)
assert results[0].session == sessions_[0]
assert results[0].status == sessions.Status.FAILED
# Verify that only the first session was called.
assert sessions_[0].execute.called
assert not sessions_[1].execute.called
def test__log_error(self):
result = nox.sessions.Result(object(), nox.sessions.Status.FAILED)
with mock.patch.object(logger, "error") as error:
result.log("foo")
error.assert_called_once_with("foo")
def test_create_report():
config = _options.options.namespace(report="/path/to/report")
results = [
sessions.Result(
session=argparse.Namespace(
signatures=["foosig"], name="foo", func=object()
),
status=sessions.Status.SUCCESS,
)
]
with mock.patch.object(io, "open", autospec=True) as open_:
with mock.patch.object(json, "dump", autospec=True) as dump:
answer = tasks.create_report(results, config)
assert answer is results
dump.assert_called_once_with(
{
"result": 1,
"sessions": [
{
"name": "foo",
def test_print_summary():
results = [
sessions.Result(
session=argparse.Namespace(friendly_name="foo"),
status=sessions.Status.SUCCESS,
),
sessions.Result(
session=argparse.Namespace(friendly_name="bar"),
status=sessions.Status.FAILED,
),
]
with mock.patch.object(sessions.Result, "log", autospec=True) as log:
answer = tasks.print_summary(results, object())
assert log.call_count == 2
assert answer is results
def test__bool_false(self):
for status in (nox.sessions.Status.FAILED, nox.sessions.Status.ABORTED):
result = nox.sessions.Result(session=object(), status=status)
assert not bool(result)
assert not result.__bool__()
assert not result.__nonzero__()
def test_print_summary():
results = [
sessions.Result(
session=argparse.Namespace(friendly_name="foo"),
status=sessions.Status.SUCCESS,
),
sessions.Result(
session=argparse.Namespace(friendly_name="bar"),
status=sessions.Status.FAILED,
),
]
with mock.patch.object(sessions.Result, "log", autospec=True) as log:
answer = tasks.print_summary(results, object())
assert log.call_count == 2
assert answer is results
with cwd:
self._create_venv()
session = Session(self)
self.func(session)
# Nothing went wrong; return a success.
return Result(self, Status.SUCCESS)
except nox.virtualenv.InterpreterNotFound as exc:
if self.global_config.error_on_missing_interpreters:
return Result(self, Status.FAILED, reason=str(exc))
else:
return Result(self, Status.SKIPPED, reason=str(exc))
except _SessionQuit as exc:
return Result(self, Status.ABORTED, reason=str(exc))
except _SessionSkip as exc:
return Result(self, Status.SKIPPED, reason=str(exc))
except nox.command.CommandFailed:
return Result(self, Status.FAILED)
except KeyboardInterrupt:
logger.error("Session {} interrupted.".format(self.friendly_name))
raise
except Exception as exc:
logger.exception(
"Session {} raised exception {!r}".format(self.friendly_name, exc)
)
return Result(self, Status.FAILED)
# the noxfile.py file is located.
cwd = py.path.local(
os.path.realpath(os.path.dirname(self.global_config.noxfile))
).as_cwd()
with cwd:
self._create_venv()
session = Session(self)
self.func(session)
# Nothing went wrong; return a success.
return Result(self, Status.SUCCESS)
except nox.virtualenv.InterpreterNotFound as exc:
if self.global_config.error_on_missing_interpreters:
return Result(self, Status.FAILED, reason=str(exc))
else:
return Result(self, Status.SKIPPED, reason=str(exc))
except _SessionQuit as exc:
return Result(self, Status.ABORTED, reason=str(exc))
except _SessionSkip as exc:
return Result(self, Status.SKIPPED, reason=str(exc))
except nox.command.CommandFailed:
return Result(self, Status.FAILED)
except KeyboardInterrupt:
logger.error("Session {} interrupted.".format(self.friendly_name))
raise