comparison tests/test-fncache.t @ 33956:1be228b96030

tests: update test-fncache to pass our import checker
author Augie Fackler <raf@durin42.com>
date Tue, 22 Aug 2017 15:51:12 -0400
parents 6c142f279625
children 4441705b7111
comparison
equal deleted inserted replaced
33955:efa6a420ba57 33956:1be228b96030
203 $ cd .. 203 $ cd ..
204 204
205 Aborting lock does not prevent fncache writes 205 Aborting lock does not prevent fncache writes
206 206
207 $ cat > exceptionext.py <<EOF 207 $ cat > exceptionext.py <<EOF
208 > from __future__ import absolute_import
208 > import os 209 > import os
209 > from mercurial import commands, error 210 > from mercurial import commands, error, extensions
210 > from mercurial.extensions import wrapcommand, wrapfunction
211 > 211 >
212 > def lockexception(orig, vfs, lockname, wait, releasefn, *args, **kwargs): 212 > def lockexception(orig, vfs, lockname, wait, releasefn, *args, **kwargs):
213 > def releasewrap(): 213 > def releasewrap():
214 > l.held = False # ensure __del__ is a noop 214 > l.held = False # ensure __del__ is a noop
215 > raise error.Abort("forced lock failure") 215 > raise error.Abort("forced lock failure")
216 > l = orig(vfs, lockname, wait, releasewrap, *args, **kwargs) 216 > l = orig(vfs, lockname, wait, releasewrap, *args, **kwargs)
217 > return l 217 > return l
218 > 218 >
219 > def reposetup(ui, repo): 219 > def reposetup(ui, repo):
220 > wrapfunction(repo, '_lock', lockexception) 220 > extensions.wrapfunction(repo, '_lock', lockexception)
221 > 221 >
222 > cmdtable = {} 222 > cmdtable = {}
223 > 223 >
224 > # wrap "commit" command to prevent wlock from being '__del__()'-ed 224 > # wrap "commit" command to prevent wlock from being '__del__()'-ed
225 > # at the end of dispatching (for intentional "forced lcok failure") 225 > # at the end of dispatching (for intentional "forced lcok failure")
234 > # prevents wlock from being released at same 'lockmod.release()' 234 > # prevents wlock from being released at same 'lockmod.release()'
235 > for i in range(wlock.held): 235 > for i in range(wlock.held):
236 > wlock.release() 236 > wlock.release()
237 > 237 >
238 > def extsetup(ui): 238 > def extsetup(ui):
239 > wrapcommand(commands.table, "commit", commitwrap) 239 > extensions.wrapcommand(commands.table, "commit", commitwrap)
240 > EOF 240 > EOF
241 $ extpath=`pwd`/exceptionext.py 241 $ extpath=`pwd`/exceptionext.py
242 $ hg init fncachetxn 242 $ hg init fncachetxn
243 $ cd fncachetxn 243 $ cd fncachetxn
244 $ printf "[extensions]\nexceptionext=$extpath\n" >> .hg/hgrc 244 $ printf "[extensions]\nexceptionext=$extpath\n" >> .hg/hgrc
250 data/y.i 250 data/y.i
251 251
252 Aborting transaction prevents fncache change 252 Aborting transaction prevents fncache change
253 253
254 $ cat > ../exceptionext.py <<EOF 254 $ cat > ../exceptionext.py <<EOF
255 > from __future__ import absolute_import
255 > import os 256 > import os
256 > from mercurial import commands, error, localrepo 257 > from mercurial import commands, error, extensions, localrepo
257 > from mercurial.extensions import wrapfunction
258 > 258 >
259 > def wrapper(orig, self, *args, **kwargs): 259 > def wrapper(orig, self, *args, **kwargs):
260 > tr = orig(self, *args, **kwargs) 260 > tr = orig(self, *args, **kwargs)
261 > def fail(tr): 261 > def fail(tr):
262 > raise error.Abort("forced transaction failure") 262 > raise error.Abort("forced transaction failure")
263 > # zzz prefix to ensure it sorted after store.write 263 > # zzz prefix to ensure it sorted after store.write
264 > tr.addfinalize('zzz-forcefails', fail) 264 > tr.addfinalize('zzz-forcefails', fail)
265 > return tr 265 > return tr
266 > 266 >
267 > def uisetup(ui): 267 > def uisetup(ui):
268 > wrapfunction(localrepo.localrepository, 'transaction', wrapper) 268 > extensions.wrapfunction(
269 > localrepo.localrepository, 'transaction', wrapper)
269 > 270 >
270 > cmdtable = {} 271 > cmdtable = {}
271 > 272 >
272 > EOF 273 > EOF
273 274
285 data/y.i 286 data/y.i
286 287
287 Aborted transactions can be recovered later 288 Aborted transactions can be recovered later
288 289
289 $ cat > ../exceptionext.py <<EOF 290 $ cat > ../exceptionext.py <<EOF
291 > from __future__ import absolute_import
290 > import os 292 > import os
291 > from mercurial import commands, error, transaction, localrepo 293 > from mercurial import (
292 > from mercurial.extensions import wrapfunction 294 > commands,
295 > error,
296 > extensions,
297 > localrepo,
298 > transaction,
299 > )
293 > 300 >
294 > def trwrapper(orig, self, *args, **kwargs): 301 > def trwrapper(orig, self, *args, **kwargs):
295 > tr = orig(self, *args, **kwargs) 302 > tr = orig(self, *args, **kwargs)
296 > def fail(tr): 303 > def fail(tr):
297 > raise error.Abort("forced transaction failure") 304 > raise error.Abort("forced transaction failure")
301 > 308 >
302 > def abortwrapper(orig, self, *args, **kwargs): 309 > def abortwrapper(orig, self, *args, **kwargs):
303 > raise error.Abort("forced transaction failure") 310 > raise error.Abort("forced transaction failure")
304 > 311 >
305 > def uisetup(ui): 312 > def uisetup(ui):
306 > wrapfunction(localrepo.localrepository, 'transaction', trwrapper) 313 > extensions.wrapfunction(localrepo.localrepository, 'transaction',
307 > wrapfunction(transaction.transaction, '_abort', abortwrapper) 314 > trwrapper)
315 > extensions.wrapfunction(transaction.transaction, '_abort',
316 > abortwrapper)
308 > 317 >
309 > cmdtable = {} 318 > cmdtable = {}
310 > 319 >
311 > EOF 320 > EOF
312 321