@ -3061,6 +3061,7 @@ class ChangelistTest(unittest.TestCase):
return_value = ( ' origin ' , ' refs/remotes/origin/main ' ) ) . start ( )
return_value = ( ' origin ' , ' refs/remotes/origin/main ' ) ) . start ( )
mock . patch ( ' git_cl.PRESUBMIT_SUPPORT ' , ' PRESUBMIT_SUPPORT ' ) . start ( )
mock . patch ( ' git_cl.PRESUBMIT_SUPPORT ' , ' PRESUBMIT_SUPPORT ' ) . start ( )
mock . patch ( ' git_cl.Settings.GetRoot ' , return_value = ' root ' ) . start ( )
mock . patch ( ' git_cl.Settings.GetRoot ' , return_value = ' root ' ) . start ( )
mock . patch ( ' git_cl.Settings.GetIsGerrit ' , return_value = True ) . start ( )
mock . patch ( ' git_cl.time_time ' ) . start ( )
mock . patch ( ' git_cl.time_time ' ) . start ( )
mock . patch ( ' metrics.collector ' ) . start ( )
mock . patch ( ' metrics.collector ' ) . start ( )
mock . patch ( ' subprocess2.Popen ' ) . start ( )
mock . patch ( ' subprocess2.Popen ' ) . start ( )
@ -3231,6 +3232,53 @@ class ChangelistTest(unittest.TestCase):
' --description_file ' , ' /tmp/fake-temp1 ' ,
' --description_file ' , ' /tmp/fake-temp1 ' ,
] )
] )
def testRunHook_NoGerrit ( self ) :
mock . patch ( ' git_cl.Settings.GetIsGerrit ' , return_value = False ) . start ( )
expected_results = {
' more_cc ' : [ ' cc@example.com ' , ' more@example.com ' ] ,
' errors ' : [ ] ,
' notifications ' : [ ] ,
' warnings ' : [ ] ,
}
gclient_utils . FileRead . return_value = json . dumps ( expected_results )
git_cl . time_time . side_effect = [ 100 , 200 , 300 , 400 ]
mockProcess = mock . Mock ( )
mockProcess . wait . return_value = 0
subprocess2 . Popen . return_value = mockProcess
git_cl . Changelist . GetAuthor . return_value = None
git_cl . Changelist . GetIssue . return_value = None
git_cl . Changelist . GetPatchset . return_value = None
cl = git_cl . Changelist ( )
results = cl . RunHook (
committing = False ,
may_prompt = False ,
verbose = 0 ,
parallel = False ,
upstream = ' upstream ' ,
description = ' description ' ,
all_files = False ,
resultdb = False )
self . assertEqual ( expected_results , results )
subprocess2 . Popen . assert_any_call ( [
' vpython3 ' , ' PRESUBMIT_SUPPORT ' ,
' --root ' , ' root ' ,
' --upstream ' , ' upstream ' ,
' --upload ' ,
' --json_output ' , ' /tmp/fake-temp2 ' ,
' --description_file ' , ' /tmp/fake-temp1 ' ,
] )
gclient_utils . FileWrite . assert_any_call (
' /tmp/fake-temp1 ' , ' description ' )
metrics . collector . add_repeated ( ' sub_commands ' , {
' command ' : ' presubmit ' ,
' execution_time ' : 100 ,
' exit_code ' : 0 ,
} )
@mock.patch ( ' sys.exit ' , side_effect = SystemExitMock )
@mock.patch ( ' sys.exit ' , side_effect = SystemExitMock )
def testRunHook_Failure ( self , _mock ) :
def testRunHook_Failure ( self , _mock ) :
git_cl . time_time . side_effect = [ 100 , 200 ]
git_cl . time_time . side_effect = [ 100 , 200 ]