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