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

Side by Side Diff: scripts/slave/recipe_modules/path/api.py

Issue 23889036: Refactor the way that TestApi works so that it is actually useful. (Closed) Base URL: svn://svn.chromium.org/chrome/trunk/tools/build
Patch Set: rebase Created 7 years, 3 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
OLDNEW
1 # Copyright 2013 The Chromium Authors. All rights reserved. 1 # Copyright 2013 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 import os 5 import os
6 from slave import recipe_api 6 from slave import recipe_api
7 7
8 8
9 def path_method(api, name, base): 9 def path_method(api, name, base):
10 """Returns a shortcut static method which functions like os.path.join but 10 """Returns a shortcut static method which functions like os.path.join but
(...skipping 82 matching lines...) Expand 10 before | Expand all | Expand 10 after
93 exists (list): Paths which should exist in the test case. Thes must be paths 93 exists (list): Paths which should exist in the test case. Thes must be paths
94 using the [*_ROOT] placeholders. ex. '[BUILD_ROOT]/scripts'. 94 using the [*_ROOT] placeholders. ex. '[BUILD_ROOT]/scripts'.
95 """ 95 """
96 96
97 OK_METHODS = ('abspath', 'basename', 'exists', 'join', 'pardir', 97 OK_METHODS = ('abspath', 'basename', 'exists', 'join', 'pardir',
98 'sep', 'split', 'splitext') 98 'sep', 'split', 'splitext')
99 99
100 def __init__(self, **kwargs): 100 def __init__(self, **kwargs):
101 super(PathApi, self).__init__(**kwargs) 101 super(PathApi, self).__init__(**kwargs)
102 102
103 if self._mock is None: # pragma: no cover 103 if not self._test_data.enabled: # pragma: no cover
104 self._path_mod = os.path 104 self._path_mod = os.path
105 # e.g. /b/build/slave/<slavename>/build 105 # e.g. /b/build/slave/<slavename>/build
106 self.slave_build = path_method( 106 self.slave_build = path_method(
107 self, 'slave_build', self.abspath(os.getcwd())) 107 self, 'slave_build', self.abspath(os.getcwd()))
108 108
109 # e.g. /b 109 # e.g. /b
110 r = self.abspath(self.join(self.slave_build(), *([self.pardir]*4))) 110 r = self.abspath(self.join(self.slave_build(), *([self.pardir]*4)))
111 for token in ('build_internal', 'build', 'depot_tools'): 111 for token in ('build_internal', 'build', 'depot_tools'):
112 # e.g. /b/{token} 112 # e.g. /b/{token}
113 setattr(self, token, path_method(self, token, self.join(r, token))) 113 setattr(self, token, path_method(self, token, self.join(r, token)))
114 self.root = path_method(self, 'root', r) 114 self.root = path_method(self, 'root', r)
115 else: 115 else:
116 self._path_mod = mock_path(self.m, self._mock.get('exists', [])) 116 self._path_mod = mock_path(self.m, self._test_data.get('exists', []))
117 self.slave_build = path_method(self, 'slave_build', '[SLAVE_BUILD_ROOT]') 117 self.slave_build = path_method(self, 'slave_build', '[SLAVE_BUILD_ROOT]')
118 self.build_internal = path_method( 118 self.build_internal = path_method(
119 self, 'build_internal', '[BUILD_INTERNAL_ROOT]') 119 self, 'build_internal', '[BUILD_INTERNAL_ROOT]')
120 self.build = path_method(self, 'build', '[BUILD_ROOT]') 120 self.build = path_method(self, 'build', '[BUILD_ROOT]')
121 self.depot_tools = path_method(self, 'depot_tools', '[DEPOT_TOOLS_ROOT]') 121 self.depot_tools = path_method(self, 'depot_tools', '[DEPOT_TOOLS_ROOT]')
122 self.root = path_method(self, 'root', '[ROOT]') 122 self.root = path_method(self, 'root', '[ROOT]')
123 123
124 # Because it only makes sense to call self.checkout() after 124 # Because it only makes sense to call self.checkout() after
125 # a checkout has been defined, make calls to self.checkout() 125 # a checkout has been defined, make calls to self.checkout()
126 # explode with a helpful message until that point. 126 # explode with a helpful message until that point.
(...skipping 10 matching lines...) Expand all
137 137
138 The checked out source is often a forest of trees possibly inside other 138 The checked out source is often a forest of trees possibly inside other
139 trees. One of these trees' root is designated as special/primary and 139 trees. One of these trees' root is designated as special/primary and
140 this method builds paths inside of it. For Chrome, that would be 'src'. 140 this method builds paths inside of it. For Chrome, that would be 'src'.
141 This defaults to the special root of the first checkout. 141 This defaults to the special root of the first checkout.
142 """ 142 """
143 return self._checkout(*args, **kwargs) 143 return self._checkout(*args, **kwargs)
144 144
145 def mock_add_paths(self, path): 145 def mock_add_paths(self, path):
146 """For testing purposes, assert that |path| exists.""" 146 """For testing purposes, assert that |path| exists."""
147 if self._mock is not None: 147 if self._test_data.enabled:
148 self._path_mod.mock_add_paths(path) 148 self._path_mod.mock_add_paths(path)
149 149
150 def add_checkout(self, checkout, *pieces): 150 def add_checkout(self, checkout, *pieces):
151 """Assert that we have a source directory with this name. """ 151 """Assert that we have a source directory with this name. """
152 checkout = self.join(checkout, *pieces) 152 checkout = self.join(checkout, *pieces)
153 self.assert_absolute(checkout) 153 self.assert_absolute(checkout)
154 if not self._checkouts: 154 if not self._checkouts:
155 self._checkout = path_method(self, 'checkout', checkout) 155 self._checkout = path_method(self, 'checkout', checkout)
156 self._checkouts.append(checkout) 156 self._checkouts.append(checkout)
157 157
(...skipping 32 matching lines...) Expand 10 before | Expand all | Expand 10 after
190 if name in self.OK_METHODS: 190 if name in self.OK_METHODS:
191 return getattr(self._path_mod, name) 191 return getattr(self._path_mod, name)
192 raise AttributeError("'%s' object has no attribute '%s'" % 192 raise AttributeError("'%s' object has no attribute '%s'" %
193 (self._path_mod, name)) # pragma: no cover 193 (self._path_mod, name)) # pragma: no cover
194 194
195 def __dir__(self): # pragma: no cover 195 def __dir__(self): # pragma: no cover
196 # Used for helping out show_me_the_modules.py 196 # Used for helping out show_me_the_modules.py
197 return self.__dict__.keys() + list(self.OK_METHODS) 197 return self.__dict__.keys() + list(self.OK_METHODS)
198 198
199 # TODO(iannucci): Custom paths? 199 # TODO(iannucci): Custom paths?
OLDNEW

Powered by Google App Engine
This is Rietveld 408576698