def test_print_summary(): results = [ sessions.Result(session='foo', status=sessions.Status.SUCCESS), sessions.Result(session='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_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_create_report(): config = Namespace(report='/path/to/report') results = [ sessions.Result( session=Namespace(signature='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', 'signature': 'foosig', 'result': 'success', 'result_code': 1, 'args': {}, }], }, mock.ANY, indent=2) open_.assert_called_once_with('/path/to/report', 'w')
def test_run_manifest_abort_on_first_failure(): # Set up a valid manifest. config = 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_run_manifest(): # Set up a valid manifest. config = Namespace(stop_on_first_error=False) 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.SUCCESS, ) # Run the manifest. results = tasks.run_manifest(manifest, global_config=config) # Verify the results look correct. assert len(results) == 2 assert results[0].session == sessions_[0] assert results[1].session == sessions_[1] for result in results: assert isinstance(result, sessions.Result) assert result.status == sessions.Status.SUCCESS
def test_create_report(): config = argparse.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", "signatures": ["foosig"], "result": "success", "result_code": 1, "args": {}, } ], }, mock.ANY, indent=2, ) open_.assert_called_once_with("/path/to/report", "w")
def test_run_manifest(with_warnings): # Set up a valid manifest. config = _options.options.namespace(stop_on_first_error=False) 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.SUCCESS) # we need the should_warn attribute, add some func if with_warnings: mock_session.name = "hello" mock_session.func = session_func_venv_pythons_warning else: mock_session.func = session_func # Run the manifest. results = tasks.run_manifest(manifest, global_config=config) # Verify the results look correct. assert len(results) == 2 assert results[0].session == sessions_[0] assert results[1].session == sessions_[1] for result in results: assert isinstance(result, sessions.Result) assert result.status == sessions.Status.SUCCESS