Mercurial > hg
annotate tests/test-filecache.py @ 15456:abcaaf51d568
phases: handle unknown nodes in boundary
We filter unknown node out of the boundary. No data is lost. A
filtering is explicitly done after strip too
author | Pierre-Yves David <pierre-yves.david@ens-lyon.org> |
---|---|
date | Mon, 07 Nov 2011 13:20:22 +0100 |
parents | 774da7121fc9 |
children | d01e08ea459d |
rev | line source |
---|---|
14928 | 1 import sys, os, subprocess |
2 | |
14982
4c01478991a3
test-filecache: change for python 2.4 compatibility
Lee Cantey <lcantey@gmail.com>
parents:
14937
diff
changeset
|
3 if subprocess.call(['%s/hghave' % os.environ['TESTDIR'], 'cacheable']): |
14928 | 4 sys.exit(80) |
5 | |
6 from mercurial import util, scmutil, extensions | |
7 | |
8 filecache = scmutil.filecache | |
9 | |
10 class fakerepo(object): | |
11 def __init__(self): | |
12 self._filecache = {} | |
13 | |
14 def join(self, p): | |
15 return p | |
16 | |
17 def sjoin(self, p): | |
18 return p | |
19 | |
20 @filecache('x') | |
21 def cached(self): | |
22 print 'creating' | |
23 | |
24 def invalidate(self): | |
25 for k in self._filecache: | |
26 try: | |
27 delattr(self, k) | |
28 except AttributeError: | |
29 pass | |
30 | |
31 def basic(repo): | |
32 # file doesn't exist, calls function | |
33 repo.cached | |
34 | |
35 repo.invalidate() | |
36 # file still doesn't exist, uses cache | |
37 repo.cached | |
38 | |
39 # create empty file | |
40 f = open('x', 'w') | |
41 f.close() | |
42 repo.invalidate() | |
43 # should recreate the object | |
44 repo.cached | |
45 | |
46 f = open('x', 'w') | |
47 f.write('a') | |
48 f.close() | |
49 repo.invalidate() | |
50 # should recreate the object | |
51 repo.cached | |
52 | |
53 repo.invalidate() | |
54 # stats file again, nothing changed, reuses object | |
55 repo.cached | |
56 | |
57 # atomic replace file, size doesn't change | |
58 # hopefully st_mtime doesn't change as well so this doesn't use the cache | |
59 # because of inode change | |
60 f = scmutil.opener('.')('x', 'w', atomictemp=True) | |
61 f.write('b') | |
15057
774da7121fc9
atomictempfile: make close() consistent with other file-like objects.
Greg Ward <greg@gerg.ca>
parents:
14982
diff
changeset
|
62 f.close() |
14928 | 63 |
64 repo.invalidate() | |
65 repo.cached | |
66 | |
67 def fakeuncacheable(): | |
68 def wrapcacheable(orig, *args, **kwargs): | |
69 return False | |
70 | |
71 def wrapinit(orig, *args, **kwargs): | |
72 pass | |
73 | |
74 originit = extensions.wrapfunction(util.cachestat, '__init__', wrapinit) | |
14937
0b3e57c1b8c0
filecache: fix check-code complaint
Matt Mackall <mpm@selenic.com>
parents:
14928
diff
changeset
|
75 origcacheable = extensions.wrapfunction(util.cachestat, 'cacheable', |
0b3e57c1b8c0
filecache: fix check-code complaint
Matt Mackall <mpm@selenic.com>
parents:
14928
diff
changeset
|
76 wrapcacheable) |
14928 | 77 |
78 try: | |
79 os.remove('x') | |
80 except: | |
81 pass | |
82 | |
83 basic(fakerepo()) | |
84 | |
85 util.cachestat.cacheable = origcacheable | |
86 util.cachestat.__init__ = originit | |
87 | |
88 print 'basic:' | |
89 print | |
90 basic(fakerepo()) | |
91 print | |
92 print 'fakeuncacheable:' | |
93 print | |
94 fakeuncacheable() |