##// END OF EJS Templates
filecache: fix check-code complaint
Matt Mackall -
r14937:0b3e57c1 default
parent child Browse files
Show More
@@ -1,95 +1,96 b''
1 1 import sys, os, subprocess
2 2
3 3 try:
4 4 subprocess.check_call(['%s/hghave' % os.environ['TESTDIR'], 'cacheable'])
5 5 except subprocess.CalledProcessError:
6 6 sys.exit(80)
7 7
8 8 from mercurial import util, scmutil, extensions
9 9
10 10 filecache = scmutil.filecache
11 11
12 12 class fakerepo(object):
13 13 def __init__(self):
14 14 self._filecache = {}
15 15
16 16 def join(self, p):
17 17 return p
18 18
19 19 def sjoin(self, p):
20 20 return p
21 21
22 22 @filecache('x')
23 23 def cached(self):
24 24 print 'creating'
25 25
26 26 def invalidate(self):
27 27 for k in self._filecache:
28 28 try:
29 29 delattr(self, k)
30 30 except AttributeError:
31 31 pass
32 32
33 33 def basic(repo):
34 34 # file doesn't exist, calls function
35 35 repo.cached
36 36
37 37 repo.invalidate()
38 38 # file still doesn't exist, uses cache
39 39 repo.cached
40 40
41 41 # create empty file
42 42 f = open('x', 'w')
43 43 f.close()
44 44 repo.invalidate()
45 45 # should recreate the object
46 46 repo.cached
47 47
48 48 f = open('x', 'w')
49 49 f.write('a')
50 50 f.close()
51 51 repo.invalidate()
52 52 # should recreate the object
53 53 repo.cached
54 54
55 55 repo.invalidate()
56 56 # stats file again, nothing changed, reuses object
57 57 repo.cached
58 58
59 59 # atomic replace file, size doesn't change
60 60 # hopefully st_mtime doesn't change as well so this doesn't use the cache
61 61 # because of inode change
62 62 f = scmutil.opener('.')('x', 'w', atomictemp=True)
63 63 f.write('b')
64 64 f.rename()
65 65
66 66 repo.invalidate()
67 67 repo.cached
68 68
69 69 def fakeuncacheable():
70 70 def wrapcacheable(orig, *args, **kwargs):
71 71 return False
72 72
73 73 def wrapinit(orig, *args, **kwargs):
74 74 pass
75 75
76 76 originit = extensions.wrapfunction(util.cachestat, '__init__', wrapinit)
77 origcacheable = extensions.wrapfunction(util.cachestat, 'cacheable', wrapcacheable)
77 origcacheable = extensions.wrapfunction(util.cachestat, 'cacheable',
78 wrapcacheable)
78 79
79 80 try:
80 81 os.remove('x')
81 82 except:
82 83 pass
83 84
84 85 basic(fakerepo())
85 86
86 87 util.cachestat.cacheable = origcacheable
87 88 util.cachestat.__init__ = originit
88 89
89 90 print 'basic:'
90 91 print
91 92 basic(fakerepo())
92 93 print
93 94 print 'fakeuncacheable:'
94 95 print
95 96 fakeuncacheable()
General Comments 0
You need to be logged in to leave comments. Login now