@ -22,6 +22,7 @@ from unittest import mock
DEPOT_TOOLS_ROOT = os . path . dirname ( os . path . dirname ( os . path . abspath ( __file__ ) ) )
DEPOT_TOOLS_ROOT = os . path . dirname ( os . path . dirname ( os . path . abspath ( __file__ ) ) )
sys . path . insert ( 0 , DEPOT_TOOLS_ROOT )
sys . path . insert ( 0 , DEPOT_TOOLS_ROOT )
import subprocess2
from testing_support import coverage_utils
from testing_support import coverage_utils
from testing_support import git_test_utils
from testing_support import git_test_utils
@ -258,7 +259,6 @@ class GitReadOnlyFunctionsTest(git_test_utils.GitRepoReadOnlyTestBase,
self . repo . run ( testfn )
self . repo . run ( testfn )
def testStreamWithRetcodeException ( self ) :
def testStreamWithRetcodeException ( self ) :
import subprocess2
with self . assertRaises ( subprocess2 . CalledProcessError ) :
with self . assertRaises ( subprocess2 . CalledProcessError ) :
with self . gc . run_stream_with_retcode ( ' checkout ' , ' unknown-branch ' ) :
with self . gc . run_stream_with_retcode ( ' checkout ' , ' unknown-branch ' ) :
pass
pass
@ -1173,6 +1173,83 @@ class WarnSubmoduleTest(unittest.TestCase):
sys . stdout . getvalue ( ) )
sys . stdout . getvalue ( ) )
@mock.patch ( ' time.sleep ' )
@mock.patch ( ' git_common._run_with_stderr ' )
class RunWithStderr ( GitCommonTestBase ) :
def setUp ( self ) :
super ( RunWithStderr , self ) . setUp ( )
msg = ' error: could not lock config file .git/config: File exists '
self . lock_failure = self . calledProcessError ( msg )
msg = ' error: wrong number of arguments, should be 2 '
self . wrong_param = self . calledProcessError ( msg )
def calledProcessError ( self , stderr ) :
return subprocess2 . CalledProcessError (
2 ,
cmd = [ ' a ' , ' b ' , ' c ' ] , # doesn't matter
cwd = ' / ' ,
stdout = ' ' ,
stderr = stderr . encode ( ' utf-8 ' ) ,
)
def runGitCheckout ( self , ex , retry_lock ) :
with self . assertRaises ( type ( ex ) ) :
self . gc . run_with_stderr ( ' checkout ' , ' a ' , retry_lock = retry_lock )
def runGitConfig ( self , ex , retry_lock ) :
with self . assertRaises ( type ( ex ) ) :
self . gc . run_with_stderr ( ' config ' , ' set ' , retry_lock = retry_lock )
def test_config_with_non_lock_failure ( self , run_mock , _ ) :
""" Tests git-config with a non-lock-failure. """
ex = self . wrong_param
run_mock . side_effect = ex
# retry_lock == True
self . runGitConfig ( ex , retry_lock = True )
self . assertEqual ( run_mock . call_count , 1 ) # 1 + 0 (retry)
# retry_lock == False
run_mock . reset_mock ( )
self . runGitConfig ( ex , retry_lock = False )
self . assertEqual ( run_mock . call_count , 1 ) # 1 + 0 (retry)
def test_config_with_lock_failure ( self , run_mock , _ ) :
""" Tests git-config with a lock-failure. """
ex = self . lock_failure
run_mock . side_effect = ex
# retry_lock == True
self . runGitConfig ( ex , retry_lock = True )
self . assertEqual ( run_mock . call_count , 6 ) # 1 + 5 (retry)
# retry_lock == False
run_mock . reset_mock ( )
self . runGitConfig ( ex , retry_lock = False )
self . assertEqual ( run_mock . call_count , 1 ) # 1 + 0 (retry)
def test_checkout_with_non_lock_failure ( self , run_mock , _ ) :
""" Tests git-checkout with a non-lock-failure. """
ex = self . wrong_param
run_mock . side_effect = ex
# retry_lock == True
self . runGitCheckout ( ex , retry_lock = True )
self . assertEqual ( run_mock . call_count , 1 ) # 1 + 0 (retry)
# retry_lock == False
run_mock . reset_mock ( )
self . runGitCheckout ( ex , retry_lock = False )
self . assertEqual ( run_mock . call_count , 1 ) # 1 + 0 (retry)
def test_checkout_with_lock_failure ( self , run_mock , _ ) :
""" Tests git-checkout with a lock-failure. """
ex = self . lock_failure
run_mock . side_effect = ex
# retry_lock == True
self . runGitCheckout ( ex , retry_lock = True )
self . assertEqual ( run_mock . call_count , 1 ) # 1 + 0 (retry)
# retry_lock == False
run_mock . reset_mock ( )
self . runGitCheckout ( ex , retry_lock = False )
self . assertEqual ( run_mock . call_count , 1 ) # 1 + 0 (retry)
if __name__ == ' __main__ ' :
if __name__ == ' __main__ ' :
sys . exit (
sys . exit (
coverage_utils . covered_main (
coverage_utils . covered_main (