gclient_test: use write() for hook tests

BUG=

Change-Id: I7561d252e10ae9b376e1b61ea3846cc8fc08f472
Reviewed-on: https://chromium-review.googlesource.com/1213323
Reviewed-by: Andrii Shyshkalov <tandrii@chromium.org>
Commit-Queue: Corentin Wallez <cwallez@chromium.org>
changes/23/1213323/3
Corentin Wallez 7 years ago committed by Commit Bot
parent f3d9294ba4
commit 82849ccc5a

@ -284,28 +284,22 @@ class GclientTest(trial_dir.TestCase):
self.assertEquals(322, len(str_obj), '%d\n%s' % (len(str_obj), str_obj)) self.assertEquals(322, len(str_obj), '%d\n%s' % (len(str_obj), str_obj))
def testHooks(self): def testHooks(self):
topdir = self.root_dir
gclient_fn = os.path.join(topdir, '.gclient')
fh = open(gclient_fn, 'w')
print >> fh, 'solutions = [{"name":"top","url":"svn://example.com/top"}]'
fh.close()
subdir_fn = os.path.join(topdir, 'top')
os.mkdir(subdir_fn)
deps_fn = os.path.join(subdir_fn, 'DEPS')
fh = open(deps_fn, 'w')
hooks = [{'pattern':'.', 'action':['cmd1', 'arg1', 'arg2']}] hooks = [{'pattern':'.', 'action':['cmd1', 'arg1', 'arg2']}]
print >> fh, 'hooks = %s' % repr(hooks)
fh.close()
fh = open(os.path.join(subdir_fn, 'fake.txt'), 'w') write('.gclient',
print >> fh, 'bogus content' 'solutions = [{\n'
fh.close() ' "name": "top",\n'
' "url": "svn://example.com/top"\n'
os.chdir(topdir) '}]')
write(os.path.join('top', 'DEPS'),
'hooks = %s' % repr(hooks))
write(os.path.join('top', 'fake.txt'),
"bogus content")
parser = gclient.OptionParser() parser = gclient.OptionParser()
options, _ = parser.parse_args([]) options, _ = parser.parse_args([])
options.force = True options.force = True
client = gclient.GClient.LoadCurrentConfig(options) client = gclient.GClient.LoadCurrentConfig(options)
work_queue = gclient_utils.ExecutionQueue(options.jobs, None, False) work_queue = gclient_utils.ExecutionQueue(options.jobs, None, False)
for s in client.dependencies: for s in client.dependencies:
@ -317,47 +311,47 @@ class GclientTest(trial_dir.TestCase):
[tuple(x['action']) for x in hooks]) [tuple(x['action']) for x in hooks])
def testCustomHooks(self): def testCustomHooks(self):
topdir = self.root_dir
gclient_fn = os.path.join(topdir, '.gclient')
fh = open(gclient_fn, 'w')
extra_hooks = [{'name': 'append', 'pattern': '.', 'action': ['supercmd']}] extra_hooks = [{'name': 'append', 'pattern': '.', 'action': ['supercmd']}]
print >> fh, ('solutions = [{"name":"top","url":"svn://example.com/top",'
'"custom_hooks": %s},' ) % repr(extra_hooks + [{'name': 'skip'}]) write('.gclient',
print >> fh, '{"name":"bottom","url":"svn://example.com/bottom"}]' 'solutions = [\n'
fh.close() ' {\n'
subdir_fn = os.path.join(topdir, 'top') ' "name": "top",\n'
os.mkdir(subdir_fn) ' "url": "svn://example.com/top",\n' +
deps_fn = os.path.join(subdir_fn, 'DEPS') (' "custom_hooks": %s' % repr(extra_hooks + [{'name': 'skip'}])) +
fh = open(deps_fn, 'w') ' },\n'
hooks = [{'pattern':'.', 'action':['cmd1', 'arg1', 'arg2']}] ' {\n'
hooks.append({'pattern':'.', 'action':['cmd2', 'arg1', 'arg2']}) ' "name": "bottom",\n'
' "url": "svn://example.com/bottom"\n'
' }\n'
']')
hooks = [
{'pattern':'.', 'action': ['cmd1', 'arg1', 'arg2']},
{'pattern':'.', 'action': ['cmd2', 'arg1', 'arg2']},
]
skip_hooks = [ skip_hooks = [
{'name': 'skip', 'pattern':'.', 'action':['cmd3', 'arg1', 'arg2']}] {'name': 'skip', 'pattern':'.', 'action': ['cmd3', 'arg1', 'arg2']},
skip_hooks.append( {'name': 'skip', 'pattern':'.', 'action': ['cmd4', 'arg1', 'arg2']},
{'name': 'skip', 'pattern':'.', 'action':['cmd4', 'arg1', 'arg2']}) ]
print >> fh, 'hooks = %s' % repr(hooks + skip_hooks) write(os.path.join('top', 'DEPS'),
fh.close() 'hooks = %s' % repr(hooks + skip_hooks))
# Make sure the custom hooks for that project don't affect the next one. # Make sure the custom hooks for that project don't affect the next one.
subdir_fn = os.path.join(topdir, 'bottom') sub_hooks = [
os.mkdir(subdir_fn) {'pattern':'.', 'action':['response1', 'yes1', 'yes2']},
deps_fn = os.path.join(subdir_fn, 'DEPS') {'name': 'skip', 'pattern': '.', 'action': ['response2', 'yes', 'sir']},
fh = open(deps_fn, 'w') ]
sub_hooks = [{'pattern':'.', 'action':['response1', 'yes1', 'yes2']}] write(os.path.join('bottom', 'DEPS'),
sub_hooks.append( 'hooks = %s' % repr(sub_hooks))
{'name': 'skip', 'pattern':'.', 'action':['response2', 'yes', 'sir']})
print >> fh, 'hooks = %s' % repr(sub_hooks) write(os.path.join('bottom', 'fake.txt'),
fh.close() "bogus content")
fh = open(os.path.join(subdir_fn, 'fake.txt'), 'w')
print >> fh, 'bogus content'
fh.close()
os.chdir(topdir)
parser = gclient.OptionParser() parser = gclient.OptionParser()
options, _ = parser.parse_args([]) options, _ = parser.parse_args([])
options.force = True options.force = True
client = gclient.GClient.LoadCurrentConfig(options) client = gclient.GClient.LoadCurrentConfig(options)
work_queue = gclient_utils.ExecutionQueue(options.jobs, None, False) work_queue = gclient_utils.ExecutionQueue(options.jobs, None, False)
for s in client.dependencies: for s in client.dependencies:

Loading…
Cancel
Save