Mercurial > hg
annotate tests/test-filecache.py @ 28778:256d90bb12fa
tests: make tinyproxy.py not import sys.argv by name
author | Yuya Nishihara <yuya@tcha.org> |
---|---|
date | Sun, 03 Apr 2016 20:12:59 +0900 |
parents | a08c90d622eb |
children | b16eacf5347c |
rev | line source |
---|---|
28742
a08c90d622eb
py3: use print_function in test-filecache.py
Robert Stanca <robert.stanca7@gmail.com>
parents:
28741
diff
changeset
|
1 from __future__ import absolute_import, print_function |
28741
fc5f548393bf
py3: use absolute_import in test-filecache.py
Robert Stanca <robert.stanca7@gmail.com>
parents:
26098
diff
changeset
|
2 import os |
fc5f548393bf
py3: use absolute_import in test-filecache.py
Robert Stanca <robert.stanca7@gmail.com>
parents:
26098
diff
changeset
|
3 import subprocess |
fc5f548393bf
py3: use absolute_import in test-filecache.py
Robert Stanca <robert.stanca7@gmail.com>
parents:
26098
diff
changeset
|
4 import sys |
14928 | 5 |
16683 | 6 if subprocess.call(['python', '%s/hghave' % os.environ['TESTDIR'], |
7 'cacheable']): | |
14928 | 8 sys.exit(80) |
9 | |
18313
3e4a944c0d04
destroyed: keep the filecache in sync with __dict__ (issue3335) (issue3693) (issue3743)
Idan Kamara <idankk86@gmail.com>
parents:
16688
diff
changeset
|
10 from mercurial import util, scmutil, extensions, hg, ui |
14928 | 11 |
12 filecache = scmutil.filecache | |
13 | |
14 class fakerepo(object): | |
15 def __init__(self): | |
16 self._filecache = {} | |
17 | |
18 def join(self, p): | |
19 return p | |
20 | |
21 def sjoin(self, p): | |
22 return p | |
23 | |
20045
b3684fd2ff1a
scmutil.filecache: support watching over multiple files
Siddharth Agarwal <sid0@fb.com>
parents:
20041
diff
changeset
|
24 @filecache('x', 'y') |
14928 | 25 def cached(self): |
28742
a08c90d622eb
py3: use print_function in test-filecache.py
Robert Stanca <robert.stanca7@gmail.com>
parents:
28741
diff
changeset
|
26 print('creating') |
20040
ed80cecdfc57
test-filecache.py: make setbeforeget test clearer
Siddharth Agarwal <sid0@fb.com>
parents:
18316
diff
changeset
|
27 return 'string from function' |
14928 | 28 |
29 def invalidate(self): | |
30 for k in self._filecache: | |
31 try: | |
32 delattr(self, k) | |
33 except AttributeError: | |
34 pass | |
35 | |
36 def basic(repo): | |
28742
a08c90d622eb
py3: use print_function in test-filecache.py
Robert Stanca <robert.stanca7@gmail.com>
parents:
28741
diff
changeset
|
37 print("* neither file exists") |
20041
42deff43460a
test-filecache.py: add markers to the output for each event
Siddharth Agarwal <sid0@fb.com>
parents:
20040
diff
changeset
|
38 # calls function |
14928 | 39 repo.cached |
40 | |
41 repo.invalidate() | |
28742
a08c90d622eb
py3: use print_function in test-filecache.py
Robert Stanca <robert.stanca7@gmail.com>
parents:
28741
diff
changeset
|
42 print("* neither file still exists") |
20041
42deff43460a
test-filecache.py: add markers to the output for each event
Siddharth Agarwal <sid0@fb.com>
parents:
20040
diff
changeset
|
43 # uses cache |
14928 | 44 repo.cached |
45 | |
46 # create empty file | |
47 f = open('x', 'w') | |
48 f.close() | |
49 repo.invalidate() | |
28742
a08c90d622eb
py3: use print_function in test-filecache.py
Robert Stanca <robert.stanca7@gmail.com>
parents:
28741
diff
changeset
|
50 print("* empty file x created") |
14928 | 51 # should recreate the object |
52 repo.cached | |
53 | |
54 f = open('x', 'w') | |
55 f.write('a') | |
56 f.close() | |
57 repo.invalidate() | |
28742
a08c90d622eb
py3: use print_function in test-filecache.py
Robert Stanca <robert.stanca7@gmail.com>
parents:
28741
diff
changeset
|
58 print("* file x changed size") |
14928 | 59 # should recreate the object |
60 repo.cached | |
61 | |
62 repo.invalidate() | |
28742
a08c90d622eb
py3: use print_function in test-filecache.py
Robert Stanca <robert.stanca7@gmail.com>
parents:
28741
diff
changeset
|
63 print("* nothing changed with either file") |
20041
42deff43460a
test-filecache.py: add markers to the output for each event
Siddharth Agarwal <sid0@fb.com>
parents:
20040
diff
changeset
|
64 # stats file again, reuses object |
14928 | 65 repo.cached |
66 | |
67 # atomic replace file, size doesn't change | |
68 # hopefully st_mtime doesn't change as well so this doesn't use the cache | |
69 # because of inode change | |
70 f = scmutil.opener('.')('x', 'w', atomictemp=True) | |
71 f.write('b') | |
15057
774da7121fc9
atomictempfile: make close() consistent with other file-like objects.
Greg Ward <greg@gerg.ca>
parents:
14982
diff
changeset
|
72 f.close() |
14928 | 73 |
74 repo.invalidate() | |
28742
a08c90d622eb
py3: use print_function in test-filecache.py
Robert Stanca <robert.stanca7@gmail.com>
parents:
28741
diff
changeset
|
75 print("* file x changed inode") |
14928 | 76 repo.cached |
77 | |
20045
b3684fd2ff1a
scmutil.filecache: support watching over multiple files
Siddharth Agarwal <sid0@fb.com>
parents:
20041
diff
changeset
|
78 # create empty file y |
b3684fd2ff1a
scmutil.filecache: support watching over multiple files
Siddharth Agarwal <sid0@fb.com>
parents:
20041
diff
changeset
|
79 f = open('y', 'w') |
b3684fd2ff1a
scmutil.filecache: support watching over multiple files
Siddharth Agarwal <sid0@fb.com>
parents:
20041
diff
changeset
|
80 f.close() |
b3684fd2ff1a
scmutil.filecache: support watching over multiple files
Siddharth Agarwal <sid0@fb.com>
parents:
20041
diff
changeset
|
81 repo.invalidate() |
28742
a08c90d622eb
py3: use print_function in test-filecache.py
Robert Stanca <robert.stanca7@gmail.com>
parents:
28741
diff
changeset
|
82 print("* empty file y created") |
20045
b3684fd2ff1a
scmutil.filecache: support watching over multiple files
Siddharth Agarwal <sid0@fb.com>
parents:
20041
diff
changeset
|
83 # should recreate the object |
b3684fd2ff1a
scmutil.filecache: support watching over multiple files
Siddharth Agarwal <sid0@fb.com>
parents:
20041
diff
changeset
|
84 repo.cached |
b3684fd2ff1a
scmutil.filecache: support watching over multiple files
Siddharth Agarwal <sid0@fb.com>
parents:
20041
diff
changeset
|
85 |
b3684fd2ff1a
scmutil.filecache: support watching over multiple files
Siddharth Agarwal <sid0@fb.com>
parents:
20041
diff
changeset
|
86 f = open('y', 'w') |
b3684fd2ff1a
scmutil.filecache: support watching over multiple files
Siddharth Agarwal <sid0@fb.com>
parents:
20041
diff
changeset
|
87 f.write('A') |
b3684fd2ff1a
scmutil.filecache: support watching over multiple files
Siddharth Agarwal <sid0@fb.com>
parents:
20041
diff
changeset
|
88 f.close() |
b3684fd2ff1a
scmutil.filecache: support watching over multiple files
Siddharth Agarwal <sid0@fb.com>
parents:
20041
diff
changeset
|
89 repo.invalidate() |
28742
a08c90d622eb
py3: use print_function in test-filecache.py
Robert Stanca <robert.stanca7@gmail.com>
parents:
28741
diff
changeset
|
90 print("* file y changed size") |
20045
b3684fd2ff1a
scmutil.filecache: support watching over multiple files
Siddharth Agarwal <sid0@fb.com>
parents:
20041
diff
changeset
|
91 # should recreate the object |
b3684fd2ff1a
scmutil.filecache: support watching over multiple files
Siddharth Agarwal <sid0@fb.com>
parents:
20041
diff
changeset
|
92 repo.cached |
b3684fd2ff1a
scmutil.filecache: support watching over multiple files
Siddharth Agarwal <sid0@fb.com>
parents:
20041
diff
changeset
|
93 |
b3684fd2ff1a
scmutil.filecache: support watching over multiple files
Siddharth Agarwal <sid0@fb.com>
parents:
20041
diff
changeset
|
94 f = scmutil.opener('.')('y', 'w', atomictemp=True) |
b3684fd2ff1a
scmutil.filecache: support watching over multiple files
Siddharth Agarwal <sid0@fb.com>
parents:
20041
diff
changeset
|
95 f.write('B') |
b3684fd2ff1a
scmutil.filecache: support watching over multiple files
Siddharth Agarwal <sid0@fb.com>
parents:
20041
diff
changeset
|
96 f.close() |
b3684fd2ff1a
scmutil.filecache: support watching over multiple files
Siddharth Agarwal <sid0@fb.com>
parents:
20041
diff
changeset
|
97 |
b3684fd2ff1a
scmutil.filecache: support watching over multiple files
Siddharth Agarwal <sid0@fb.com>
parents:
20041
diff
changeset
|
98 repo.invalidate() |
28742
a08c90d622eb
py3: use print_function in test-filecache.py
Robert Stanca <robert.stanca7@gmail.com>
parents:
28741
diff
changeset
|
99 print("* file y changed inode") |
20045
b3684fd2ff1a
scmutil.filecache: support watching over multiple files
Siddharth Agarwal <sid0@fb.com>
parents:
20041
diff
changeset
|
100 repo.cached |
b3684fd2ff1a
scmutil.filecache: support watching over multiple files
Siddharth Agarwal <sid0@fb.com>
parents:
20041
diff
changeset
|
101 |
b3684fd2ff1a
scmutil.filecache: support watching over multiple files
Siddharth Agarwal <sid0@fb.com>
parents:
20041
diff
changeset
|
102 f = scmutil.opener('.')('x', 'w', atomictemp=True) |
b3684fd2ff1a
scmutil.filecache: support watching over multiple files
Siddharth Agarwal <sid0@fb.com>
parents:
20041
diff
changeset
|
103 f.write('c') |
b3684fd2ff1a
scmutil.filecache: support watching over multiple files
Siddharth Agarwal <sid0@fb.com>
parents:
20041
diff
changeset
|
104 f.close() |
b3684fd2ff1a
scmutil.filecache: support watching over multiple files
Siddharth Agarwal <sid0@fb.com>
parents:
20041
diff
changeset
|
105 f = scmutil.opener('.')('y', 'w', atomictemp=True) |
b3684fd2ff1a
scmutil.filecache: support watching over multiple files
Siddharth Agarwal <sid0@fb.com>
parents:
20041
diff
changeset
|
106 f.write('C') |
b3684fd2ff1a
scmutil.filecache: support watching over multiple files
Siddharth Agarwal <sid0@fb.com>
parents:
20041
diff
changeset
|
107 f.close() |
b3684fd2ff1a
scmutil.filecache: support watching over multiple files
Siddharth Agarwal <sid0@fb.com>
parents:
20041
diff
changeset
|
108 |
b3684fd2ff1a
scmutil.filecache: support watching over multiple files
Siddharth Agarwal <sid0@fb.com>
parents:
20041
diff
changeset
|
109 repo.invalidate() |
28742
a08c90d622eb
py3: use print_function in test-filecache.py
Robert Stanca <robert.stanca7@gmail.com>
parents:
28741
diff
changeset
|
110 print("* both files changed inode") |
20045
b3684fd2ff1a
scmutil.filecache: support watching over multiple files
Siddharth Agarwal <sid0@fb.com>
parents:
20041
diff
changeset
|
111 repo.cached |
b3684fd2ff1a
scmutil.filecache: support watching over multiple files
Siddharth Agarwal <sid0@fb.com>
parents:
20041
diff
changeset
|
112 |
14928 | 113 def fakeuncacheable(): |
114 def wrapcacheable(orig, *args, **kwargs): | |
115 return False | |
116 | |
117 def wrapinit(orig, *args, **kwargs): | |
118 pass | |
119 | |
120 originit = extensions.wrapfunction(util.cachestat, '__init__', wrapinit) | |
14937
0b3e57c1b8c0
filecache: fix check-code complaint
Matt Mackall <mpm@selenic.com>
parents:
14928
diff
changeset
|
121 origcacheable = extensions.wrapfunction(util.cachestat, 'cacheable', |
0b3e57c1b8c0
filecache: fix check-code complaint
Matt Mackall <mpm@selenic.com>
parents:
14928
diff
changeset
|
122 wrapcacheable) |
14928 | 123 |
20045
b3684fd2ff1a
scmutil.filecache: support watching over multiple files
Siddharth Agarwal <sid0@fb.com>
parents:
20041
diff
changeset
|
124 for fn in ['x', 'y']: |
b3684fd2ff1a
scmutil.filecache: support watching over multiple files
Siddharth Agarwal <sid0@fb.com>
parents:
20041
diff
changeset
|
125 try: |
b3684fd2ff1a
scmutil.filecache: support watching over multiple files
Siddharth Agarwal <sid0@fb.com>
parents:
20041
diff
changeset
|
126 os.remove(fn) |
b3684fd2ff1a
scmutil.filecache: support watching over multiple files
Siddharth Agarwal <sid0@fb.com>
parents:
20041
diff
changeset
|
127 except OSError: |
b3684fd2ff1a
scmutil.filecache: support watching over multiple files
Siddharth Agarwal <sid0@fb.com>
parents:
20041
diff
changeset
|
128 pass |
14928 | 129 |
130 basic(fakerepo()) | |
131 | |
132 util.cachestat.cacheable = origcacheable | |
133 util.cachestat.__init__ = originit | |
134 | |
18313
3e4a944c0d04
destroyed: keep the filecache in sync with __dict__ (issue3335) (issue3693) (issue3743)
Idan Kamara <idankk86@gmail.com>
parents:
16688
diff
changeset
|
135 def test_filecache_synced(): |
26098 | 136 # test old behavior that caused filecached properties to go out of sync |
18313
3e4a944c0d04
destroyed: keep the filecache in sync with __dict__ (issue3335) (issue3693) (issue3743)
Idan Kamara <idankk86@gmail.com>
parents:
16688
diff
changeset
|
137 os.system('hg init && echo a >> a && hg ci -qAm.') |
3e4a944c0d04
destroyed: keep the filecache in sync with __dict__ (issue3335) (issue3693) (issue3743)
Idan Kamara <idankk86@gmail.com>
parents:
16688
diff
changeset
|
138 repo = hg.repository(ui.ui()) |
3e4a944c0d04
destroyed: keep the filecache in sync with __dict__ (issue3335) (issue3693) (issue3743)
Idan Kamara <idankk86@gmail.com>
parents:
16688
diff
changeset
|
139 # first rollback clears the filecache, but changelog to stays in __dict__ |
3e4a944c0d04
destroyed: keep the filecache in sync with __dict__ (issue3335) (issue3693) (issue3743)
Idan Kamara <idankk86@gmail.com>
parents:
16688
diff
changeset
|
140 repo.rollback() |
3e4a944c0d04
destroyed: keep the filecache in sync with __dict__ (issue3335) (issue3693) (issue3743)
Idan Kamara <idankk86@gmail.com>
parents:
16688
diff
changeset
|
141 repo.commit('.') |
3e4a944c0d04
destroyed: keep the filecache in sync with __dict__ (issue3335) (issue3693) (issue3743)
Idan Kamara <idankk86@gmail.com>
parents:
16688
diff
changeset
|
142 # second rollback comes along and touches the changelog externally |
3e4a944c0d04
destroyed: keep the filecache in sync with __dict__ (issue3335) (issue3693) (issue3743)
Idan Kamara <idankk86@gmail.com>
parents:
16688
diff
changeset
|
143 # (file is moved) |
3e4a944c0d04
destroyed: keep the filecache in sync with __dict__ (issue3335) (issue3693) (issue3743)
Idan Kamara <idankk86@gmail.com>
parents:
16688
diff
changeset
|
144 repo.rollback() |
3e4a944c0d04
destroyed: keep the filecache in sync with __dict__ (issue3335) (issue3693) (issue3743)
Idan Kamara <idankk86@gmail.com>
parents:
16688
diff
changeset
|
145 # but since changelog isn't under the filecache control anymore, we don't |
3e4a944c0d04
destroyed: keep the filecache in sync with __dict__ (issue3335) (issue3693) (issue3743)
Idan Kamara <idankk86@gmail.com>
parents:
16688
diff
changeset
|
146 # see that it changed, and return the old changelog without reconstructing |
3e4a944c0d04
destroyed: keep the filecache in sync with __dict__ (issue3335) (issue3693) (issue3743)
Idan Kamara <idankk86@gmail.com>
parents:
16688
diff
changeset
|
147 # it |
3e4a944c0d04
destroyed: keep the filecache in sync with __dict__ (issue3335) (issue3693) (issue3743)
Idan Kamara <idankk86@gmail.com>
parents:
16688
diff
changeset
|
148 repo.commit('.') |
3e4a944c0d04
destroyed: keep the filecache in sync with __dict__ (issue3335) (issue3693) (issue3743)
Idan Kamara <idankk86@gmail.com>
parents:
16688
diff
changeset
|
149 |
18316
f36375576ed5
filecache: create an entry in _filecache when __set__ is called for a missing one
Idan Kamara <idankk86@gmail.com>
parents:
18313
diff
changeset
|
150 def setbeforeget(repo): |
f36375576ed5
filecache: create an entry in _filecache when __set__ is called for a missing one
Idan Kamara <idankk86@gmail.com>
parents:
18313
diff
changeset
|
151 os.remove('x') |
20045
b3684fd2ff1a
scmutil.filecache: support watching over multiple files
Siddharth Agarwal <sid0@fb.com>
parents:
20041
diff
changeset
|
152 os.remove('y') |
20040
ed80cecdfc57
test-filecache.py: make setbeforeget test clearer
Siddharth Agarwal <sid0@fb.com>
parents:
18316
diff
changeset
|
153 repo.cached = 'string set externally' |
18316
f36375576ed5
filecache: create an entry in _filecache when __set__ is called for a missing one
Idan Kamara <idankk86@gmail.com>
parents:
18313
diff
changeset
|
154 repo.invalidate() |
28742
a08c90d622eb
py3: use print_function in test-filecache.py
Robert Stanca <robert.stanca7@gmail.com>
parents:
28741
diff
changeset
|
155 print("* neither file exists") |
a08c90d622eb
py3: use print_function in test-filecache.py
Robert Stanca <robert.stanca7@gmail.com>
parents:
28741
diff
changeset
|
156 print(repo.cached) |
18316
f36375576ed5
filecache: create an entry in _filecache when __set__ is called for a missing one
Idan Kamara <idankk86@gmail.com>
parents:
18313
diff
changeset
|
157 repo.invalidate() |
f36375576ed5
filecache: create an entry in _filecache when __set__ is called for a missing one
Idan Kamara <idankk86@gmail.com>
parents:
18313
diff
changeset
|
158 f = open('x', 'w') |
f36375576ed5
filecache: create an entry in _filecache when __set__ is called for a missing one
Idan Kamara <idankk86@gmail.com>
parents:
18313
diff
changeset
|
159 f.write('a') |
f36375576ed5
filecache: create an entry in _filecache when __set__ is called for a missing one
Idan Kamara <idankk86@gmail.com>
parents:
18313
diff
changeset
|
160 f.close() |
28742
a08c90d622eb
py3: use print_function in test-filecache.py
Robert Stanca <robert.stanca7@gmail.com>
parents:
28741
diff
changeset
|
161 print("* file x created") |
a08c90d622eb
py3: use print_function in test-filecache.py
Robert Stanca <robert.stanca7@gmail.com>
parents:
28741
diff
changeset
|
162 print(repo.cached) |
18316
f36375576ed5
filecache: create an entry in _filecache when __set__ is called for a missing one
Idan Kamara <idankk86@gmail.com>
parents:
18313
diff
changeset
|
163 |
20045
b3684fd2ff1a
scmutil.filecache: support watching over multiple files
Siddharth Agarwal <sid0@fb.com>
parents:
20041
diff
changeset
|
164 repo.cached = 'string 2 set externally' |
b3684fd2ff1a
scmutil.filecache: support watching over multiple files
Siddharth Agarwal <sid0@fb.com>
parents:
20041
diff
changeset
|
165 repo.invalidate() |
28742
a08c90d622eb
py3: use print_function in test-filecache.py
Robert Stanca <robert.stanca7@gmail.com>
parents:
28741
diff
changeset
|
166 print("* string set externally again") |
a08c90d622eb
py3: use print_function in test-filecache.py
Robert Stanca <robert.stanca7@gmail.com>
parents:
28741
diff
changeset
|
167 print(repo.cached) |
20045
b3684fd2ff1a
scmutil.filecache: support watching over multiple files
Siddharth Agarwal <sid0@fb.com>
parents:
20041
diff
changeset
|
168 |
b3684fd2ff1a
scmutil.filecache: support watching over multiple files
Siddharth Agarwal <sid0@fb.com>
parents:
20041
diff
changeset
|
169 repo.invalidate() |
b3684fd2ff1a
scmutil.filecache: support watching over multiple files
Siddharth Agarwal <sid0@fb.com>
parents:
20041
diff
changeset
|
170 f = open('y', 'w') |
b3684fd2ff1a
scmutil.filecache: support watching over multiple files
Siddharth Agarwal <sid0@fb.com>
parents:
20041
diff
changeset
|
171 f.write('b') |
b3684fd2ff1a
scmutil.filecache: support watching over multiple files
Siddharth Agarwal <sid0@fb.com>
parents:
20041
diff
changeset
|
172 f.close() |
28742
a08c90d622eb
py3: use print_function in test-filecache.py
Robert Stanca <robert.stanca7@gmail.com>
parents:
28741
diff
changeset
|
173 print("* file y created") |
a08c90d622eb
py3: use print_function in test-filecache.py
Robert Stanca <robert.stanca7@gmail.com>
parents:
28741
diff
changeset
|
174 print(repo.cached) |
20045
b3684fd2ff1a
scmutil.filecache: support watching over multiple files
Siddharth Agarwal <sid0@fb.com>
parents:
20041
diff
changeset
|
175 |
28742
a08c90d622eb
py3: use print_function in test-filecache.py
Robert Stanca <robert.stanca7@gmail.com>
parents:
28741
diff
changeset
|
176 print('basic:') |
a08c90d622eb
py3: use print_function in test-filecache.py
Robert Stanca <robert.stanca7@gmail.com>
parents:
28741
diff
changeset
|
177 print() |
14928 | 178 basic(fakerepo()) |
28742
a08c90d622eb
py3: use print_function in test-filecache.py
Robert Stanca <robert.stanca7@gmail.com>
parents:
28741
diff
changeset
|
179 print() |
a08c90d622eb
py3: use print_function in test-filecache.py
Robert Stanca <robert.stanca7@gmail.com>
parents:
28741
diff
changeset
|
180 print('fakeuncacheable:') |
a08c90d622eb
py3: use print_function in test-filecache.py
Robert Stanca <robert.stanca7@gmail.com>
parents:
28741
diff
changeset
|
181 print() |
14928 | 182 fakeuncacheable() |
18313
3e4a944c0d04
destroyed: keep the filecache in sync with __dict__ (issue3335) (issue3693) (issue3743)
Idan Kamara <idankk86@gmail.com>
parents:
16688
diff
changeset
|
183 test_filecache_synced() |
28742
a08c90d622eb
py3: use print_function in test-filecache.py
Robert Stanca <robert.stanca7@gmail.com>
parents:
28741
diff
changeset
|
184 print() |
a08c90d622eb
py3: use print_function in test-filecache.py
Robert Stanca <robert.stanca7@gmail.com>
parents:
28741
diff
changeset
|
185 print('setbeforeget:') |
a08c90d622eb
py3: use print_function in test-filecache.py
Robert Stanca <robert.stanca7@gmail.com>
parents:
28741
diff
changeset
|
186 print() |
18316
f36375576ed5
filecache: create an entry in _filecache when __set__ is called for a missing one
Idan Kamara <idankk86@gmail.com>
parents:
18313
diff
changeset
|
187 setbeforeget(fakerepo()) |