Mercurial > hg
annotate tests/test-filecache.py @ 16022:04604d1a9fc3 stable
push: more precise failure check on subrepo push
This will let us distinguish between nothing to push and push failed
author | Matt Mackall <mpm@selenic.com> |
---|---|
date | Mon, 30 Jan 2012 11:26:20 -0600 |
parents | d01e08ea459d |
children | 525fdb738975 |
rev | line source |
---|---|
14928 | 1 import sys, os, subprocess |
2 | |
15518
d01e08ea459d
tests: launch hghave with python interpreter without relying on hash-bang
Mads Kiilerich <mads@kiilerich.com>
parents:
15057
diff
changeset
|
3 if subprocess.call(['python', '%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() |