|
@@ -45,10 +45,9 @@ import json
|
|
|
import owners_client
|
|
|
import presubmit_support as presubmit
|
|
|
import rdb_wrapper
|
|
|
-from lib import scm
|
|
|
+import scm
|
|
|
import subprocess2 as subprocess
|
|
|
from lib import utils
|
|
|
-from lib import change as libchange
|
|
|
|
|
|
|
|
|
# Shortcut.
|
|
@@ -184,7 +183,7 @@ index fe3de7b..54ae6e1 100755
|
|
|
self.fake_change = FakeChange(self)
|
|
|
self.rdb_client = mock.MagicMock()
|
|
|
|
|
|
- mock.patch('lib.utils.FileRead').start()
|
|
|
+ mock.patch('gclient_utils.FileRead').start()
|
|
|
mock.patch('gclient_utils.FileWrite').start()
|
|
|
mock.patch('json.load').start()
|
|
|
mock.patch('multiprocessing.cpu_count', lambda: 2)
|
|
@@ -202,8 +201,8 @@ index fe3de7b..54ae6e1 100755
|
|
|
mock.patch('presubmit_support.time_time', return_value=0).start()
|
|
|
mock.patch('presubmit_support.warn').start()
|
|
|
mock.patch('random.randint').start()
|
|
|
- mock.patch('lib.scm.GIT.GenerateDiff').start()
|
|
|
- mock.patch('lib.scm.determine_scm').start()
|
|
|
+ mock.patch('scm.GIT.GenerateDiff').start()
|
|
|
+ mock.patch('scm.determine_scm').start()
|
|
|
mock.patch('subprocess2.Popen').start()
|
|
|
mock.patch('sys.stderr', StringIO()).start()
|
|
|
mock.patch('sys.stdout', StringIO()).start()
|
|
@@ -233,7 +232,7 @@ class PresubmitUnittest(PresubmitTestsBase):
|
|
|
self.assertEqual(canned.CheckOwners, orig)
|
|
|
|
|
|
def testTagLineRe(self):
|
|
|
- m = libchange.Change.TAG_LINE_RE.match(' BUG =1223, 1445 \t')
|
|
|
+ m = presubmit.Change.TAG_LINE_RE.match(' BUG =1223, 1445 \t')
|
|
|
self.assertIsNotNone(m)
|
|
|
self.assertEqual(m.group('key'), 'BUG')
|
|
|
self.assertEqual(m.group('value'), '1223, 1445')
|
|
@@ -348,14 +347,15 @@ class PresubmitUnittest(PresubmitTestsBase):
|
|
|
|
|
|
scm.GIT.GenerateDiff.return_value = '\n'.join(unified_diff)
|
|
|
|
|
|
- change = libchange.GitChange('mychange',
|
|
|
- '\n'.join(description_lines),
|
|
|
- self.fake_root_dir,
|
|
|
- files,
|
|
|
- 0,
|
|
|
- 0,
|
|
|
- None,
|
|
|
- upstream=None)
|
|
|
+ change = presubmit.GitChange(
|
|
|
+ 'mychange',
|
|
|
+ '\n'.join(description_lines),
|
|
|
+ self.fake_root_dir,
|
|
|
+ files,
|
|
|
+ 0,
|
|
|
+ 0,
|
|
|
+ None,
|
|
|
+ upstream=None)
|
|
|
self.assertIsNotNone(change.Name() == 'mychange')
|
|
|
self.assertIsNotNone(change.DescriptionText() ==
|
|
|
'Hello there\nthis is a change\nand some more regular text')
|
|
@@ -411,8 +411,14 @@ class PresubmitUnittest(PresubmitTestsBase):
|
|
|
|
|
|
def testInvalidChange(self):
|
|
|
with self.assertRaises(AssertionError):
|
|
|
- libchange.GitChange('mychange', 'description', self.fake_root_dir,
|
|
|
- ['foo/blat.cc', 'bar'], 0, 0, None)
|
|
|
+ presubmit.GitChange(
|
|
|
+ 'mychange',
|
|
|
+ 'description',
|
|
|
+ self.fake_root_dir,
|
|
|
+ ['foo/blat.cc', 'bar'],
|
|
|
+ 0,
|
|
|
+ 0,
|
|
|
+ None)
|
|
|
|
|
|
def testExecPresubmitScript(self):
|
|
|
description_lines = ('Hello there',
|
|
@@ -423,8 +429,14 @@ class PresubmitUnittest(PresubmitTestsBase):
|
|
|
]
|
|
|
fake_presubmit = os.path.join(self.fake_root_dir, 'PRESUBMIT.py')
|
|
|
|
|
|
- change = libchange.Change('mychange', '\n'.join(description_lines),
|
|
|
- self.fake_root_dir, files, 0, 0, None)
|
|
|
+ change = presubmit.Change(
|
|
|
+ 'mychange',
|
|
|
+ '\n'.join(description_lines),
|
|
|
+ self.fake_root_dir,
|
|
|
+ files,
|
|
|
+ 0,
|
|
|
+ 0,
|
|
|
+ None)
|
|
|
executer = presubmit.PresubmitExecuter(
|
|
|
change, False, None, presubmit.GerritAccessor())
|
|
|
self.assertFalse(executer.ExecPresubmitScript('', fake_presubmit))
|
|
@@ -472,7 +484,7 @@ class PresubmitUnittest(PresubmitTestsBase):
|
|
|
description_lines = ('Hello there', 'this is a change', 'BUG=123')
|
|
|
files = [['A', 'foo\\blat.cc']]
|
|
|
fake_presubmit = os.path.join(self.fake_root_dir, 'PRESUBMIT.py')
|
|
|
- change = libchange.Change('mychange', '\n'.join(description_lines),
|
|
|
+ change = presubmit.Change('mychange', '\n'.join(description_lines),
|
|
|
self.fake_root_dir, files, 0, 0, None)
|
|
|
executer = presubmit.PresubmitExecuter(
|
|
|
change, True, None, presubmit.GerritAccessor())
|
|
@@ -572,7 +584,7 @@ class PresubmitUnittest(PresubmitTestsBase):
|
|
|
def testDoPostUploadExecuter(self):
|
|
|
os.path.isfile.side_effect = lambda f: 'PRESUBMIT.py' in f
|
|
|
os.listdir.return_value = ['PRESUBMIT.py']
|
|
|
- utils.FileRead.return_value = self.presubmit_text
|
|
|
+ gclient_utils.FileRead.return_value = self.presubmit_text
|
|
|
change = self.ExampleChange()
|
|
|
self.assertEqual(
|
|
|
0,
|
|
@@ -591,7 +603,7 @@ class PresubmitUnittest(PresubmitTestsBase):
|
|
|
path = os.path.join(self.fake_root_dir, 'PRESUBMIT.py')
|
|
|
os.path.isfile.side_effect = lambda f: f == path
|
|
|
os.listdir.return_value = ['PRESUBMIT.py']
|
|
|
- utils.FileRead.return_value = self.presubmit_text
|
|
|
+ gclient_utils.FileRead.return_value = self.presubmit_text
|
|
|
change = self.ExampleChange(extra_lines=['PROMPT_WARNING=yes'])
|
|
|
self.assertEqual(
|
|
|
0,
|
|
@@ -609,7 +621,7 @@ class PresubmitUnittest(PresubmitTestsBase):
|
|
|
path = os.path.join(self.fake_root_dir, 'PRESUBMIT.py')
|
|
|
os.path.isfile.side_effect = lambda f: f == path
|
|
|
os.listdir.return_value = ['PRESUBMIT.py']
|
|
|
- utils.FileRead.return_value = self.presubmit_text
|
|
|
+ gclient_utils.FileRead.return_value = self.presubmit_text
|
|
|
change = self.ExampleChange(extra_lines=['ERROR=yes'])
|
|
|
self.assertEqual(
|
|
|
1,
|
|
@@ -637,7 +649,7 @@ class PresubmitUnittest(PresubmitTestsBase):
|
|
|
os.path.isfile.side_effect = lambda f: f in [root_path, haspresubmit_path]
|
|
|
os.listdir.return_value = ['PRESUBMIT.py']
|
|
|
|
|
|
- utils.FileRead.return_value = self.presubmit_text
|
|
|
+ gclient_utils.FileRead.return_value = self.presubmit_text
|
|
|
|
|
|
# Make a change which will have no warnings.
|
|
|
change = self.ExampleChange(extra_lines=['STORY=http://tracker/123'])
|
|
@@ -746,7 +758,7 @@ def CheckChangeOnCommit(input_api, output_api):
|
|
|
os.listdir.return_value = ['PRESUBMIT.py']
|
|
|
random.randint.return_value = 1
|
|
|
|
|
|
- utils.FileRead.return_value = self.presubmit_text
|
|
|
+ gclient_utils.FileRead.return_value = self.presubmit_text
|
|
|
|
|
|
# Make a change with a single warning.
|
|
|
change = self.ExampleChange(extra_lines=['PROMPT_WARNING=yes'])
|
|
@@ -781,7 +793,7 @@ def CheckChangeOnCommit(input_api, output_api):
|
|
|
os.path.isfile.side_effect = (
|
|
|
lambda f: f in [presubmit_path, haspresubmit_path])
|
|
|
os.listdir.return_value = ['PRESUBMIT.py']
|
|
|
- utils.FileRead.return_value = self.presubmit_text
|
|
|
+ gclient_utils.FileRead.return_value = self.presubmit_text
|
|
|
random.randint.return_value = 1
|
|
|
|
|
|
change = self.ExampleChange(extra_lines=['PROMPT_WARNING=yes'])
|
|
@@ -806,7 +818,7 @@ def CheckChangeOnCommit(input_api, output_api):
|
|
|
os.path.isfile.side_effect = (
|
|
|
lambda f: f in [presubmit_path, haspresubmit_path])
|
|
|
os.listdir.return_value = ['PRESUBMIT.py']
|
|
|
- utils.FileRead.return_value = self.presubmit_text
|
|
|
+ gclient_utils.FileRead.return_value = self.presubmit_text
|
|
|
random.randint.return_value = 1
|
|
|
|
|
|
change = self.ExampleChange(extra_lines=['ERROR=yes'])
|
|
@@ -864,13 +876,14 @@ def CheckChangeOnCommit(input_api, output_api):
|
|
|
files = [
|
|
|
['A', os.path.join('haspresubmit', 'blat.cc')],
|
|
|
]
|
|
|
- return libchange.Change(name='mychange',
|
|
|
- description='\n'.join(description_lines),
|
|
|
- local_root=self.fake_root_dir,
|
|
|
- files=files,
|
|
|
- issue=0,
|
|
|
- patchset=0,
|
|
|
- author=None)
|
|
|
+ return presubmit.Change(
|
|
|
+ name='mychange',
|
|
|
+ description='\n'.join(description_lines),
|
|
|
+ local_root=self.fake_root_dir,
|
|
|
+ files=files,
|
|
|
+ issue=0,
|
|
|
+ patchset=0,
|
|
|
+ author=None)
|
|
|
|
|
|
def testMergeMasters(self):
|
|
|
merge = presubmit._MergeMasters
|
|
@@ -898,7 +911,7 @@ def CheckChangeOnCommit(input_api, output_api):
|
|
|
def testMainPostUpload(self):
|
|
|
os.path.isfile.side_effect = lambda f: 'PRESUBMIT.py' in f
|
|
|
os.listdir.return_value = ['PRESUBMIT.py']
|
|
|
- utils.FileRead.return_value = (
|
|
|
+ gclient_utils.FileRead.return_value = (
|
|
|
'USE_PYTHON3 = ' + str(sys.version_info.major == 3) + '\n'
|
|
|
'def PostUploadHook(gerrit, change, output_api):\n'
|
|
|
' return ()\n')
|
|
@@ -911,7 +924,7 @@ def CheckChangeOnCommit(input_api, output_api):
|
|
|
|
|
|
@mock.patch('lib.utils.ListRelevantFilesInSourceCheckout')
|
|
|
def testMainUnversioned(self, *_mocks):
|
|
|
- utils.FileRead.return_value = ''
|
|
|
+ gclient_utils.FileRead.return_value = ''
|
|
|
scm.determine_scm.return_value = None
|
|
|
utils.ListRelevantFilesInSourceCheckout.return_value = [
|
|
|
os.path.join(self.fake_root_dir, 'PRESUBMIT.py')
|
|
@@ -923,7 +936,7 @@ def CheckChangeOnCommit(input_api, output_api):
|
|
|
|
|
|
@mock.patch('lib.utils.ListRelevantFilesInSourceCheckout')
|
|
|
def testMainUnversionedChecksFail(self, *_mocks):
|
|
|
- utils.FileRead.return_value = (
|
|
|
+ gclient_utils.FileRead.return_value = (
|
|
|
'USE_PYTHON3 = ' + str(sys.version_info.major == 3) + '\n'
|
|
|
'def CheckChangeOnUpload(input_api, output_api):\n'
|
|
|
' return [output_api.PresubmitError("!!")]\n')
|
|
@@ -949,22 +962,23 @@ def CheckChangeOnCommit(input_api, output_api):
|
|
|
'presubmit_unittest.py: error: <files> is not optional for unversioned '
|
|
|
'directories.\n')
|
|
|
|
|
|
- @mock.patch('lib.change.Change', mock.Mock())
|
|
|
+ @mock.patch('presubmit_support.Change', mock.Mock())
|
|
|
def testParseChange_Files(self):
|
|
|
presubmit._parse_files.return_value=[('M', 'random_file.txt')]
|
|
|
scm.determine_scm.return_value = None
|
|
|
options = mock.Mock(all_files=False, source_controlled_only = False)
|
|
|
|
|
|
change = presubmit._parse_change(None, options)
|
|
|
- self.assertEqual(libchange.Change.return_value, change)
|
|
|
- libchange.Change.assert_called_once_with(options.name,
|
|
|
- options.description,
|
|
|
- options.root,
|
|
|
- [('M', 'random_file.txt')],
|
|
|
- options.issue,
|
|
|
- options.patchset,
|
|
|
- options.author,
|
|
|
- upstream=options.upstream)
|
|
|
+ self.assertEqual(presubmit.Change.return_value, change)
|
|
|
+ presubmit.Change.assert_called_once_with(
|
|
|
+ options.name,
|
|
|
+ options.description,
|
|
|
+ options.root,
|
|
|
+ [('M', 'random_file.txt')],
|
|
|
+ options.issue,
|
|
|
+ options.patchset,
|
|
|
+ options.author,
|
|
|
+ upstream=options.upstream)
|
|
|
presubmit._parse_files.assert_called_once_with(
|
|
|
options.files, options.recursive)
|
|
|
|
|
@@ -990,63 +1004,65 @@ def CheckChangeOnCommit(input_api, output_api):
|
|
|
parser.error.assert_called_once_with(
|
|
|
'<files> cannot be specified when --all-files is set.')
|
|
|
|
|
|
- @mock.patch('lib.change.GitChange', mock.Mock())
|
|
|
+ @mock.patch('presubmit_support.GitChange', mock.Mock())
|
|
|
def testParseChange_FilesAndGit(self):
|
|
|
scm.determine_scm.return_value = 'git'
|
|
|
presubmit._parse_files.return_value = [('M', 'random_file.txt')]
|
|
|
options = mock.Mock(all_files=False, source_controlled_only = False)
|
|
|
|
|
|
change = presubmit._parse_change(None, options)
|
|
|
- self.assertEqual(libchange.GitChange.return_value, change)
|
|
|
- libchange.GitChange.assert_called_once_with(options.name,
|
|
|
- options.description,
|
|
|
- options.root,
|
|
|
- [('M', 'random_file.txt')],
|
|
|
- options.issue,
|
|
|
- options.patchset,
|
|
|
- options.author,
|
|
|
- upstream=options.upstream)
|
|
|
+ self.assertEqual(presubmit.GitChange.return_value, change)
|
|
|
+ presubmit.GitChange.assert_called_once_with(
|
|
|
+ options.name,
|
|
|
+ options.description,
|
|
|
+ options.root,
|
|
|
+ [('M', 'random_file.txt')],
|
|
|
+ options.issue,
|
|
|
+ options.patchset,
|
|
|
+ options.author,
|
|
|
+ upstream=options.upstream)
|
|
|
presubmit._parse_files.assert_called_once_with(
|
|
|
options.files, options.recursive)
|
|
|
|
|
|
- @mock.patch('lib.change.GitChange', mock.Mock())
|
|
|
- @mock.patch('lib.scm.GIT.CaptureStatus', mock.Mock())
|
|
|
+ @mock.patch('presubmit_support.GitChange', mock.Mock())
|
|
|
+ @mock.patch('scm.GIT.CaptureStatus', mock.Mock())
|
|
|
def testParseChange_NoFilesAndGit(self):
|
|
|
scm.determine_scm.return_value = 'git'
|
|
|
scm.GIT.CaptureStatus.return_value = [('A', 'added.txt')]
|
|
|
options = mock.Mock(all_files=False, files=[])
|
|
|
|
|
|
change = presubmit._parse_change(None, options)
|
|
|
- self.assertEqual(libchange.GitChange.return_value, change)
|
|
|
- libchange.GitChange.assert_called_once_with(options.name,
|
|
|
- options.description,
|
|
|
- options.root,
|
|
|
- [('A', 'added.txt')],
|
|
|
- options.issue,
|
|
|
- options.patchset,
|
|
|
- options.author,
|
|
|
- upstream=options.upstream)
|
|
|
+ self.assertEqual(presubmit.GitChange.return_value, change)
|
|
|
+ presubmit.GitChange.assert_called_once_with(
|
|
|
+ options.name,
|
|
|
+ options.description,
|
|
|
+ options.root,
|
|
|
+ [('A', 'added.txt')],
|
|
|
+ options.issue,
|
|
|
+ options.patchset,
|
|
|
+ options.author,
|
|
|
+ upstream=options.upstream)
|
|
|
scm.GIT.CaptureStatus.assert_called_once_with(
|
|
|
options.root, options.upstream)
|
|
|
|
|
|
- @mock.patch('lib.change.GitChange', mock.Mock())
|
|
|
- @mock.patch('lib.scm.GIT.GetAllFiles', mock.Mock())
|
|
|
+ @mock.patch('presubmit_support.GitChange', mock.Mock())
|
|
|
+ @mock.patch('scm.GIT.GetAllFiles', mock.Mock())
|
|
|
def testParseChange_AllFilesAndGit(self):
|
|
|
scm.determine_scm.return_value = 'git'
|
|
|
scm.GIT.GetAllFiles.return_value = ['foo.txt', 'bar.txt']
|
|
|
options = mock.Mock(all_files=True, files=[])
|
|
|
|
|
|
change = presubmit._parse_change(None, options)
|
|
|
- self.assertEqual(libchange.GitChange.return_value, change)
|
|
|
- libchange.GitChange.assert_called_once_with(options.name,
|
|
|
- options.description,
|
|
|
- options.root,
|
|
|
- [('M', 'foo.txt'),
|
|
|
- ('M', 'bar.txt')],
|
|
|
- options.issue,
|
|
|
- options.patchset,
|
|
|
- options.author,
|
|
|
- upstream=options.upstream)
|
|
|
+ self.assertEqual(presubmit.GitChange.return_value, change)
|
|
|
+ presubmit.GitChange.assert_called_once_with(
|
|
|
+ options.name,
|
|
|
+ options.description,
|
|
|
+ options.root,
|
|
|
+ [('M', 'foo.txt'), ('M', 'bar.txt')],
|
|
|
+ options.issue,
|
|
|
+ options.patchset,
|
|
|
+ options.author,
|
|
|
+ upstream=options.upstream)
|
|
|
scm.GIT.GetAllFiles.assert_called_once_with(options.root)
|
|
|
|
|
|
def testParseGerritOptions_NoGerritUrl(self):
|
|
@@ -1182,9 +1198,14 @@ class InputApiUnittest(PresubmitTestsBase):
|
|
|
os.path.isfile.side_effect = lambda f: f in known_files
|
|
|
presubmit.scm.GIT.GenerateDiff.return_value = '\n'.join(diffs)
|
|
|
|
|
|
- change = libchange.GitChange('mychange', '\n'.join(description_lines),
|
|
|
- self.fake_root_dir,
|
|
|
- [[f[0], f[1]] for f in files], 0, 0, None)
|
|
|
+ change = presubmit.GitChange(
|
|
|
+ 'mychange',
|
|
|
+ '\n'.join(description_lines),
|
|
|
+ self.fake_root_dir,
|
|
|
+ [[f[0], f[1]] for f in files],
|
|
|
+ 0,
|
|
|
+ 0,
|
|
|
+ None)
|
|
|
input_api = presubmit.InputApi(
|
|
|
change,
|
|
|
os.path.join(self.fake_root_dir, 'foo', 'PRESUBMIT.py'),
|
|
@@ -1230,9 +1251,14 @@ class InputApiUnittest(PresubmitTestsBase):
|
|
|
for _, f in files]
|
|
|
os.path.isfile.side_effect = lambda f: f in known_files
|
|
|
|
|
|
- change = libchange.GitChange('mychange', 'description\nlines\n',
|
|
|
- self.fake_root_dir,
|
|
|
- [[f[0], f[1]] for f in files], 0, 0, None)
|
|
|
+ change = presubmit.GitChange(
|
|
|
+ 'mychange',
|
|
|
+ 'description\nlines\n',
|
|
|
+ self.fake_root_dir,
|
|
|
+ [[f[0], f[1]] for f in files],
|
|
|
+ 0,
|
|
|
+ 0,
|
|
|
+ None)
|
|
|
input_api = presubmit.InputApi(
|
|
|
change,
|
|
|
os.path.join(self.fake_root_dir, 'foo', 'PRESUBMIT.py'),
|
|
@@ -1249,8 +1275,7 @@ class InputApiUnittest(PresubmitTestsBase):
|
|
|
|
|
|
def testDefaultFilesToCheckFilesToSkipFilters(self):
|
|
|
def f(x):
|
|
|
- return libchange.AffectedFile(x, 'M', self.fake_root_dir, None)
|
|
|
-
|
|
|
+ return presubmit.AffectedFile(x, 'M', self.fake_root_dir, None)
|
|
|
files = [
|
|
|
(
|
|
|
[
|
|
@@ -1355,8 +1380,8 @@ class InputApiUnittest(PresubmitTestsBase):
|
|
|
for _, item in files]
|
|
|
os.path.isfile.side_effect = lambda f: f in known_files
|
|
|
|
|
|
- change = libchange.GitChange('mychange', '', self.fake_root_dir, files, 0,
|
|
|
- 0, None)
|
|
|
+ change = presubmit.GitChange(
|
|
|
+ 'mychange', '', self.fake_root_dir, files, 0, 0, None)
|
|
|
input_api = presubmit.InputApi(
|
|
|
change,
|
|
|
os.path.join(self.fake_root_dir, 'PRESUBMIT.py'),
|
|
@@ -1375,8 +1400,8 @@ class InputApiUnittest(PresubmitTestsBase):
|
|
|
for _, item in files]
|
|
|
os.path.isfile.side_effect = lambda f: f in known_files
|
|
|
|
|
|
- change = libchange.GitChange('mychange', '', self.fake_root_dir, files, 0,
|
|
|
- 0, None)
|
|
|
+ change = presubmit.GitChange(
|
|
|
+ 'mychange', '', self.fake_root_dir, files, 0, 0, None)
|
|
|
input_api = presubmit.InputApi(
|
|
|
change, os.path.join(self.fake_root_dir, 'PRESUBMIT.py'), False, None,
|
|
|
False)
|
|
@@ -1401,8 +1426,8 @@ class InputApiUnittest(PresubmitTestsBase):
|
|
|
['M', os.path.join('elsewhere', 'ouf.cc')],
|
|
|
]
|
|
|
|
|
|
- change = libchange.Change('mychange', '', self.fake_root_dir, files, 0, 0,
|
|
|
- None)
|
|
|
+ change = presubmit.Change(
|
|
|
+ 'mychange', '', self.fake_root_dir, files, 0, 0, None)
|
|
|
affected_files = change.AffectedFiles()
|
|
|
# Validate that normpath strips trailing path separators.
|
|
|
self.assertEqual('isdir', normpath('isdir/'))
|
|
@@ -1436,8 +1461,8 @@ class InputApiUnittest(PresubmitTestsBase):
|
|
|
utils.normpath(os.path.join(self.fake_root_dir, 'isdir', 'blat.cc')))
|
|
|
|
|
|
def testDeprecated(self):
|
|
|
- change = libchange.Change('mychange', '', self.fake_root_dir, [], 0, 0,
|
|
|
- None)
|
|
|
+ change = presubmit.Change(
|
|
|
+ 'mychange', '', self.fake_root_dir, [], 0, 0, None)
|
|
|
api = presubmit.InputApi(
|
|
|
change,
|
|
|
os.path.join(self.fake_root_dir, 'foo', 'PRESUBMIT.py'), True,
|
|
@@ -1446,8 +1471,8 @@ class InputApiUnittest(PresubmitTestsBase):
|
|
|
|
|
|
def testReadFileStringDenied(self):
|
|
|
|
|
|
- change = libchange.Change('foo', 'foo', self.fake_root_dir, [('M', 'AA')],
|
|
|
- 0, 0, None)
|
|
|
+ change = presubmit.Change(
|
|
|
+ 'foo', 'foo', self.fake_root_dir, [('M', 'AA')], 0, 0, None)
|
|
|
input_api = presubmit.InputApi(
|
|
|
change, os.path.join(self.fake_root_dir, '/p'), False,
|
|
|
None, False)
|
|
@@ -1457,35 +1482,31 @@ class InputApiUnittest(PresubmitTestsBase):
|
|
|
path = os.path.join(self.fake_root_dir, 'AA/boo')
|
|
|
presubmit.gclient_utils.FileRead.return_code = None
|
|
|
|
|
|
- change = libchange.Change('foo', 'foo', self.fake_root_dir, [('M', 'AA')],
|
|
|
- 0, 0, None)
|
|
|
+ change = presubmit.Change(
|
|
|
+ 'foo', 'foo', self.fake_root_dir, [('M', 'AA')], 0, 0, None)
|
|
|
input_api = presubmit.InputApi(
|
|
|
change, os.path.join(self.fake_root_dir, '/p'), False,
|
|
|
None, False)
|
|
|
input_api.ReadFile(path, 'x')
|
|
|
|
|
|
def testReadFileAffectedFileDenied(self):
|
|
|
- fileobj = libchange.AffectedFile('boo',
|
|
|
- 'M',
|
|
|
- 'Unrelated',
|
|
|
+ fileobj = presubmit.AffectedFile('boo', 'M', 'Unrelated',
|
|
|
diff_cache=mock.Mock())
|
|
|
|
|
|
- change = libchange.Change('foo', 'foo', self.fake_root_dir, [('M', 'AA')],
|
|
|
- 0, 0, None)
|
|
|
+ change = presubmit.Change(
|
|
|
+ 'foo', 'foo', self.fake_root_dir, [('M', 'AA')], 0, 0, None)
|
|
|
input_api = presubmit.InputApi(
|
|
|
change, os.path.join(self.fake_root_dir, '/p'), False,
|
|
|
None, False)
|
|
|
self.assertRaises(IOError, input_api.ReadFile, fileobj, 'x')
|
|
|
|
|
|
def testReadFileAffectedFileAccepted(self):
|
|
|
- fileobj = libchange.AffectedFile('AA/boo',
|
|
|
- 'M',
|
|
|
- self.fake_root_dir,
|
|
|
+ fileobj = presubmit.AffectedFile('AA/boo', 'M', self.fake_root_dir,
|
|
|
diff_cache=mock.Mock())
|
|
|
presubmit.gclient_utils.FileRead.return_code = None
|
|
|
|
|
|
- change = libchange.Change('foo', 'foo', self.fake_root_dir, [('M', 'AA')],
|
|
|
- 0, 0, None)
|
|
|
+ change = presubmit.Change(
|
|
|
+ 'foo', 'foo', self.fake_root_dir, [('M', 'AA')], 0, 0, None)
|
|
|
input_api = presubmit.InputApi(
|
|
|
change, os.path.join(self.fake_root_dir, '/p'), False,
|
|
|
None, False)
|
|
@@ -1560,25 +1581,25 @@ class OutputApiUnittest(PresubmitTestsBase):
|
|
|
|
|
|
class AffectedFileUnittest(PresubmitTestsBase):
|
|
|
def testAffectedFile(self):
|
|
|
- utils.FileRead.return_value = 'whatever\ncookie'
|
|
|
- af = libchange.GitAffectedFile('foo/blat.cc', 'M', self.fake_root_dir, None)
|
|
|
+ gclient_utils.FileRead.return_value = 'whatever\ncookie'
|
|
|
+ af = presubmit.GitAffectedFile('foo/blat.cc', 'M', self.fake_root_dir, None)
|
|
|
self.assertEqual(utils.normpath('foo/blat.cc'), af.LocalPath())
|
|
|
self.assertEqual('M', af.Action())
|
|
|
self.assertEqual(['whatever', 'cookie'], af.NewContents())
|
|
|
|
|
|
def testAffectedFileNotExists(self):
|
|
|
notfound = 'notfound.cc'
|
|
|
- utils.FileRead.side_effect = IOError
|
|
|
- af = libchange.AffectedFile(notfound, 'A', self.fake_root_dir, None)
|
|
|
+ gclient_utils.FileRead.side_effect = IOError
|
|
|
+ af = presubmit.AffectedFile(notfound, 'A', self.fake_root_dir, None)
|
|
|
self.assertEqual([], af.NewContents())
|
|
|
|
|
|
def testIsTestableFile(self):
|
|
|
files = [
|
|
|
- libchange.GitAffectedFile('foo/blat.txt', 'M', self.fake_root_dir,
|
|
|
+ presubmit.GitAffectedFile('foo/blat.txt', 'M', self.fake_root_dir,
|
|
|
None),
|
|
|
- libchange.GitAffectedFile('foo/binary.blob', 'M', self.fake_root_dir,
|
|
|
+ presubmit.GitAffectedFile('foo/binary.blob', 'M', self.fake_root_dir,
|
|
|
None),
|
|
|
- libchange.GitAffectedFile('blat/flop.txt', 'D', self.fake_root_dir,
|
|
|
+ presubmit.GitAffectedFile('blat/flop.txt', 'D', self.fake_root_dir,
|
|
|
None)
|
|
|
]
|
|
|
blat = os.path.join('foo', 'blat.txt')
|
|
@@ -1594,14 +1615,14 @@ class AffectedFileUnittest(PresubmitTestsBase):
|
|
|
|
|
|
class ChangeUnittest(PresubmitTestsBase):
|
|
|
def testAffectedFiles(self):
|
|
|
- change = libchange.Change('', '', self.fake_root_dir, [('Y', 'AA')], 3, 5,
|
|
|
- '')
|
|
|
+ change = presubmit.Change(
|
|
|
+ '', '', self.fake_root_dir, [('Y', 'AA')], 3, 5, '')
|
|
|
self.assertEqual(1, len(change.AffectedFiles()))
|
|
|
self.assertEqual('Y', change.AffectedFiles()[0].Action())
|
|
|
|
|
|
def testSetDescriptionText(self):
|
|
|
- change = libchange.Change('', 'foo\nDRU=ro', self.fake_root_dir, [], 3, 5,
|
|
|
- '')
|
|
|
+ change = presubmit.Change(
|
|
|
+ '', 'foo\nDRU=ro', self.fake_root_dir, [], 3, 5, '')
|
|
|
self.assertEqual('foo', change.DescriptionText())
|
|
|
self.assertEqual('foo\nDRU=ro', change.FullDescriptionText())
|
|
|
self.assertEqual({'DRU': 'ro'}, change.tags)
|
|
@@ -1612,28 +1633,28 @@ class ChangeUnittest(PresubmitTestsBase):
|
|
|
self.assertEqual({'WHIZ': 'bang', 'FOO': 'baz'}, change.tags)
|
|
|
|
|
|
def testAddDescriptionFooter(self):
|
|
|
- change = libchange.Change('', 'foo\nDRU=ro\n\nChange-Id: asdf',
|
|
|
- self.fake_root_dir, [], 3, 5, '')
|
|
|
+ change = presubmit.Change(
|
|
|
+ '', 'foo\nDRU=ro\n\nChange-Id: asdf', self.fake_root_dir, [], 3, 5, '')
|
|
|
change.AddDescriptionFooter('my-footer', 'my-value')
|
|
|
self.assertEqual(
|
|
|
'foo\nDRU=ro\n\nChange-Id: asdf\nMy-Footer: my-value',
|
|
|
change.FullDescriptionText())
|
|
|
|
|
|
def testAddDescriptionFooter_NoPreviousFooters(self):
|
|
|
- change = libchange.Change('', 'foo\nDRU=ro', self.fake_root_dir, [], 3, 5,
|
|
|
- '')
|
|
|
+ change = presubmit.Change(
|
|
|
+ '', 'foo\nDRU=ro', self.fake_root_dir, [], 3, 5, '')
|
|
|
change.AddDescriptionFooter('my-footer', 'my-value')
|
|
|
self.assertEqual(
|
|
|
'foo\nDRU=ro\n\nMy-Footer: my-value', change.FullDescriptionText())
|
|
|
|
|
|
def testAddDescriptionFooter_InvalidFooter(self):
|
|
|
- change = libchange.Change('', 'foo\nDRU=ro', self.fake_root_dir, [], 3, 5,
|
|
|
- '')
|
|
|
+ change = presubmit.Change(
|
|
|
+ '', 'foo\nDRU=ro', self.fake_root_dir, [], 3, 5, '')
|
|
|
with self.assertRaises(ValueError):
|
|
|
change.AddDescriptionFooter('invalid.characters in:the', 'footer key')
|
|
|
|
|
|
def testGitFootersFromDescription(self):
|
|
|
- change = libchange.Change(
|
|
|
+ change = presubmit.Change(
|
|
|
'', 'foo\n\nChange-Id: asdf\nBug: 1\nBug: 2\nNo-Try: True',
|
|
|
self.fake_root_dir, [], 0, 0, '')
|
|
|
self.assertEqual({
|
|
@@ -1643,45 +1664,48 @@ class ChangeUnittest(PresubmitTestsBase):
|
|
|
}, change.GitFootersFromDescription())
|
|
|
|
|
|
def testGitFootersFromDescription_NoFooters(self):
|
|
|
- change = libchange.Change('', 'foo', self.fake_root_dir, [], 0, 0, '')
|
|
|
+ change = presubmit.Change('', 'foo', self.fake_root_dir, [], 0, 0, '')
|
|
|
self.assertEqual({}, change.GitFootersFromDescription())
|
|
|
|
|
|
def testBugFromDescription_FixedAndBugGetDeduped(self):
|
|
|
- change = libchange.Change('',
|
|
|
- 'foo\n\nChange-Id: asdf\nBug: 1, 2\nFixed:2, 1 ',
|
|
|
- self.fake_root_dir, [], 0, 0, '')
|
|
|
+ change = presubmit.Change(
|
|
|
+ '', 'foo\n\nChange-Id: asdf\nBug: 1, 2\nFixed:2, 1 ',
|
|
|
+ self.fake_root_dir, [], 0, 0, '')
|
|
|
self.assertEqual(['1', '2'], change.BugsFromDescription())
|
|
|
self.assertEqual('1,2', change.BUG)
|
|
|
|
|
|
def testBugsFromDescription_MixedTagsAndFooters(self):
|
|
|
- change = libchange.Change('', 'foo\nBUG=2,1\n\nChange-Id: asdf\nBug: 3, 6',
|
|
|
- self.fake_root_dir, [], 0, 0, '')
|
|
|
+ change = presubmit.Change(
|
|
|
+ '', 'foo\nBUG=2,1\n\nChange-Id: asdf\nBug: 3, 6',
|
|
|
+ self.fake_root_dir, [], 0, 0, '')
|
|
|
self.assertEqual(['1', '2', '3', '6'], change.BugsFromDescription())
|
|
|
self.assertEqual('1,2,3,6', change.BUG)
|
|
|
|
|
|
def testBugsFromDescription_MultipleFooters(self):
|
|
|
- change = libchange.Change(
|
|
|
+ change = presubmit.Change(
|
|
|
'', 'foo\n\nChange-Id: asdf\nBug: 1\nBug:4, 6\nFixed: 7',
|
|
|
self.fake_root_dir, [], 0, 0, '')
|
|
|
self.assertEqual(['1', '4', '6', '7'], change.BugsFromDescription())
|
|
|
self.assertEqual('1,4,6,7', change.BUG)
|
|
|
|
|
|
def testBugFromDescription_OnlyFixed(self):
|
|
|
- change = libchange.Change('', 'foo\n\nChange-Id: asdf\nFixed:1, 2',
|
|
|
- self.fake_root_dir, [], 0, 0, '')
|
|
|
+ change = presubmit.Change(
|
|
|
+ '', 'foo\n\nChange-Id: asdf\nFixed:1, 2',
|
|
|
+ self.fake_root_dir, [], 0, 0, '')
|
|
|
self.assertEqual(['1', '2'], change.BugsFromDescription())
|
|
|
self.assertEqual('1,2', change.BUG)
|
|
|
|
|
|
def testReviewersFromDescription(self):
|
|
|
- change = libchange.Change('', 'foo\nR=foo,bar\n\nChange-Id: asdf\nR: baz',
|
|
|
- self.fake_root_dir, [], 0, 0, '')
|
|
|
+ change = presubmit.Change(
|
|
|
+ '', 'foo\nR=foo,bar\n\nChange-Id: asdf\nR: baz',
|
|
|
+ self.fake_root_dir, [], 0, 0, '')
|
|
|
self.assertEqual(['bar', 'foo'], change.ReviewersFromDescription())
|
|
|
self.assertEqual('bar,foo', change.R)
|
|
|
|
|
|
def testTBRsFromDescription(self):
|
|
|
- change = libchange.Change('',
|
|
|
- 'foo\nTBR=foo,bar\n\nChange-Id: asdf\nTBR: baz',
|
|
|
- self.fake_root_dir, [], 0, 0, '')
|
|
|
+ change = presubmit.Change(
|
|
|
+ '', 'foo\nTBR=foo,bar\n\nChange-Id: asdf\nTBR: baz',
|
|
|
+ self.fake_root_dir, [], 0, 0, '')
|
|
|
self.assertEqual(['bar', 'baz', 'foo'], change.TBRsFromDescription())
|
|
|
self.assertEqual('bar,baz,foo', change.TBR)
|
|
|
|
|
@@ -1732,11 +1756,11 @@ class CannedChecksUnittest(PresubmitTestsBase):
|
|
|
|
|
|
def DescriptionTest(self, check, description1, description2, error_type,
|
|
|
committing):
|
|
|
- change1 = libchange.Change('foo1', description1, self.fake_root_dir, None,
|
|
|
- 0, 0, None)
|
|
|
+ change1 = presubmit.Change(
|
|
|
+ 'foo1', description1, self.fake_root_dir, None, 0, 0, None)
|
|
|
input_api1 = self.MockInputApi(change1, committing)
|
|
|
- change2 = libchange.Change('foo2', description2, self.fake_root_dir, None,
|
|
|
- 0, 0, None)
|
|
|
+ change2 = presubmit.Change(
|
|
|
+ 'foo2', description2, self.fake_root_dir, None, 0, 0, None)
|
|
|
input_api2 = self.MockInputApi(change2, committing)
|
|
|
|
|
|
results1 = check(input_api1, presubmit.OutputApi)
|
|
@@ -1757,10 +1781,10 @@ class CannedChecksUnittest(PresubmitTestsBase):
|
|
|
content2_path: file path for content2.
|
|
|
error_type: the type of the error expected for content2.
|
|
|
"""
|
|
|
- change1 = libchange.Change('foo1', 'foo1\n', self.fake_root_dir, None, 0, 0,
|
|
|
- None)
|
|
|
+ change1 = presubmit.Change(
|
|
|
+ 'foo1', 'foo1\n', self.fake_root_dir, None, 0, 0, None)
|
|
|
input_api1 = self.MockInputApi(change1, False)
|
|
|
- affected_file1 = mock.MagicMock(libchange.GitAffectedFile)
|
|
|
+ affected_file1 = mock.MagicMock(presubmit.GitAffectedFile)
|
|
|
input_api1.AffectedFiles.return_value = [affected_file1]
|
|
|
affected_file1.LocalPath.return_value = content1_path
|
|
|
affected_file1.NewContents.return_value = [
|
|
@@ -1777,11 +1801,11 @@ class CannedChecksUnittest(PresubmitTestsBase):
|
|
|
(43, 'hfoo'),
|
|
|
(23, 'ifoo')]
|
|
|
|
|
|
- change2 = libchange.Change('foo2', 'foo2\n', self.fake_root_dir, None, 0, 0,
|
|
|
- None)
|
|
|
+ change2 = presubmit.Change(
|
|
|
+ 'foo2', 'foo2\n', self.fake_root_dir, None, 0, 0, None)
|
|
|
input_api2 = self.MockInputApi(change2, False)
|
|
|
|
|
|
- affected_file2 = mock.MagicMock(libchange.GitAffectedFile)
|
|
|
+ affected_file2 = mock.MagicMock(presubmit.GitAffectedFile)
|
|
|
input_api2.AffectedFiles.return_value = [affected_file2]
|
|
|
affected_file2.LocalPath.return_value = content2_path
|
|
|
affected_file2.NewContents.return_value = [
|
|
@@ -1813,10 +1837,10 @@ class CannedChecksUnittest(PresubmitTestsBase):
|
|
|
content: Python source which is expected to pass or fail the test.
|
|
|
should_pass: True iff the test should pass, False otherwise.
|
|
|
"""
|
|
|
- change = libchange.Change('foo1', 'foo1\n', self.fake_root_dir, None, 0, 0,
|
|
|
+ change = presubmit.Change('foo1', 'foo1\n', self.fake_root_dir, None, 0, 0,
|
|
|
None)
|
|
|
input_api = self.MockInputApi(change, False)
|
|
|
- affected_file = mock.MagicMock(libchange.GitAffectedFile)
|
|
|
+ affected_file = mock.MagicMock(presubmit.GitAffectedFile)
|
|
|
input_api.AffectedFiles.return_value = [affected_file]
|
|
|
affected_file.LocalPath.return_value = 'foo.py'
|
|
|
affected_file.NewContents.return_value = content.splitlines()
|
|
@@ -1831,16 +1855,16 @@ class CannedChecksUnittest(PresubmitTestsBase):
|
|
|
presubmit.OutputApi.PresubmitPromptWarning)
|
|
|
|
|
|
def ReadFileTest(self, check, content1, content2, error_type):
|
|
|
- change1 = libchange.Change('foo1', 'foo1\n', self.fake_root_dir, None, 0, 0,
|
|
|
- None)
|
|
|
+ change1 = presubmit.Change(
|
|
|
+ 'foo1', 'foo1\n', self.fake_root_dir, None, 0, 0, None)
|
|
|
input_api1 = self.MockInputApi(change1, False)
|
|
|
- affected_file1 = mock.MagicMock(libchange.GitAffectedFile)
|
|
|
+ affected_file1 = mock.MagicMock(presubmit.GitAffectedFile)
|
|
|
input_api1.AffectedSourceFiles.return_value = [affected_file1]
|
|
|
input_api1.ReadFile.return_value = content1
|
|
|
- change2 = libchange.Change('foo2', 'foo2\n', self.fake_root_dir, None, 0, 0,
|
|
|
- None)
|
|
|
+ change2 = presubmit.Change(
|
|
|
+ 'foo2', 'foo2\n', self.fake_root_dir, None, 0, 0, None)
|
|
|
input_api2 = self.MockInputApi(change2, False)
|
|
|
- affected_file2 = mock.MagicMock(libchange.GitAffectedFile)
|
|
|
+ affected_file2 = mock.MagicMock(presubmit.GitAffectedFile)
|
|
|
input_api2.AffectedSourceFiles.return_value = [affected_file2]
|
|
|
input_api2.ReadFile.return_value = content2
|
|
|
affected_file2.LocalPath.return_value = 'bar.cc'
|
|
@@ -1935,10 +1959,10 @@ class CannedChecksUnittest(PresubmitTestsBase):
|
|
|
@mock.patch('git_cl.Changelist')
|
|
|
@mock.patch('auth.Authenticator')
|
|
|
def testCannedCheckChangedLUCIConfigs(self, mockGetAuth, mockChangelist):
|
|
|
- affected_file1 = mock.MagicMock(libchange.GitAffectedFile)
|
|
|
+ affected_file1 = mock.MagicMock(presubmit.GitAffectedFile)
|
|
|
affected_file1.LocalPath.return_value = 'foo.cfg'
|
|
|
affected_file1.NewContents.return_value = ['test', 'foo']
|
|
|
- affected_file2 = mock.MagicMock(libchange.GitAffectedFile)
|
|
|
+ affected_file2 = mock.MagicMock(presubmit.GitAffectedFile)
|
|
|
affected_file2.LocalPath.return_value = 'bar.cfg'
|
|
|
affected_file2.NewContents.return_value = ['test', 'bar']
|
|
|
|
|
@@ -1957,8 +1981,8 @@ class CannedChecksUnittest(PresubmitTestsBase):
|
|
|
mockChangelist().GetRemoteBranch.return_value = ('remote', branch)
|
|
|
mockChangelist().GetRemoteUrl.return_value = host
|
|
|
|
|
|
- change1 = libchange.Change('foo', 'foo1', self.fake_root_dir, None, 0, 0,
|
|
|
- None)
|
|
|
+ change1 = presubmit.Change(
|
|
|
+ 'foo', 'foo1', self.fake_root_dir, None, 0, 0, None)
|
|
|
input_api = self.MockInputApi(change1, False)
|
|
|
affected_files = (affected_file1, affected_file2)
|
|
|
|
|
@@ -1976,17 +2000,17 @@ class CannedChecksUnittest(PresubmitTestsBase):
|
|
|
presubmit.OutputApi.PresubmitPromptWarning)
|
|
|
|
|
|
# Make sure makefiles are ignored.
|
|
|
- change1 = libchange.Change('foo1', 'foo1\n', self.fake_root_dir, None, 0, 0,
|
|
|
- None)
|
|
|
+ change1 = presubmit.Change(
|
|
|
+ 'foo1', 'foo1\n', self.fake_root_dir, None, 0, 0, None)
|
|
|
input_api1 = self.MockInputApi(change1, False)
|
|
|
- affected_file1 = mock.MagicMock(libchange.GitAffectedFile)
|
|
|
+ affected_file1 = mock.MagicMock(presubmit.GitAffectedFile)
|
|
|
affected_file1.LocalPath.return_value = 'foo.cc'
|
|
|
- affected_file2 = mock.MagicMock(libchange.GitAffectedFile)
|
|
|
+ affected_file2 = mock.MagicMock(presubmit.GitAffectedFile)
|
|
|
affected_file2.LocalPath.return_value = 'foo/Makefile'
|
|
|
- affected_file3 = mock.MagicMock(libchange.GitAffectedFile)
|
|
|
+ affected_file3 = mock.MagicMock(presubmit.GitAffectedFile)
|
|
|
affected_file3.LocalPath.return_value = 'makefile'
|
|
|
# Only this one will trigger.
|
|
|
- affected_file4 = mock.MagicMock(libchange.GitAffectedFile)
|
|
|
+ affected_file4 = mock.MagicMock(presubmit.GitAffectedFile)
|
|
|
affected_file1.LocalPath.return_value = 'foo.cc'
|
|
|
affected_file1.NewContents.return_value = ['yo, ']
|
|
|
affected_file4.LocalPath.return_value = 'makefile.foo'
|
|
@@ -2208,10 +2232,10 @@ the current line as well!
|
|
|
expected_result,
|
|
|
new_file=False,
|
|
|
**kwargs):
|
|
|
- change = mock.MagicMock(libchange.GitChange)
|
|
|
+ change = mock.MagicMock(presubmit.GitChange)
|
|
|
change.scm = 'svn'
|
|
|
input_api = self.MockInputApi(change, committing)
|
|
|
- affected_file = mock.MagicMock(libchange.GitAffectedFile)
|
|
|
+ affected_file = mock.MagicMock(presubmit.GitAffectedFile)
|
|
|
if new_file:
|
|
|
affected_file.Action.return_value = 'A'
|
|
|
input_api.AffectedSourceFiles.return_value = [affected_file]
|
|
@@ -2494,12 +2518,12 @@ the current line as well!
|
|
|
self.checkstdout('')
|
|
|
|
|
|
def GetInputApiWithFiles(self, files):
|
|
|
- change = mock.MagicMock(libchange.Change)
|
|
|
- change.AffectedFiles = lambda *a, **kw: (libchange.Change.AffectedFiles(
|
|
|
- change, *a, **kw))
|
|
|
+ change = mock.MagicMock(presubmit.Change)
|
|
|
+ change.AffectedFiles = lambda *a, **kw: (
|
|
|
+ presubmit.Change.AffectedFiles(change, *a, **kw))
|
|
|
change._affected_files = []
|
|
|
for path, (action, contents) in files.items():
|
|
|
- affected_file = mock.MagicMock(libchange.GitAffectedFile)
|
|
|
+ affected_file = mock.MagicMock(presubmit.GitAffectedFile)
|
|
|
affected_file.AbsoluteLocalPath.return_value = path
|
|
|
affected_file.LocalPath.return_value = path
|
|
|
affected_file.Action.return_value = action
|
|
@@ -2634,7 +2658,7 @@ the current line as well!
|
|
|
"reviewers": {"REVIEWER": [{u'email': a}] for a in approvers},
|
|
|
}
|
|
|
|
|
|
- change = mock.MagicMock(libchange.Change)
|
|
|
+ change = mock.MagicMock(presubmit.Change)
|
|
|
change.OriginalOwnersFiles.return_value = {}
|
|
|
change.RepositoryRoot.return_value = None
|
|
|
change.ReviewersFromDescription.return_value = manually_specified_reviewers
|
|
@@ -2644,7 +2668,7 @@ the current line as well!
|
|
|
|
|
|
affected_files = []
|
|
|
for f in modified_files:
|
|
|
- affected_file = mock.MagicMock(libchange.GitAffectedFile)
|
|
|
+ affected_file = mock.MagicMock(presubmit.GitAffectedFile)
|
|
|
affected_file.LocalPath.return_value = f
|
|
|
affected_files.append(affected_file)
|
|
|
change.AffectedFiles.return_value = affected_files
|
|
@@ -2683,8 +2707,8 @@ the current line as well!
|
|
|
@mock.patch('io.open', mock.mock_open())
|
|
|
def testCannedRunUnitTests(self):
|
|
|
io.open().readline.return_value = ''
|
|
|
- change = libchange.Change('foo1', 'description1', self.fake_root_dir, None,
|
|
|
- 0, 0, None)
|
|
|
+ change = presubmit.Change(
|
|
|
+ 'foo1', 'description1', self.fake_root_dir, None, 0, 0, None)
|
|
|
input_api = self.MockInputApi(change, False)
|
|
|
input_api.verbose = True
|
|
|
input_api.PresubmitLocalPath.return_value = self.fake_root_dir
|
|
@@ -2729,8 +2753,8 @@ the current line as well!
|
|
|
@mock.patch('io.open', mock.mock_open())
|
|
|
def testCannedRunUnitTestsWithTimer(self):
|
|
|
io.open().readline.return_value = ''
|
|
|
- change = libchange.Change('foo1', 'description1', self.fake_root_dir, None,
|
|
|
- 0, 0, None)
|
|
|
+ change = presubmit.Change(
|
|
|
+ 'foo1', 'description1', self.fake_root_dir, None, 0, 0, None)
|
|
|
input_api = self.MockInputApi(change, False)
|
|
|
input_api.verbose = True
|
|
|
input_api.thread_pool.timeout = 100
|
|
@@ -2755,8 +2779,8 @@ the current line as well!
|
|
|
@mock.patch('io.open', mock.mock_open())
|
|
|
def testCannedRunUnitTestsWithTimerTimesOut(self):
|
|
|
io.open().readline.return_value = ''
|
|
|
- change = libchange.Change('foo1', 'description1', self.fake_root_dir, None,
|
|
|
- 0, 0, None)
|
|
|
+ change = presubmit.Change(
|
|
|
+ 'foo1', 'description1', self.fake_root_dir, None, 0, 0, None)
|
|
|
input_api = self.MockInputApi(change, False)
|
|
|
input_api.verbose = True
|
|
|
input_api.thread_pool.timeout = 100
|
|
@@ -2789,8 +2813,8 @@ the current line as well!
|
|
|
@mock.patch('io.open', mock.mock_open())
|
|
|
def testCannedRunUnitTestsPython3(self):
|
|
|
io.open().readline.return_value = '#!/usr/bin/env python3'
|
|
|
- change = libchange.Change('foo1', 'description1', self.fake_root_dir, None,
|
|
|
- 0, 0, None)
|
|
|
+ change = presubmit.Change(
|
|
|
+ 'foo1', 'description1', self.fake_root_dir, None, 0, 0, None)
|
|
|
input_api = self.MockInputApi(change, False)
|
|
|
input_api.verbose = True
|
|
|
input_api.PresubmitLocalPath.return_value = self.fake_root_dir
|
|
@@ -2845,8 +2869,8 @@ the current line as well!
|
|
|
@mock.patch('io.open', mock.mock_open())
|
|
|
def testCannedRunUnitTestsDontRunOnPython2(self):
|
|
|
io.open().readline.return_value = '#!/usr/bin/env python3'
|
|
|
- change = libchange.Change('foo1', 'description1', self.fake_root_dir, None,
|
|
|
- 0, 0, None)
|
|
|
+ change = presubmit.Change(
|
|
|
+ 'foo1', 'description1', self.fake_root_dir, None, 0, 0, None)
|
|
|
input_api = self.MockInputApi(change, False)
|
|
|
input_api.verbose = True
|
|
|
input_api.PresubmitLocalPath.return_value = self.fake_root_dir
|
|
@@ -2889,8 +2913,8 @@ the current line as well!
|
|
|
@mock.patch('io.open', mock.mock_open())
|
|
|
def testCannedRunUnitTestsDontRunOnPython3(self):
|
|
|
io.open().readline.return_value = '#!/usr/bin/env python3'
|
|
|
- change = libchange.Change('foo1', 'description1', self.fake_root_dir, None,
|
|
|
- 0, 0, None)
|
|
|
+ change = presubmit.Change(
|
|
|
+ 'foo1', 'description1', self.fake_root_dir, None, 0, 0, None)
|
|
|
input_api = self.MockInputApi(change, False)
|
|
|
input_api.verbose = True
|
|
|
input_api.PresubmitLocalPath.return_value = self.fake_root_dir
|
|
@@ -2931,8 +2955,8 @@ the current line as well!
|
|
|
self.checkstdout('')
|
|
|
|
|
|
def testCannedRunUnitTestsInDirectory(self):
|
|
|
- change = libchange.Change('foo1', 'description1', self.fake_root_dir, None,
|
|
|
- 0, 0, None)
|
|
|
+ change = presubmit.Change(
|
|
|
+ 'foo1', 'description1', self.fake_root_dir, None, 0, 0, None)
|
|
|
input_api = self.MockInputApi(change, False)
|
|
|
input_api.verbose = True
|
|
|
input_api.logging = mock.MagicMock(logging)
|
|
@@ -2964,10 +2988,10 @@ the current line as well!
|
|
|
|
|
|
def testPanProjectChecks(self):
|
|
|
# Make sure it accepts both list and tuples.
|
|
|
- change = libchange.Change('foo1', 'description1', self.fake_root_dir, None,
|
|
|
- 0, 0, None)
|
|
|
+ change = presubmit.Change(
|
|
|
+ 'foo1', 'description1', self.fake_root_dir, None, 0, 0, None)
|
|
|
input_api = self.MockInputApi(change, False)
|
|
|
- affected_file = mock.MagicMock(libchange.GitAffectedFile)
|
|
|
+ affected_file = mock.MagicMock(presubmit.GitAffectedFile)
|
|
|
input_api.AffectedFiles.return_value = [affected_file]
|
|
|
affected_file.NewContents.return_value = 'Hey!\nHo!\nHey!\nHo!\n\n'
|
|
|
# CheckChangeHasNoTabs() calls _FindNewViolationsOfRule() which calls
|
|
@@ -3064,13 +3088,13 @@ the current line as well!
|
|
|
])
|
|
|
|
|
|
def testCannedCheckVPythonSpec(self):
|
|
|
- change = libchange.Change('a', 'b', self.fake_root_dir, None, 0, 0, None)
|
|
|
+ change = presubmit.Change('a', 'b', self.fake_root_dir, None, 0, 0, None)
|
|
|
input_api = self.MockInputApi(change, False)
|
|
|
affected_filenames = ['/path1/to/.vpython', '/path1/to/.vpython3']
|
|
|
affected_files = []
|
|
|
|
|
|
for filename in affected_filenames:
|
|
|
- affected_file = mock.MagicMock(libchange.GitAffectedFile)
|
|
|
+ affected_file = mock.MagicMock(presubmit.GitAffectedFile)
|
|
|
affected_file.AbsoluteLocalPath.return_value = filename
|
|
|
affected_files.append(affected_file)
|
|
|
input_api.AffectedTestableFiles.return_value = affected_files
|