@ -2668,13 +2668,14 @@ the current line as well!
self . assertEqual ( 1 , len ( results ) )
self . assertIsInstance ( results [ 0 ] , presubmit . OutputApi . PresubmitError )
def GetInputApiWithOWNERS ( self , owners_content ):
def GetInputApiWithOWNERS ( self , owners_content , code_owners_enabled = False ):
input_api = self . GetInputApiWithFiles ( { ' OWNERS ' : ( ' M ' , owners_content ) } )
owners_file = StringIO ( owners_content )
fopen = lambda * args : owners_file
input_api . owners_db = owners . Database ( ' ' , fopen , os . path )
input_api . gerrit . IsCodeOwnersEnabledOnRepo = lambda : code_owners_enabled
return input_api
@ -2689,6 +2690,17 @@ the current line as well!
input_api , presubmit . OutputApi )
)
def testCheckOwnersFormatWorks_CodeOwners ( self ) :
# If code owners is enabled, we rely on it to check owners format instead of
# depot tools.
input_api = self . GetInputApiWithOWNERS (
' any content ' , code_owners_enabled = True )
self . assertEqual (
[ ] ,
presubmit_canned_checks . CheckOwnersFormat (
input_api , presubmit . OutputApi )
)
def testCheckOwnersFormatFails ( self ) :
input_api = self . GetInputApiWithOWNERS ( ' \n ' . join ( [
' set noparent ' ,
@ -2704,7 +2716,7 @@ the current line as well!
self , tbr = False , issue = ' 1 ' , approvers = None , modified_files = None ,
owners_by_path = None , is_committing = True , response = None ,
expected_output = ' ' , manually_specified_reviewers = None , dry_run = None ,
allow_tbr= Tru e) :
code_owners_enabled= Fals e) :
# The set of people who lgtm'ed a change.
approvers = approvers or set ( )
manually_specified_reviewers = manually_specified_reviewers or [ ]
@ -2748,13 +2760,14 @@ the current line as well!
input_api . tbr = tbr
input_api . dry_run = dry_run
input_api . gerrit . _FetchChangeDetail = lambda _ : response
input_api . gerrit . IsCodeOwnersEnabledOnRepo = lambda : code_owners_enabled
input_api . owners_client = owners_client . DepotToolsClient ( ' root ' , ' branch ' )
with mock . patch ( ' owners_client.DepotToolsClient.ListOwners ' ,
side_effect = lambda f : owners_by_path . get ( f , [ ] ) ) :
results = presubmit_canned_checks . CheckOwners (
input_api , presubmit . OutputApi , allow_tbr = allow_tbr )
input_api , presubmit . OutputApi )
for result in results :
result . handle ( )
if expected_output :
@ -3067,12 +3080,11 @@ the current line as well!
def testCannedCheckOwners_TBRIgnored ( self ) :
self . AssertOwnersWorks (
tbr = True ,
allow_tbr = False ,
expected_output = ' Missing LGTM from someone other than '
' john@example.com \n ' )
code_owners_enabled = True ,
expected_output = ' ' )
self . AssertOwnersWorks (
tbr = True ,
allow_tbr= Fals e,
code_owners_enabled= Tru e,
is_committing = False ,
expected_output = ' ' )