#NEWLINE# @ mock . patch ( 'rally.cli.commands.task.jsonschema.validate' , return_value = None ) #NEWLINE# @ mock . patch ( 'rally.cli.commands.task.os.path.realpath' , side_effect = ( lambda p : ( 'realpath_%s' % p ) ) ) #NEWLINE# @ mock . patch ( 'rally.cli.commands.task.open' , side_effect = mock . mock_open ( ) , create = True ) #NEWLINE# @ mock . patch ( 'rally.cli.commands.task.plot' ) #NEWLINE# @ mock . patch ( 'rally.cli.commands.task.webbrowser' ) #NEWLINE# @ mock . patch ( 'rally.cli.commands.task.api.Task.get' ) #NEWLINE# def test_report_one_uuid( self , mock_task_get , mock_webbrowser , mock_plot , mock_open , mock_realpath , mock_validate ) : #NEWLINE# #INDENT# task_id = 'eb290c30-38d8-4c8f-bbcc-fc8f74b004ae' #NEWLINE# data = [ { #NEWLINE# #INDENT# 'key' : { #NEWLINE# #INDENT# 'name' : 'class.test' , #NEWLINE# 'pos' : 0 , #NEWLINE# #UNINDENT# } , #NEWLINE# 'data' : { #NEWLINE# #INDENT# 'raw' : 'foo_raw' , #NEWLINE# 'sla' : 'foo_sla' , #NEWLINE# 'load_duration' : 0.1 , #NEWLINE# 'full_duration' : 1.2 , #NEWLINE# #UNINDENT# } , #NEWLINE# #UNINDENT# } , { #NEWLINE# #INDENT# 'key' : { #NEWLINE# #INDENT# 'name' : 'class.test' , #NEWLINE# 'pos' : 0 , #NEWLINE# #UNINDENT# } , #NEWLINE# 'data' : { #NEWLINE# #INDENT# 'raw' : 'bar_raw' , #NEWLINE# 'sla' : 'bar_sla' , #NEWLINE# 'load_duration' : 2.1 , #NEWLINE# 'full_duration' : 2.2 , #NEWLINE# #UNINDENT# } , #NEWLINE# #UNINDENT# } ] #NEWLINE# results = [ { #NEWLINE# #INDENT# 'key' : x [ 'key' ] , #NEWLINE# 'result' : x [ 'data' ] [ 'raw' ] , #NEWLINE# 'sla' : x [ 'data' ] [ 'sla' ] , #NEWLINE# 'load_duration' : x [ 'data' ] [ 'load_duration' ] , #NEWLINE# 'full_duration' : x [ 'data' ] [ 'full_duration' ] , #NEWLINE# #UNINDENT# } for x in data ] #NEWLINE# mock_results = mock . Mock ( return_value = data ) #NEWLINE# mock_task_get . return_value = mock . Mock ( get_results = mock_results ) #NEWLINE# mock_plot . plot . return_value = 'html_report' #NEWLINE# def reset_mocks( ) : #NEWLINE# #INDENT# for m in ( mock_task_get , mock_webbrowser , mock_plot , mock_open ) : #NEWLINE# #INDENT# m . reset_mock ( ) #NEWLINE# #UNINDENT# #UNINDENT# self . task . report ( tasks = task_id , out = ( '/tmp/%s.html' % task_id ) ) #NEWLINE# mock_open . assert_called_once_with ( ( '/tmp/%s.html' % task_id ) , 'w+' ) #NEWLINE# mock_plot . plot . assert_called_once_with ( results , include_libs = False ) #NEWLINE# mock_open . side_effect ( ) . write . assert_called_once_with ( 'html_report' ) #NEWLINE# mock_task_get . assert_called_once_with ( task_id ) #NEWLINE# reset_mocks ( ) #NEWLINE# self . task . report ( tasks = task_id , out = ( '/tmp/%s.html' % task_id ) , out_format = 'junit' ) #NEWLINE# mock_open . assert_called_once_with ( ( '/tmp/%s.html' % task_id ) , 'w+' ) #NEWLINE# self . assertFalse ( mock_plot . plot . called ) #NEWLINE# reset_mocks ( ) #NEWLINE# self . task . report ( task_id , out = 'output.html' , open_it = True , out_format = 'html' ) #NEWLINE# mock_webbrowser . open_new_tab . assert_called_once_with ( 'file://realpath_output.html' ) #NEWLINE# mock_plot . plot . assert_called_once_with ( results , include_libs = False ) #NEWLINE# reset_mocks ( ) #NEWLINE# self . task . report ( task_id , open_it = False , out = 'output.html' , out_format = 'html_static' ) #NEWLINE# self . assertFalse ( mock_webbrowser . open_new_tab . called ) #NEWLINE# mock_plot . plot . assert_called_once_with ( results , include_libs = True )