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

Side by Side Diff: tools/mb/mb_unittest.py

Issue 1204793002: Fix errors in MB when run for the first time on a new builder. (Closed) Base URL: https://chromium.googlesource.com/chromium/src.git@master
Patch Set: patch for review Created 5 years, 5 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
« no previous file with comments | « tools/mb/mb.py ('k') | no next file » | no next file with comments »
Toggle Intra-line Diffs ('i') | Expand Comments ('e') | Collapse Comments ('c') | Show Comments Hide Comments ('s')
OLDNEW
1 # Copyright 2015 The Chromium Authors. All rights reserved. 1 # Copyright 2015 The Chromium Authors. All rights reserved.
2 # Use of this source code is governed by a BSD-style license that can be 2 # Use of this source code is governed by a BSD-style license that can be
3 # found in the LICENSE file. 3 # found in the LICENSE file.
4 4
5 """Tests for mb.py.""" 5 """Tests for mb.py."""
6 6
7 import json 7 import json
8 import sys 8 import sys
9 import unittest 9 import unittest
10 10
11 import mb 11 import mb
12 12
13 13
14 class FakeMBW(mb.MetaBuildWrapper): 14 class FakeMBW(mb.MetaBuildWrapper):
15 def __init__(self): 15 def __init__(self):
16 super(FakeMBW, self).__init__() 16 super(FakeMBW, self).__init__()
17 self.files = {} 17 self.files = {}
18 self.calls = [] 18 self.calls = []
19 self.cmds = []
Dirk Pranke 2015/06/23 19:54:37 the stuff related to self.cmds and TempFile() are
19 self.out = '' 20 self.out = ''
20 self.err = '' 21 self.err = ''
21 self.platform = 'linux2' 22 self.platform = 'linux2'
22 self.chromium_src_dir = '/fake_src' 23 self.chromium_src_dir = '/fake_src'
23 self.default_config = '/fake_src/tools/mb/mb_config.pyl' 24 self.default_config = '/fake_src/tools/mb/mb_config.pyl'
24 25
25 def ExpandUser(self, path): 26 def ExpandUser(self, path):
26 return '$HOME/%s' % path 27 return '$HOME/%s' % path
27 28
28 def Exists(self, path): 29 def Exists(self, path):
29 return self.files.get(path) is not None 30 return self.files.get(path) is not None
30 31
32 def MaybeMakeDirectory(self, path):
33 pass
34
31 def ReadFile(self, path): 35 def ReadFile(self, path):
32 return self.files[path] 36 return self.files[path]
33 37
34 def WriteFile(self, path, contents): 38 def WriteFile(self, path, contents):
35 self.files[path] = contents 39 self.files[path] = contents
36 40
37 def Call(self, cmd): 41 def Call(self, cmd):
38 self.calls.append(cmd) 42 self.calls.append(cmd)
43 if self.cmds:
44 return self.cmds.pop(0)
39 return 0, '', '' 45 return 0, '', ''
40 46
41 def Print(self, *args, **kwargs): 47 def Print(self, *args, **kwargs):
42 sep = kwargs.get('sep', ' ') 48 sep = kwargs.get('sep', ' ')
43 end = kwargs.get('end', '\n') 49 end = kwargs.get('end', '\n')
44 f = kwargs.get('file', sys.stdout) 50 f = kwargs.get('file', sys.stdout)
45 if f == sys.stderr: 51 if f == sys.stderr:
46 self.err += sep.join(args) + end 52 self.err += sep.join(args) + end
47 else: 53 else:
48 self.out += sep.join(args) + end 54 self.out += sep.join(args) + end
49 55
50 def TempFile(self): 56 def TempFile(self, mode='w'):
51 return FakeFile(self.files) 57 return FakeFile(self.files)
52 58
53 def RemoveFile(self, path): 59 def RemoveFile(self, path):
54 del self.files[path] 60 del self.files[path]
55 61
56 62
57 class FakeFile(object): 63 class FakeFile(object):
58 def __init__(self, files): 64 def __init__(self, files):
59 self.name = '/tmp/file' 65 self.name = '/tmp/file'
60 self.buf = '' 66 self.buf = ''
(...skipping 117 matching lines...) Expand 10 before | Expand all | Expand 10 after
178 files = {'/tmp/in.json': """{\ 184 files = {'/tmp/in.json': """{\
179 "files": ["foo/foo_unittest.cc"], 185 "files": ["foo/foo_unittest.cc"],
180 "targets": ["bar_unittests"] 186 "targets": ["bar_unittests"]
181 }"""} 187 }"""}
182 mbw = self.fake_mbw(files) 188 mbw = self.fake_mbw(files)
183 mbw.cmds = [ 189 mbw.cmds = [
184 (0, '', ''), 190 (0, '', ''),
185 (1, 'The input matches no targets, configs, or files\n', ''), 191 (1, 'The input matches no targets, configs, or files\n', ''),
186 (1, 'The input matches no targets, configs, or files\n', ''), 192 (1, 'The input matches no targets, configs, or files\n', ''),
187 ] 193 ]
188 mbw.Call = lambda cmd: mbw.cmds.pop(0)
189 194
190 self.check(['analyze', '-c', 'gn_debug', '//out/Default', 195 self.check(['analyze', '-c', 'gn_debug', '//out/Default',
191 '/tmp/in.json', '/tmp/out.json'], mbw=mbw, ret=0) 196 '/tmp/in.json', '/tmp/out.json'], mbw=mbw, ret=0)
192 out = json.loads(mbw.files['/tmp/out.json']) 197 out = json.loads(mbw.files['/tmp/out.json'])
193 self.assertEqual(out, { 198 self.assertEqual(out, {
194 'build_targets': [], 199 'build_targets': [],
195 'targets': [], 200 'targets': [],
196 'status': 'No dependency', 201 'status': 'No dependency',
197 }) 202 })
198 203
(...skipping 28 matching lines...) Expand all
227 232
228 def test_lookup(self): 233 def test_lookup(self):
229 self.check(['lookup', '-c', 'gn_debug'], ret=0) 234 self.check(['lookup', '-c', 'gn_debug'], ret=0)
230 235
231 def test_validate(self): 236 def test_validate(self):
232 self.check(['validate'], ret=0) 237 self.check(['validate'], ret=0)
233 238
234 239
235 if __name__ == '__main__': 240 if __name__ == '__main__':
236 unittest.main() 241 unittest.main()
OLDNEW
« no previous file with comments | « tools/mb/mb.py ('k') | no next file » | no next file with comments »

Powered by Google App Engine
This is Rietveld 408576698