Chromium Code Reviews
chromiumcodereview-hr@appspot.gserviceaccount.com (chromiumcodereview-hr) | Please choose your nickname with Settings | Help | Chromium Project | Gerrit Changes | Sign out
(442)

Side by Side Diff: scripts/slave/unittests/annotated_run_test.py

Issue 1884523002: Extract update_scripts out of annotated_run (Closed) Base URL: svn://svn.chromium.org/chrome/trunk/tools/build
Patch Set: presubmit Created 4 years, 8 months ago
Use n/p to move between diff chunks; N/P to move between comments. Draft comments are only viewable by you.
Jump to:
View unified diff | Download patch | Annotate | Revision Log
« no previous file with comments | « scripts/slave/annotated_run.py ('k') | scripts/slave/update_scripts.py » ('j') | no next file with comments »
Toggle Intra-line Diffs ('i') | Expand Comments ('e') | Collapse Comments ('c') | Show Comments Hide Comments ('s')
OLDNEW
1 #!/usr/bin/env python 1 #!/usr/bin/env python
2 2
3 # Copyright 2015 The Chromium Authors. All rights reserved. 3 # Copyright 2015 The Chromium Authors. All rights reserved.
4 # Use of this source code is governed by a BSD-style license that can be 4 # Use of this source code is governed by a BSD-style license that can be
5 # found in the LICENSE file. 5 # found in the LICENSE file.
6 6
7 """Tests that the tools/build annotated_run wrapper actually runs.""" 7 """Tests that the tools/build annotated_run wrapper actually runs."""
8 8
9 import collections 9 import collections
10 import contextlib 10 import contextlib
11 import json 11 import json
12 import logging 12 import logging
13 import os 13 import os
14 import subprocess 14 import subprocess
15 import sys 15 import sys
16 import tempfile 16 import tempfile
17 import unittest 17 import unittest
18 18
19 import test_env # pylint: disable=W0403,W0611 19 import test_env # pylint: disable=W0403,W0611
20 20
21 import mock 21 import mock
22 from common import chromium_utils 22 from common import chromium_utils
23 from common import env 23 from common import env
24 from slave import annotated_run 24 from slave import annotated_run
25 from slave import gce 25 from slave import gce
26 from slave import infra_platform 26 from slave import infra_platform
27 from slave import update_scripts
27 28
28 BASE_DIR = os.path.dirname(os.path.dirname(os.path.abspath(__file__))) 29 BASE_DIR = os.path.dirname(os.path.dirname(os.path.abspath(__file__)))
29 30
30 31
31 MockOptions = collections.namedtuple('MockOptions', 32 MockOptions = collections.namedtuple('MockOptions',
32 ('dry_run', 'logdog_force', 'logdog_butler_path', 'logdog_annotee_path', 33 ('dry_run', 'logdog_force', 'logdog_butler_path', 'logdog_annotee_path',
33 'logdog_verbose', 'logdog_service_account_json', 'logdog_pubsub_topic', 34 'logdog_verbose', 'logdog_service_account_json', 'logdog_pubsub_topic',
34 'logdog_host')) 35 'logdog_host'))
35 36
36 37
37 class AnnotatedRunTest(unittest.TestCase): 38 class AnnotatedRunTest(unittest.TestCase):
38 def test_example(self): 39 def test_example(self):
39 build_properties = { 40 build_properties = {
40 'recipe': 'annotated_run_test', 41 'recipe': 'annotated_run_test',
41 'true_prop': True, 42 'true_prop': True,
42 'num_prop': 123, 43 'num_prop': 123,
43 'string_prop': '321', 44 'string_prop': '321',
44 'dict_prop': {'foo': 'bar'}, 45 'dict_prop': {'foo': 'bar'},
45 } 46 }
46 47
47 script_path = os.path.join(BASE_DIR, 'annotated_run.py') 48 script_path = os.path.join(BASE_DIR, 'annotated_run.py')
48 exit_code = subprocess.call([ 49 exit_code = subprocess.call([
49 'python', script_path, 50 'python', script_path,
50 '--build-properties=%s' % json.dumps(build_properties)]) 51 '--build-properties=%s' % json.dumps(build_properties)])
51 self.assertEqual(exit_code, 0) 52 self.assertEqual(exit_code, 0)
52 53
54 @mock.patch('slave.update_scripts._run_command')
53 @mock.patch('slave.annotated_run._run_command') 55 @mock.patch('slave.annotated_run._run_command')
54 @mock.patch('slave.annotated_run.main') 56 @mock.patch('slave.annotated_run.main')
55 @mock.patch('sys.platform', return_value='win') 57 @mock.patch('sys.platform', return_value='win')
56 @mock.patch('tempfile.mkstemp', side_effect=Exception('failure')) 58 @mock.patch('tempfile.mkstemp', side_effect=Exception('failure'))
57 @mock.patch('os.environ', {}) 59 @mock.patch('os.environ', {})
58 def test_update_scripts_must_run(self, _tempfile_mkstemp, _sys_platform, 60 def test_update_scripts_must_run(self, _tempfile_mkstemp, _sys_platform,
59 main, run_command): 61 main, annotated_run_command,
62 update_scripts_run_command):
63 update_scripts._run_command.return_value = (0, "")
64 annotated_run._run_command.return_value = (0, "")
60 annotated_run.main.side_effect = Exception('Test error!') 65 annotated_run.main.side_effect = Exception('Test error!')
61 annotated_run._run_command.return_value = (0, "")
62 annotated_run.shell_main(['annotated_run.py', 'foo']) 66 annotated_run.shell_main(['annotated_run.py', 'foo'])
63 67
64 gclient_path = os.path.join(env.Build, os.pardir, 'depot_tools', 68 gclient_path = os.path.join(env.Build, os.pardir, 'depot_tools',
65 'gclient.bat') 69 'gclient.bat')
66 run_command.assert_has_calls([ 70 annotated_run_command.assert_has_calls([
71 mock.call([sys.executable, 'annotated_run.py', 'foo']),
72 ])
73 update_scripts_run_command.assert_has_calls([
67 mock.call([gclient_path, 'sync', '--force', '--verbose', '--jobs=2', 74 mock.call([gclient_path, 'sync', '--force', '--verbose', '--jobs=2',
68 '--break_repo_locks'], 75 '--break_repo_locks'],
69 cwd=env.Build), 76 cwd=env.Build),
70 mock.call([sys.executable, 'annotated_run.py', 'foo']),
71 ]) 77 ])
72 main.assert_not_called() 78 main.assert_not_called()
73 79
74 80
75 class _AnnotatedRunExecTestBase(unittest.TestCase): 81 class _AnnotatedRunExecTestBase(unittest.TestCase):
76 def setUp(self): 82 def setUp(self):
77 logging.basicConfig(level=logging.ERROR+1) 83 logging.basicConfig(level=logging.ERROR+1)
78 84
79 self.maxDiff = None 85 self.maxDiff = None
80 self._patchers = [] 86 self._patchers = []
(...skipping 304 matching lines...) Expand 10 before | Expand all | Expand 10 after
385 391
386 def test_will_not_bootstrap_if_recursive(self): 392 def test_will_not_bootstrap_if_recursive(self):
387 os.environ['LOGDOG_STREAM_PREFIX'] = 'foo' 393 os.environ['LOGDOG_STREAM_PREFIX'] = 'foo'
388 self.assertRaises(annotated_run.LogDogNotBootstrapped, 394 self.assertRaises(annotated_run.LogDogNotBootstrapped,
389 annotated_run._logdog_bootstrap, self.rt, self.opts, self.basedir, 395 annotated_run._logdog_bootstrap, self.rt, self.opts, self.basedir,
390 self.tdir, self._config(), self.properties, []) 396 self.tdir, self._config(), self.properties, [])
391 397
392 398
393 if __name__ == '__main__': 399 if __name__ == '__main__':
394 unittest.main() 400 unittest.main()
OLDNEW
« no previous file with comments | « scripts/slave/annotated_run.py ('k') | scripts/slave/update_scripts.py » ('j') | no next file with comments »

Powered by Google App Engine
This is Rietveld 408576698