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

Side by Side Diff: unittests/repo_test_util.py

Issue 2071443003: Introduce different repo types (git and gitiles) (Closed) Base URL: https://github.com/luci/recipes-py.git@master
Patch Set: rename Created 4 years, 6 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 | « unittests/package_test.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 2016 The LUCI Authors. All rights reserved. 1 # Copyright 2016 The LUCI Authors. All rights reserved.
2 # Use of this source code is governed under the Apache License, Version 2.0 2 # Use of this source code is governed under the Apache License, Version 2.0
3 # that can be found in the LICENSE file. 3 # that can be found in the LICENSE file.
4 4
5 """Utilities for testing with real repos (e.g. git).""" 5 """Utilities for testing with real repos (e.g. git)."""
6 6
7 7
8 import contextlib 8 import contextlib
9 import os 9 import os
10 import shutil 10 import shutil
11 import subprocess 11 import subprocess
12 import sys 12 import sys
13 import tempfile 13 import tempfile
14 import unittest 14 import unittest
15 15
16 16
17 ROOT_DIR = os.path.dirname(os.path.dirname(os.path.abspath(__file__))) 17 ROOT_DIR = os.path.dirname(os.path.dirname(os.path.abspath(__file__)))
18 sys.path.insert(0, os.path.join(ROOT_DIR, 'recipe_engine', 'third_party')) 18 sys.path.insert(0, os.path.join(ROOT_DIR, 'recipe_engine', 'third_party'))
19 sys.path.insert(0, ROOT_DIR) 19 sys.path.insert(0, ROOT_DIR)
20 20
21 21
22 from recipe_engine import fetch
22 from recipe_engine import package 23 from recipe_engine import package
23 from recipe_engine import package_pb2 24 from recipe_engine import package_pb2
24 25
25 26
26 @contextlib.contextmanager 27 @contextlib.contextmanager
27 def in_directory(target_dir): 28 def in_directory(target_dir):
28 """Context manager that restores original working directory on exit.""" 29 """Context manager that restores original working directory on exit."""
29 old_dir = os.getcwd() 30 old_dir = os.getcwd()
30 os.chdir(target_dir) 31 os.chdir(target_dir)
31 try: 32 try:
(...skipping 24 matching lines...) Expand all
56 repo_root='bar', 57 repo_root='bar',
57 allow_fetch=False 58 allow_fetch=False
58 ) 59 )
59 60
60 def tearDown(self): 61 def tearDown(self):
61 shutil.rmtree(self._root_dir) 62 shutil.rmtree(self._root_dir)
62 63
63 def get_git_repo_spec(self, repo): 64 def get_git_repo_spec(self, repo):
64 """Returns GitRepoSpec corresponding to given repo.""" 65 """Returns GitRepoSpec corresponding to given repo."""
65 return package.GitRepoSpec( 66 return package.GitRepoSpec(
66 repo['name'], repo['root'], 'master', repo['revision'], '') 67 repo['name'],
68 repo['root'],
69 'master',
70 repo['revision'],
71 '',
72 fetch.GitBackend())
67 73
68 def get_root_repo_spec(self, repo): 74 def get_root_repo_spec(self, repo):
69 """Returns RootRepoSpec corresponding to given repo.""" 75 """Returns RootRepoSpec corresponding to given repo."""
70 config_file = os.path.join(repo['root'], 'infra', 'config', 'recipes.cfg') 76 config_file = os.path.join(repo['root'], 'infra', 'config', 'recipes.cfg')
71 return package.RootRepoSpec(config_file) 77 return package.RootRepoSpec(config_file)
72 78
73 def get_package_spec(self, repo): 79 def get_package_spec(self, repo):
74 """Returns PackageSpec corresponding to given repo.""" 80 """Returns PackageSpec corresponding to given repo."""
75 config_file = os.path.join(repo['root'], 'infra', 'config', 'recipes.cfg') 81 config_file = os.path.join(repo['root'], 'infra', 'config', 'recipes.cfg')
76 return package.PackageSpec.load_proto(package.ProtoFile(config_file)) 82 return package.PackageSpec.load_proto(package.ProtoFile(config_file))
(...skipping 185 matching lines...) Expand 10 before | Expand all | Expand 10 after
262 message = ' '.join( 268 message = ' '.join(
263 ['update %r recipe_module: ' % name] + 269 ['update %r recipe_module: ' % name] +
264 ['%s(%s)' % t for t in methods.iteritems()] 270 ['%s(%s)' % t for t in methods.iteritems()]
265 ) 271 )
266 return self.commit_in_repo(repo, message) 272 return self.commit_in_repo(repo, message)
267 273
268 def reset_repo(self, repo, revision): 274 def reset_repo(self, repo, revision):
269 """Resets repo contents to given revision.""" 275 """Resets repo contents to given revision."""
270 with in_directory(repo['root']): 276 with in_directory(repo['root']):
271 subprocess.check_output(['git', 'reset', '--hard', revision]) 277 subprocess.check_output(['git', 'reset', '--hard', revision])
OLDNEW
« no previous file with comments | « unittests/package_test.py ('k') | no next file » | no next file with comments »

Powered by Google App Engine
This is Rietveld 408576698