| OLD | NEW |
| 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 logging | 9 import logging |
| 10 import os | 10 import os |
| (...skipping 105 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
| 116 '#### PER-REPO CONFIGURATION (editable) ####', | 116 '#### PER-REPO CONFIGURATION (editable) ####', |
| 117 'REPO_ROOT = "."', | 117 'REPO_ROOT = "."', |
| 118 'RECIPES_CFG = os.path.join("infra", "config", "recipes.cfg")', | 118 'RECIPES_CFG = os.path.join("infra", "config", "recipes.cfg")', |
| 119 '#### END PER-REPO CONFIGURATION ####', | 119 '#### END PER-REPO CONFIGURATION ####', |
| 120 'if sys.argv[1] != "fetch":', | 120 'if sys.argv[1] != "fetch":', |
| 121 ' sys.exit(subprocess.call(', | 121 ' sys.exit(subprocess.call(', |
| 122 ' [sys.executable, %r, "--package", %r] + sys.argv[1:]))' % ( | 122 ' [sys.executable, %r, "--package", %r] + sys.argv[1:]))' % ( |
| 123 self._recipe_tool, | 123 self._recipe_tool, |
| 124 os.path.join(repo_dir, 'infra', 'config', 'recipes.cfg')), | 124 os.path.join(repo_dir, 'infra', 'config', 'recipes.cfg')), |
| 125 ])) | 125 ])) |
| 126 with open('some_file', 'w') as f: | 126 subprocess.check_output(['git', 'add', 'recipes.py']) |
| 127 print >> f, 'I\'m a file' | |
| 128 subprocess.check_output(['git', 'add', 'recipes.py', 'some_file']) | |
| 129 rev = self.update_recipes_cfg(name, spec) | 127 rev = self.update_recipes_cfg(name, spec) |
| 130 return { | 128 return { |
| 131 'name': name, | 129 'name': name, |
| 132 'root': repo_dir, | 130 'root': repo_dir, |
| 133 'revision': rev, | 131 'revision': rev, |
| 134 'spec': spec, | 132 'spec': spec, |
| 135 } | 133 } |
| 136 | 134 |
| 137 def repo_setup(self, repo_deps): | 135 def repo_setup(self, repo_deps): |
| 138 """Creates a set of repos with recipes.cfg reflecting requested | 136 """Creates a set of repos with recipes.cfg reflecting requested |
| (...skipping 51 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
| 190 | 188 |
| 191 def commit_in_repo(self, repo, message='Empty commit', | 189 def commit_in_repo(self, repo, message='Empty commit', |
| 192 author_name='John Doe', | 190 author_name='John Doe', |
| 193 author_email='john.doe@example.com'): | 191 author_email='john.doe@example.com'): |
| 194 """Creates a commit in given repo.""" | 192 """Creates a commit in given repo.""" |
| 195 root = repo['root'] | 193 root = repo['root'] |
| 196 | 194 |
| 197 env = dict(os.environ) | 195 env = dict(os.environ) |
| 198 env['GIT_AUTHOR_NAME'] = author_name | 196 env['GIT_AUTHOR_NAME'] = author_name |
| 199 env['GIT_AUTHOR_EMAIL'] = author_email | 197 env['GIT_AUTHOR_EMAIL'] = author_email |
| 200 with open(os.path.join(root, 'some_file'), 'a') as f: | |
| 201 print >> f, message | |
| 202 subprocess.check_output( | 198 subprocess.check_output( |
| 203 ['git', '-C', root, 'commit', | 199 ['git', '-C', root, 'commit', |
| 204 '-a', '-m', message], env=env) | 200 '-a', '--allow-empty', |
| 201 '-m', message], env=env) |
| 205 rev = subprocess.check_output( | 202 rev = subprocess.check_output( |
| 206 ['git', '-C', root, 'rev-parse', 'HEAD']).strip() | 203 ['git', '-C', root, 'rev-parse', 'HEAD']).strip() |
| 207 return { | 204 return { |
| 208 'root': repo['root'], | 205 'root': repo['root'], |
| 209 'revision': rev, | 206 'revision': rev, |
| 210 'spec': repo['spec'], | 207 'spec': repo['spec'], |
| 211 'author_name': author_name, | 208 'author_name': author_name, |
| 212 'author_email': author_email, | 209 'author_email': author_email, |
| 213 'message_lines': message.splitlines(), | 210 'message_lines': message.splitlines(), |
| 214 } | 211 } |
| (...skipping 127 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
| 342 os.unlink(os.path.join(module_dir, 'example.py')) | 339 os.unlink(os.path.join(module_dir, 'example.py')) |
| 343 | 340 |
| 344 self.train_recipes(repo) | 341 self.train_recipes(repo) |
| 345 | 342 |
| 346 subprocess.check_call(['git', 'add', module_dir]) | 343 subprocess.check_call(['git', 'add', module_dir]) |
| 347 message = ' '.join( | 344 message = ' '.join( |
| 348 ['update %r recipe_module: ' % name] + | 345 ['update %r recipe_module: ' % name] + |
| 349 ['%s(%s)' % t for t in methods.iteritems()] | 346 ['%s(%s)' % t for t in methods.iteritems()] |
| 350 ) | 347 ) |
| 351 return self.commit_in_repo(repo, message) | 348 return self.commit_in_repo(repo, message) |
| OLD | NEW |