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_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_create_report_noop(): config = Namespace(report=None) with mock.patch.object(io, 'open', autospec=True) as open_: results = tasks.create_report(mock.sentinel.RESULTS, config) assert not open_.called assert results is mock.sentinel.RESULTS
def test_create_report_noop(): config = argparse.Namespace(report=None) with mock.patch.object(io, "open", autospec=True) as open_: results = tasks.create_report(mock.sentinel.RESULTS, config) assert not open_.called assert results is mock.sentinel.RESULTS
def test_create_report_noop(): config = _options.options.namespace(report=None) with mock.patch.object(builtins, "open", autospec=True) as open_: results = tasks.create_report(mock.sentinel.RESULTS, config) assert not open_.called assert results is mock.sentinel.RESULTS