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

Side by Side Diff: tests/fake_repos.py

Issue 6350013: Change the fake repo svn users to be emails. (Closed) Base URL: svn://svn.chromium.org/chrome/trunk/tools/depot_tools
Patch Set: Created 9 years, 11 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 | « no previous file | tests/gclient_smoketest.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/python 1 #!/usr/bin/python
2 # Copyright (c) 2010 The Chromium Authors. All rights reserved. 2 # Copyright (c) 2010 The Chromium Authors. All rights reserved.
3 # Use of this source code is governed by a BSD-style license that can be 3 # Use of this source code is governed by a BSD-style license that can be
4 # found in the LICENSE file. 4 # found in the LICENSE file.
5 5
6 """Generate fake repositories for testing.""" 6 """Generate fake repositories for testing."""
7 7
8 import atexit 8 import atexit
9 import errno 9 import errno
10 import logging 10 import logging
(...skipping 138 matching lines...) Expand 10 before | Expand all | Expand 10 after
149 if k not in dict2: 149 if k not in dict2:
150 diff[k] = v 150 diff[k] = v
151 elif v != dict2[k]: 151 elif v != dict2[k]:
152 diff[k] = (v, dict2[k]) 152 diff[k] = (v, dict2[k])
153 for k, v in dict2.iteritems(): 153 for k, v in dict2.iteritems():
154 if k not in dict1: 154 if k not in dict1:
155 diff[k] = v 155 diff[k] = v
156 return diff 156 return diff
157 157
158 158
159 def commit_svn(repo): 159 def commit_svn(repo, usr, pwd):
160 """Commits the changes and returns the new revision number.""" 160 """Commits the changes and returns the new revision number."""
161 to_add = [] 161 to_add = []
162 to_remove = [] 162 to_remove = []
163 for status, filepath in scm.SVN.CaptureStatus(repo): 163 for status, filepath in scm.SVN.CaptureStatus(repo):
164 if status[0] == '?': 164 if status[0] == '?':
165 to_add.append(filepath) 165 to_add.append(filepath)
166 elif status[0] == '!': 166 elif status[0] == '!':
167 to_remove.append(filepath) 167 to_remove.append(filepath)
168 if to_add: 168 if to_add:
169 check_call(['svn', 'add', '--no-auto-props', '-q'] + to_add, cwd=repo) 169 check_call(['svn', 'add', '--no-auto-props', '-q'] + to_add, cwd=repo)
170 if to_remove: 170 if to_remove:
171 check_call(['svn', 'remove', '-q'] + to_remove, cwd=repo) 171 check_call(['svn', 'remove', '-q'] + to_remove, cwd=repo)
172 proc = Popen(['svn', 'commit', repo, '-m', 'foo', '--non-interactive', 172 proc = Popen(
173 '--no-auth-cache', '--username', 'user1', '--password', 'foo'], 173 ['svn', 'commit', repo, '-m', 'foo', '--non-interactive',
174 cwd=repo) 174 '--no-auth-cache',
175 '--username', usr, '--password', pwd],
176 cwd=repo)
175 out, err = proc.communicate() 177 out, err = proc.communicate()
176 match = re.search(r'(\d+)', out) 178 match = re.search(r'(\d+)', out)
177 if not match: 179 if not match:
178 raise Exception('Commit failed', out, err, proc.returncode) 180 raise Exception('Commit failed', out, err, proc.returncode)
179 rev = match.group(1) 181 rev = match.group(1)
180 st = Popen(['svn', 'status'], cwd=repo).communicate()[0] 182 st = Popen(['svn', 'status'], cwd=repo).communicate()[0]
181 assert len(st) == 0, st 183 assert len(st) == 0, st
182 logging.debug('At revision %s' % rev) 184 logging.debug('At revision %s' % rev)
183 return rev 185 return rev
184 186
(...skipping 21 matching lines...) Expand all
206 populateSvn() and populateGit() need to be implemented by the subclass. 208 populateSvn() and populateGit() need to be implemented by the subclass.
207 """ 209 """
208 210
209 # Should leak the repositories. 211 # Should leak the repositories.
210 SHOULD_LEAK = False 212 SHOULD_LEAK = False
211 # Override if unhappy. 213 # Override if unhappy.
212 TRIAL_DIR = None 214 TRIAL_DIR = None
213 # Hostname 215 # Hostname
214 HOST = '127.0.0.1' 216 HOST = '127.0.0.1'
215 NB_GIT_REPOS = 1 217 NB_GIT_REPOS = 1
218 USERS = [
219 ('user1@example.com', 'foo'),
220 ('user2@example.com', 'bar'),
221 ]
216 222
217 def __init__(self, trial_dir=None, leak=None, host=None): 223 def __init__(self, trial_dir=None, leak=None, host=None):
218 global _FAKE_LOADED 224 global _FAKE_LOADED
219 if _FAKE_LOADED: 225 if _FAKE_LOADED:
220 raise Exception('You can only start one FakeRepos at a time.') 226 raise Exception('You can only start one FakeRepos at a time.')
221 _FAKE_LOADED = True 227 _FAKE_LOADED = True
222 # Quick hack. 228 # Quick hack.
223 if '-v' in sys.argv: 229 if '-v' in sys.argv:
224 logging.basicConfig(level=logging.DEBUG) 230 logging.basicConfig(level=logging.DEBUG)
225 elif leak is not None: 231 elif leak is not None:
(...skipping 73 matching lines...) Expand 10 before | Expand all | Expand 10 after
299 root = join(self.repos_dir, 'svn') 305 root = join(self.repos_dir, 'svn')
300 try: 306 try:
301 check_call(['svnadmin', 'create', root]) 307 check_call(['svnadmin', 'create', root])
302 except OSError: 308 except OSError:
303 return False 309 return False
304 write(join(root, 'conf', 'svnserve.conf'), 310 write(join(root, 'conf', 'svnserve.conf'),
305 '[general]\n' 311 '[general]\n'
306 'anon-access = read\n' 312 'anon-access = read\n'
307 'auth-access = write\n' 313 'auth-access = write\n'
308 'password-db = passwd\n') 314 'password-db = passwd\n')
309 write(join(root, 'conf', 'passwd'), 315 text = '[users]\n'
310 '[users]\n' 316 text += ''.join('%s = %s\n' % (usr, pwd) for usr, pwd in self.USERS)
311 'user1 = foo\n' 317 write(join(root, 'conf', 'passwd'), text)
312 'user2 = bar\n')
313 318
314 # Start the daemon. 319 # Start the daemon.
315 cmd = ['svnserve', '-d', '--foreground', '-r', self.repos_dir] 320 cmd = ['svnserve', '-d', '--foreground', '-r', self.repos_dir]
316 if self.HOST == '127.0.0.1': 321 if self.HOST == '127.0.0.1':
317 cmd.append('--listen-host=127.0.0.1') 322 cmd.append('--listen-host=127.0.0.1')
318 self.svnserve = Popen(cmd, cwd=root) 323 self.svnserve = Popen(cmd, cwd=root)
319 self.populateSvn() 324 self.populateSvn()
320 return True 325 return True
321 326
322 def setUpGIT(self): 327 def setUpGIT(self):
(...skipping 10 matching lines...) Expand all
333 # Start the daemon. 338 # Start the daemon.
334 cmd = ['git', 'daemon', '--export-all', '--base-path=' + self.repos_dir] 339 cmd = ['git', 'daemon', '--export-all', '--base-path=' + self.repos_dir]
335 if self.HOST == '127.0.0.1': 340 if self.HOST == '127.0.0.1':
336 cmd.append('--listen=127.0.0.1') 341 cmd.append('--listen=127.0.0.1')
337 logging.debug(cmd) 342 logging.debug(cmd)
338 self.gitdaemon = Popen(cmd, cwd=self.repos_dir) 343 self.gitdaemon = Popen(cmd, cwd=self.repos_dir)
339 return True 344 return True
340 345
341 def _commit_svn(self, tree): 346 def _commit_svn(self, tree):
342 self._genTree(self.svn_root, tree) 347 self._genTree(self.svn_root, tree)
343 commit_svn(self.svn_root) 348 commit_svn(self.svn_root, self.USERS[0][0], self.USERS[0][1])
344 if self.svn_revs and self.svn_revs[-1]: 349 if self.svn_revs and self.svn_revs[-1]:
345 new_tree = self.svn_revs[-1].copy() 350 new_tree = self.svn_revs[-1].copy()
346 new_tree.update(tree) 351 new_tree.update(tree)
347 else: 352 else:
348 new_tree = tree.copy() 353 new_tree = tree.copy()
349 self.svn_revs.append(new_tree) 354 self.svn_revs.append(new_tree)
350 355
351 def _commit_git(self, repo, tree): 356 def _commit_git(self, repo, tree):
352 repo_root = join(self.git_root, repo) 357 repo_root = join(self.git_root, repo)
353 self._genTree(repo_root, tree) 358 self._genTree(repo_root, tree)
(...skipping 14 matching lines...) Expand all
368 373
369 class FakeRepos(FakeReposBase): 374 class FakeRepos(FakeReposBase):
370 """Implements populateSvn() and populateGit().""" 375 """Implements populateSvn() and populateGit()."""
371 NB_GIT_REPOS = 4 376 NB_GIT_REPOS = 4
372 377
373 def populateSvn(self): 378 def populateSvn(self):
374 """Creates a few revisions of changes including DEPS files.""" 379 """Creates a few revisions of changes including DEPS files."""
375 # Repos 380 # Repos
376 check_call(['svn', 'checkout', 'svn://127.0.0.1/svn', self.svn_root, '-q', 381 check_call(['svn', 'checkout', 'svn://127.0.0.1/svn', self.svn_root, '-q',
377 '--non-interactive', '--no-auth-cache', 382 '--non-interactive', '--no-auth-cache',
378 '--username', 'user1', '--password', 'foo']) 383 '--username', self.USERS[0][0], '--password', self.USERS[0][1]])
379 assert os.path.isdir(join(self.svn_root, '.svn')) 384 assert os.path.isdir(join(self.svn_root, '.svn'))
380 def file_system(rev, DEPS): 385 def file_system(rev, DEPS):
381 fs = { 386 fs = {
382 'origin': 'svn@%(rev)d\n', 387 'origin': 'svn@%(rev)d\n',
383 'trunk/origin': 'svn/trunk@%(rev)d\n', 388 'trunk/origin': 'svn/trunk@%(rev)d\n',
384 'trunk/src/origin': 'svn/trunk/src@%(rev)d\n', 389 'trunk/src/origin': 'svn/trunk/src@%(rev)d\n',
385 'trunk/src/third_party/origin': 'svn/trunk/src/third_party@%(rev)d\n', 390 'trunk/src/third_party/origin': 'svn/trunk/src/third_party@%(rev)d\n',
386 'trunk/other/origin': 'src/trunk/other@%(rev)d\n', 391 'trunk/other/origin': 'src/trunk/other@%(rev)d\n',
387 'trunk/third_party/origin': 'svn/trunk/third_party@%(rev)d\n', 392 'trunk/third_party/origin': 'svn/trunk/third_party@%(rev)d\n',
388 'trunk/third_party/foo/origin': 'svn/trunk/third_party/foo@%(rev)d\n', 393 'trunk/third_party/foo/origin': 'svn/trunk/third_party/foo@%(rev)d\n',
(...skipping 299 matching lines...) Expand 10 before | Expand all | Expand 10 after
688 693
689 694
690 # Kind of hack. 695 # Kind of hack.
691 if '-l' in sys.argv: 696 if '-l' in sys.argv:
692 FakeRepos.SHOULD_LEAK = True 697 FakeRepos.SHOULD_LEAK = True
693 sys.argv.remove('-l') 698 sys.argv.remove('-l')
694 699
695 700
696 if __name__ == '__main__': 701 if __name__ == '__main__':
697 sys.exit(main(sys.argv)) 702 sys.exit(main(sys.argv))
OLDNEW
« no previous file with comments | « no previous file | tests/gclient_smoketest.py » ('j') | no next file with comments »

Powered by Google App Engine
This is Rietveld 408576698