comparison tests/test_util.py @ 865:04729f3a3d17

test_util: merge load_fixture_and_fetch() into TestBase method The middle-term goal is to make TestBase repo_path and wc_path private, so they can be changed for every load call. This is not required to use nosetests multiprocess facility as the fixtures create temporary directories but it makes things much clearer and avoid weird cases where a repository was loaded several times at the same location in a single test (cf test_startrev). That way we will be more confident the tests can be parallelized. The long term goal is to make hgsubversion compatible with nosetests --processes option.
author Patrick Mezard <patrick@mezard.eu>
date Thu, 19 Apr 2012 18:29:25 +0200
parents e9af7eba88db
children 20e73b5ab6f7
comparison
equal deleted inserted replaced
864:39d45f2190ee 865:04729f3a3d17
175 req = dispatchmod.request(cmd) 175 req = dispatchmod.request(cmd)
176 dispatchmod.dispatch(req) 176 dispatchmod.dispatch(req)
177 except AttributeError, e: 177 except AttributeError, e:
178 dispatchmod.dispatch(cmd) 178 dispatchmod.dispatch(cmd)
179 179
180 def load_fixture_and_fetch(fixture_name, repo_path, wc_path, stupid=False,
181 subdir='', noupdate=True, layout='auto',
182 startrev=0, externals=None):
183 load_svndump_fixture(repo_path, fixture_name)
184 if subdir:
185 repo_path += '/' + subdir
186
187 cmd = [
188 'clone',
189 '--layout=%s' % layout,
190 '--startrev=%s' % startrev,
191 fileurl(repo_path),
192 wc_path,
193 ]
194 if stupid:
195 cmd.append('--stupid')
196 if noupdate:
197 cmd.append('--noupdate')
198 if externals:
199 cmd[:0] = ['--config', 'hgsubversion.externals=%s' % externals]
200
201 dispatch(cmd)
202
203 return hg.repository(testui(), wc_path)
204
205 def rmtree(path): 180 def rmtree(path):
206 # Read-only files cannot be removed under Windows 181 # Read-only files cannot be removed under Windows
207 for root, dirs, files in os.walk(path): 182 for root, dirs, files in os.walk(path):
208 for f in files: 183 for f in files:
209 f = os.path.join(root, f) 184 f = os.path.join(root, f)
290 265
291 def ui(self, stupid=False, layout='auto'): 266 def ui(self, stupid=False, layout='auto'):
292 return testui(stupid, layout) 267 return testui(stupid, layout)
293 268
294 def _load_fixture_and_fetch(self, fixture_name, subdir=None, stupid=False, 269 def _load_fixture_and_fetch(self, fixture_name, subdir=None, stupid=False,
295 layout='auto', startrev=0, externals=None): 270 layout='auto', startrev=0, externals=None,
271 noupdate=True):
296 if layout == 'single': 272 if layout == 'single':
297 if subdir is None: 273 if subdir is None:
298 subdir = 'trunk' 274 subdir = 'trunk'
299 elif subdir is None: 275 elif subdir is None:
300 subdir = '' 276 subdir = ''
301 return load_fixture_and_fetch(fixture_name, self.repo_path, 277 load_svndump_fixture(self.repo_path, fixture_name)
302 self.wc_path, subdir=subdir, 278 projectpath = self.repo_path
303 stupid=stupid, layout=layout, 279 if subdir:
304 startrev=startrev, externals=externals) 280 projectpath += '/' + subdir
281
282 cmd = [
283 'clone',
284 '--layout=%s' % layout,
285 '--startrev=%s' % startrev,
286 fileurl(projectpath),
287 self.wc_path,
288 ]
289 if stupid:
290 cmd.append('--stupid')
291 if noupdate:
292 cmd.append('--noupdate')
293 if externals:
294 cmd[:0] = ['--config', 'hgsubversion.externals=%s' % externals]
295
296 dispatch(cmd)
297
298 return hg.repository(testui(), self.wc_path)
305 299
306 def _add_svn_rev(self, changes): 300 def _add_svn_rev(self, changes):
307 '''changes is a dict of filename -> contents''' 301 '''changes is a dict of filename -> contents'''
308 if self.svn_wc is None: 302 if self.svn_wc is None:
309 self.svn_wc = os.path.join(self.tmpdir, 'testsvn_wc') 303 self.svn_wc = os.path.join(self.tmpdir, 'testsvn_wc')