Mercurial > hg
annotate tests/test-filecache.py @ 17725:ffd589d4b785
vfs: define "join()" in each classes derived from "abstractvfs"
This patch defines "join()" in each classes derived from "abstractvfs"
except "vfs", which already defines it.
This allows all vfs instances to be used for indirect file API
invocation.
author | FUJIWARA Katsunori <foozy@lares.dti.ne.jp> |
---|---|
date | Tue, 09 Oct 2012 01:41:55 +0900 |
parents | cfb6682961b8 |
children | 3e4a944c0d04 |
rev | line source |
---|---|
14928 | 1 import sys, os, subprocess |
2 | |
16683 | 3 if subprocess.call(['python', '%s/hghave' % os.environ['TESTDIR'], |
4 'cacheable']): | |
14928 | 5 sys.exit(80) |
6 | |
7 from mercurial import util, scmutil, extensions | |
8 | |
9 filecache = scmutil.filecache | |
10 | |
11 class fakerepo(object): | |
12 def __init__(self): | |
13 self._filecache = {} | |
14 | |
15 def join(self, p): | |
16 return p | |
17 | |
18 def sjoin(self, p): | |
19 return p | |
20 | |
21 @filecache('x') | |
22 def cached(self): | |
23 print 'creating' | |
24 | |
25 def invalidate(self): | |
26 for k in self._filecache: | |
27 try: | |
28 delattr(self, k) | |
29 except AttributeError: | |
30 pass | |
31 | |
32 def basic(repo): | |
33 # file doesn't exist, calls function | |
34 repo.cached | |
35 | |
36 repo.invalidate() | |
37 # file still doesn't exist, uses cache | |
38 repo.cached | |
39 | |
40 # create empty file | |
41 f = open('x', 'w') | |
42 f.close() | |
43 repo.invalidate() | |
44 # should recreate the object | |
45 repo.cached | |
46 | |
47 f = open('x', 'w') | |
48 f.write('a') | |
49 f.close() | |
50 repo.invalidate() | |
51 # should recreate the object | |
52 repo.cached | |
53 | |
54 repo.invalidate() | |
55 # stats file again, nothing changed, reuses object | |
56 repo.cached | |
57 | |
58 # atomic replace file, size doesn't change | |
59 # hopefully st_mtime doesn't change as well so this doesn't use the cache | |
60 # because of inode change | |
61 f = scmutil.opener('.')('x', 'w', atomictemp=True) | |
62 f.write('b') | |
15057
774da7121fc9
atomictempfile: make close() consistent with other file-like objects.
Greg Ward <greg@gerg.ca>
parents:
14982
diff
changeset
|
63 f.close() |
14928 | 64 |
65 repo.invalidate() | |
66 repo.cached | |
67 | |
68 def fakeuncacheable(): | |
69 def wrapcacheable(orig, *args, **kwargs): | |
70 return False | |
71 | |
72 def wrapinit(orig, *args, **kwargs): | |
73 pass | |
74 | |
75 originit = extensions.wrapfunction(util.cachestat, '__init__', wrapinit) | |
14937
0b3e57c1b8c0
filecache: fix check-code complaint
Matt Mackall <mpm@selenic.com>
parents:
14928
diff
changeset
|
76 origcacheable = extensions.wrapfunction(util.cachestat, 'cacheable', |
0b3e57c1b8c0
filecache: fix check-code complaint
Matt Mackall <mpm@selenic.com>
parents:
14928
diff
changeset
|
77 wrapcacheable) |
14928 | 78 |
79 try: | |
80 os.remove('x') | |
16688
cfb6682961b8
cleanup: replace naked excepts with more specific ones
Brodie Rao <brodie@sf.io>
parents:
16683
diff
changeset
|
81 except OSError: |
14928 | 82 pass |
83 | |
84 basic(fakerepo()) | |
85 | |
86 util.cachestat.cacheable = origcacheable | |
87 util.cachestat.__init__ = originit | |
88 | |
89 print 'basic:' | |
90 print | |
91 basic(fakerepo()) | |
92 print | |
93 print 'fakeuncacheable:' | |
94 print | |
95 fakeuncacheable() |