Mercurial > hg
annotate tests/test-filecache.py @ 38783:e7aa113b14f7
global: use pycompat.xrange()
On Python 3, our module importer automatically rewrites xrange()
to pycompat.xrange().
We want to move away from the custom importer on Python 3.
This commit converts all instances of xrange() to use
pycompat.xrange().
Differential Revision: https://phab.mercurial-scm.org/D4032
author | Gregory Szorc <gregory.szorc@gmail.com> |
---|---|
date | Wed, 01 Aug 2018 13:00:45 -0700 |
parents | b3ffa2faae04 |
children | 7caf632e30c3 |
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 |
36781
ffa3026d4196
cleanup: use stat_result[stat.ST_MTIME] instead of stat_result.st_mtime
Augie Fackler <augie@google.com>
parents:
36286
diff
changeset
|
3 import stat |
28741
fc5f548393bf
py3: use absolute_import in test-filecache.py
Robert Stanca <robert.stanca7@gmail.com>
parents:
26098
diff
changeset
|
4 import subprocess |
fc5f548393bf
py3: use absolute_import in test-filecache.py
Robert Stanca <robert.stanca7@gmail.com>
parents:
26098
diff
changeset
|
5 import sys |
14928 | 6 |
16683 | 7 if subprocess.call(['python', '%s/hghave' % os.environ['TESTDIR'], |
8 'cacheable']): | |
14928 | 9 sys.exit(80) |
10 | |
37900
b3ffa2faae04
tests: port test-filecache.py to Python 3
Augie Fackler <augie@google.com>
parents:
36781
diff
changeset
|
11 print_ = print |
b3ffa2faae04
tests: port test-filecache.py to Python 3
Augie Fackler <augie@google.com>
parents:
36781
diff
changeset
|
12 def print(*args, **kwargs): |
b3ffa2faae04
tests: port test-filecache.py to Python 3
Augie Fackler <augie@google.com>
parents:
36781
diff
changeset
|
13 """print() wrapper that flushes stdout buffers to avoid py3 buffer issues |
b3ffa2faae04
tests: port test-filecache.py to Python 3
Augie Fackler <augie@google.com>
parents:
36781
diff
changeset
|
14 |
b3ffa2faae04
tests: port test-filecache.py to Python 3
Augie Fackler <augie@google.com>
parents:
36781
diff
changeset
|
15 We could also just write directly to sys.stdout.buffer the way the |
b3ffa2faae04
tests: port test-filecache.py to Python 3
Augie Fackler <augie@google.com>
parents:
36781
diff
changeset
|
16 ui object will, but this was easier for porting the test. |
b3ffa2faae04
tests: port test-filecache.py to Python 3
Augie Fackler <augie@google.com>
parents:
36781
diff
changeset
|
17 """ |
b3ffa2faae04
tests: port test-filecache.py to Python 3
Augie Fackler <augie@google.com>
parents:
36781
diff
changeset
|
18 print_(*args, **kwargs) |
b3ffa2faae04
tests: port test-filecache.py to Python 3
Augie Fackler <augie@google.com>
parents:
36781
diff
changeset
|
19 sys.stdout.flush() |
b3ffa2faae04
tests: port test-filecache.py to Python 3
Augie Fackler <augie@google.com>
parents:
36781
diff
changeset
|
20 |
28802
b16eacf5347c
test-filecache: sort import lines
Yuya Nishihara <yuya@tcha.org>
parents:
28742
diff
changeset
|
21 from mercurial import ( |
b16eacf5347c
test-filecache: sort import lines
Yuya Nishihara <yuya@tcha.org>
parents:
28742
diff
changeset
|
22 extensions, |
b16eacf5347c
test-filecache: sort import lines
Yuya Nishihara <yuya@tcha.org>
parents:
28742
diff
changeset
|
23 hg, |
31284
74cbbd5420ba
filecache: explicitly test 'repofilecache'
Pierre-Yves David <pierre-yves.david@ens-lyon.org>
parents:
31251
diff
changeset
|
24 localrepo, |
36286
daa5f47558cf
py3: use range instead of xrange on py3 in tests/test-filecache.py
Pulkit Goyal <7895pulkit@gmail.com>
parents:
31284
diff
changeset
|
25 pycompat, |
28803
76c091f9711e
test-filecache: alias ui as uimod
Yuya Nishihara <yuya@tcha.org>
parents:
28802
diff
changeset
|
26 ui as uimod, |
28802
b16eacf5347c
test-filecache: sort import lines
Yuya Nishihara <yuya@tcha.org>
parents:
28742
diff
changeset
|
27 util, |
31251
34d57ddaf9f2
vfs: use 'vfs' module directly in 'test-filecache'
Pierre-Yves David <pierre-yves.david@ens-lyon.org>
parents:
31216
diff
changeset
|
28 vfs as vfsmod, |
28802
b16eacf5347c
test-filecache: sort import lines
Yuya Nishihara <yuya@tcha.org>
parents:
28742
diff
changeset
|
29 ) |
14928 | 30 |
36286
daa5f47558cf
py3: use range instead of xrange on py3 in tests/test-filecache.py
Pulkit Goyal <7895pulkit@gmail.com>
parents:
31284
diff
changeset
|
31 if pycompat.ispy3: |
daa5f47558cf
py3: use range instead of xrange on py3 in tests/test-filecache.py
Pulkit Goyal <7895pulkit@gmail.com>
parents:
31284
diff
changeset
|
32 xrange = range |
daa5f47558cf
py3: use range instead of xrange on py3 in tests/test-filecache.py
Pulkit Goyal <7895pulkit@gmail.com>
parents:
31284
diff
changeset
|
33 |
14928 | 34 class fakerepo(object): |
35 def __init__(self): | |
36 self._filecache = {} | |
37 | |
31284
74cbbd5420ba
filecache: explicitly test 'repofilecache'
Pierre-Yves David <pierre-yves.david@ens-lyon.org>
parents:
31251
diff
changeset
|
38 class fakevfs(object): |
74cbbd5420ba
filecache: explicitly test 'repofilecache'
Pierre-Yves David <pierre-yves.david@ens-lyon.org>
parents:
31251
diff
changeset
|
39 |
74cbbd5420ba
filecache: explicitly test 'repofilecache'
Pierre-Yves David <pierre-yves.david@ens-lyon.org>
parents:
31251
diff
changeset
|
40 def join(self, p): |
74cbbd5420ba
filecache: explicitly test 'repofilecache'
Pierre-Yves David <pierre-yves.david@ens-lyon.org>
parents:
31251
diff
changeset
|
41 return p |
74cbbd5420ba
filecache: explicitly test 'repofilecache'
Pierre-Yves David <pierre-yves.david@ens-lyon.org>
parents:
31251
diff
changeset
|
42 |
74cbbd5420ba
filecache: explicitly test 'repofilecache'
Pierre-Yves David <pierre-yves.david@ens-lyon.org>
parents:
31251
diff
changeset
|
43 vfs = fakevfs() |
74cbbd5420ba
filecache: explicitly test 'repofilecache'
Pierre-Yves David <pierre-yves.david@ens-lyon.org>
parents:
31251
diff
changeset
|
44 |
74cbbd5420ba
filecache: explicitly test 'repofilecache'
Pierre-Yves David <pierre-yves.david@ens-lyon.org>
parents:
31251
diff
changeset
|
45 def unfiltered(self): |
74cbbd5420ba
filecache: explicitly test 'repofilecache'
Pierre-Yves David <pierre-yves.david@ens-lyon.org>
parents:
31251
diff
changeset
|
46 return self |
14928 | 47 |
48 def sjoin(self, p): | |
49 return p | |
50 | |
31284
74cbbd5420ba
filecache: explicitly test 'repofilecache'
Pierre-Yves David <pierre-yves.david@ens-lyon.org>
parents:
31251
diff
changeset
|
51 @localrepo.repofilecache('x', 'y') |
14928 | 52 def cached(self): |
28742
a08c90d622eb
py3: use print_function in test-filecache.py
Robert Stanca <robert.stanca7@gmail.com>
parents:
28741
diff
changeset
|
53 print('creating') |
20040
ed80cecdfc57
test-filecache.py: make setbeforeget test clearer
Siddharth Agarwal <sid0@fb.com>
parents:
18316
diff
changeset
|
54 return 'string from function' |
14928 | 55 |
56 def invalidate(self): | |
57 for k in self._filecache: | |
58 try: | |
37900
b3ffa2faae04
tests: port test-filecache.py to Python 3
Augie Fackler <augie@google.com>
parents:
36781
diff
changeset
|
59 delattr(self, pycompat.sysstr(k)) |
14928 | 60 except AttributeError: |
61 pass | |
62 | |
63 def basic(repo): | |
28742
a08c90d622eb
py3: use print_function in test-filecache.py
Robert Stanca <robert.stanca7@gmail.com>
parents:
28741
diff
changeset
|
64 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
|
65 # calls function |
14928 | 66 repo.cached |
67 | |
68 repo.invalidate() | |
28742
a08c90d622eb
py3: use print_function in test-filecache.py
Robert Stanca <robert.stanca7@gmail.com>
parents:
28741
diff
changeset
|
69 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
|
70 # uses cache |
14928 | 71 repo.cached |
72 | |
73 # create empty file | |
74 f = open('x', 'w') | |
75 f.close() | |
76 repo.invalidate() | |
28742
a08c90d622eb
py3: use print_function in test-filecache.py
Robert Stanca <robert.stanca7@gmail.com>
parents:
28741
diff
changeset
|
77 print("* empty file x created") |
14928 | 78 # should recreate the object |
79 repo.cached | |
80 | |
81 f = open('x', 'w') | |
82 f.write('a') | |
83 f.close() | |
84 repo.invalidate() | |
28742
a08c90d622eb
py3: use print_function in test-filecache.py
Robert Stanca <robert.stanca7@gmail.com>
parents:
28741
diff
changeset
|
85 print("* file x changed size") |
14928 | 86 # should recreate the object |
87 repo.cached | |
88 | |
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("* 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
|
91 # stats file again, reuses object |
14928 | 92 repo.cached |
93 | |
94 # atomic replace file, size doesn't change | |
95 # hopefully st_mtime doesn't change as well so this doesn't use the cache | |
96 # because of inode change | |
37900
b3ffa2faae04
tests: port test-filecache.py to Python 3
Augie Fackler <augie@google.com>
parents:
36781
diff
changeset
|
97 f = vfsmod.vfs(b'.')(b'x', b'w', atomictemp=True) |
b3ffa2faae04
tests: port test-filecache.py to Python 3
Augie Fackler <augie@google.com>
parents:
36781
diff
changeset
|
98 f.write(b'b') |
15057
774da7121fc9
atomictempfile: make close() consistent with other file-like objects.
Greg Ward <greg@gerg.ca>
parents:
14982
diff
changeset
|
99 f.close() |
14928 | 100 |
101 repo.invalidate() | |
28742
a08c90d622eb
py3: use print_function in test-filecache.py
Robert Stanca <robert.stanca7@gmail.com>
parents:
28741
diff
changeset
|
102 print("* file x changed inode") |
14928 | 103 repo.cached |
104 | |
20045
b3684fd2ff1a
scmutil.filecache: support watching over multiple files
Siddharth Agarwal <sid0@fb.com>
parents:
20041
diff
changeset
|
105 # create empty file y |
b3684fd2ff1a
scmutil.filecache: support watching over multiple files
Siddharth Agarwal <sid0@fb.com>
parents:
20041
diff
changeset
|
106 f = open('y', 'w') |
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 repo.invalidate() |
28742
a08c90d622eb
py3: use print_function in test-filecache.py
Robert Stanca <robert.stanca7@gmail.com>
parents:
28741
diff
changeset
|
109 print("* empty file y created") |
20045
b3684fd2ff1a
scmutil.filecache: support watching over multiple files
Siddharth Agarwal <sid0@fb.com>
parents:
20041
diff
changeset
|
110 # should recreate the object |
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 |
b3684fd2ff1a
scmutil.filecache: support watching over multiple files
Siddharth Agarwal <sid0@fb.com>
parents:
20041
diff
changeset
|
113 f = open('y', 'w') |
b3684fd2ff1a
scmutil.filecache: support watching over multiple files
Siddharth Agarwal <sid0@fb.com>
parents:
20041
diff
changeset
|
114 f.write('A') |
b3684fd2ff1a
scmutil.filecache: support watching over multiple files
Siddharth Agarwal <sid0@fb.com>
parents:
20041
diff
changeset
|
115 f.close() |
b3684fd2ff1a
scmutil.filecache: support watching over multiple files
Siddharth Agarwal <sid0@fb.com>
parents:
20041
diff
changeset
|
116 repo.invalidate() |
28742
a08c90d622eb
py3: use print_function in test-filecache.py
Robert Stanca <robert.stanca7@gmail.com>
parents:
28741
diff
changeset
|
117 print("* file y changed size") |
20045
b3684fd2ff1a
scmutil.filecache: support watching over multiple files
Siddharth Agarwal <sid0@fb.com>
parents:
20041
diff
changeset
|
118 # should recreate the object |
b3684fd2ff1a
scmutil.filecache: support watching over multiple files
Siddharth Agarwal <sid0@fb.com>
parents:
20041
diff
changeset
|
119 repo.cached |
b3684fd2ff1a
scmutil.filecache: support watching over multiple files
Siddharth Agarwal <sid0@fb.com>
parents:
20041
diff
changeset
|
120 |
37900
b3ffa2faae04
tests: port test-filecache.py to Python 3
Augie Fackler <augie@google.com>
parents:
36781
diff
changeset
|
121 f = vfsmod.vfs(b'.')(b'y', b'w', atomictemp=True) |
b3ffa2faae04
tests: port test-filecache.py to Python 3
Augie Fackler <augie@google.com>
parents:
36781
diff
changeset
|
122 f.write(b'B') |
20045
b3684fd2ff1a
scmutil.filecache: support watching over multiple files
Siddharth Agarwal <sid0@fb.com>
parents:
20041
diff
changeset
|
123 f.close() |
b3684fd2ff1a
scmutil.filecache: support watching over multiple files
Siddharth Agarwal <sid0@fb.com>
parents:
20041
diff
changeset
|
124 |
b3684fd2ff1a
scmutil.filecache: support watching over multiple files
Siddharth Agarwal <sid0@fb.com>
parents:
20041
diff
changeset
|
125 repo.invalidate() |
28742
a08c90d622eb
py3: use print_function in test-filecache.py
Robert Stanca <robert.stanca7@gmail.com>
parents:
28741
diff
changeset
|
126 print("* file y changed inode") |
20045
b3684fd2ff1a
scmutil.filecache: support watching over multiple files
Siddharth Agarwal <sid0@fb.com>
parents:
20041
diff
changeset
|
127 repo.cached |
b3684fd2ff1a
scmutil.filecache: support watching over multiple files
Siddharth Agarwal <sid0@fb.com>
parents:
20041
diff
changeset
|
128 |
37900
b3ffa2faae04
tests: port test-filecache.py to Python 3
Augie Fackler <augie@google.com>
parents:
36781
diff
changeset
|
129 f = vfsmod.vfs(b'.')(b'x', b'w', atomictemp=True) |
b3ffa2faae04
tests: port test-filecache.py to Python 3
Augie Fackler <augie@google.com>
parents:
36781
diff
changeset
|
130 f.write(b'c') |
20045
b3684fd2ff1a
scmutil.filecache: support watching over multiple files
Siddharth Agarwal <sid0@fb.com>
parents:
20041
diff
changeset
|
131 f.close() |
37900
b3ffa2faae04
tests: port test-filecache.py to Python 3
Augie Fackler <augie@google.com>
parents:
36781
diff
changeset
|
132 f = vfsmod.vfs(b'.')(b'y', b'w', atomictemp=True) |
b3ffa2faae04
tests: port test-filecache.py to Python 3
Augie Fackler <augie@google.com>
parents:
36781
diff
changeset
|
133 f.write(b'C') |
20045
b3684fd2ff1a
scmutil.filecache: support watching over multiple files
Siddharth Agarwal <sid0@fb.com>
parents:
20041
diff
changeset
|
134 f.close() |
b3684fd2ff1a
scmutil.filecache: support watching over multiple files
Siddharth Agarwal <sid0@fb.com>
parents:
20041
diff
changeset
|
135 |
b3684fd2ff1a
scmutil.filecache: support watching over multiple files
Siddharth Agarwal <sid0@fb.com>
parents:
20041
diff
changeset
|
136 repo.invalidate() |
28742
a08c90d622eb
py3: use print_function in test-filecache.py
Robert Stanca <robert.stanca7@gmail.com>
parents:
28741
diff
changeset
|
137 print("* both files changed inode") |
20045
b3684fd2ff1a
scmutil.filecache: support watching over multiple files
Siddharth Agarwal <sid0@fb.com>
parents:
20041
diff
changeset
|
138 repo.cached |
b3684fd2ff1a
scmutil.filecache: support watching over multiple files
Siddharth Agarwal <sid0@fb.com>
parents:
20041
diff
changeset
|
139 |
14928 | 140 def fakeuncacheable(): |
141 def wrapcacheable(orig, *args, **kwargs): | |
142 return False | |
143 | |
144 def wrapinit(orig, *args, **kwargs): | |
145 pass | |
146 | |
147 originit = extensions.wrapfunction(util.cachestat, '__init__', wrapinit) | |
14937
0b3e57c1b8c0
filecache: fix check-code complaint
Matt Mackall <mpm@selenic.com>
parents:
14928
diff
changeset
|
148 origcacheable = extensions.wrapfunction(util.cachestat, 'cacheable', |
0b3e57c1b8c0
filecache: fix check-code complaint
Matt Mackall <mpm@selenic.com>
parents:
14928
diff
changeset
|
149 wrapcacheable) |
14928 | 150 |
20045
b3684fd2ff1a
scmutil.filecache: support watching over multiple files
Siddharth Agarwal <sid0@fb.com>
parents:
20041
diff
changeset
|
151 for fn in ['x', 'y']: |
b3684fd2ff1a
scmutil.filecache: support watching over multiple files
Siddharth Agarwal <sid0@fb.com>
parents:
20041
diff
changeset
|
152 try: |
b3684fd2ff1a
scmutil.filecache: support watching over multiple files
Siddharth Agarwal <sid0@fb.com>
parents:
20041
diff
changeset
|
153 os.remove(fn) |
b3684fd2ff1a
scmutil.filecache: support watching over multiple files
Siddharth Agarwal <sid0@fb.com>
parents:
20041
diff
changeset
|
154 except OSError: |
b3684fd2ff1a
scmutil.filecache: support watching over multiple files
Siddharth Agarwal <sid0@fb.com>
parents:
20041
diff
changeset
|
155 pass |
14928 | 156 |
157 basic(fakerepo()) | |
158 | |
159 util.cachestat.cacheable = origcacheable | |
160 util.cachestat.__init__ = originit | |
161 | |
18313
3e4a944c0d04
destroyed: keep the filecache in sync with __dict__ (issue3335) (issue3693) (issue3743)
Idan Kamara <idankk86@gmail.com>
parents:
16688
diff
changeset
|
162 def test_filecache_synced(): |
26098 | 163 # 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
|
164 os.system('hg init && echo a >> a && hg ci -qAm.') |
30559
d83ca854fa21
ui: factor out ui.load() to create a ui without loading configs (API)
Yuya Nishihara <yuya@tcha.org>
parents:
30332
diff
changeset
|
165 repo = hg.repository(uimod.ui.load()) |
18313
3e4a944c0d04
destroyed: keep the filecache in sync with __dict__ (issue3335) (issue3693) (issue3743)
Idan Kamara <idankk86@gmail.com>
parents:
16688
diff
changeset
|
166 # 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
|
167 repo.rollback() |
37900
b3ffa2faae04
tests: port test-filecache.py to Python 3
Augie Fackler <augie@google.com>
parents:
36781
diff
changeset
|
168 repo.commit(b'.') |
18313
3e4a944c0d04
destroyed: keep the filecache in sync with __dict__ (issue3335) (issue3693) (issue3743)
Idan Kamara <idankk86@gmail.com>
parents:
16688
diff
changeset
|
169 # 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
|
170 # (file is moved) |
3e4a944c0d04
destroyed: keep the filecache in sync with __dict__ (issue3335) (issue3693) (issue3743)
Idan Kamara <idankk86@gmail.com>
parents:
16688
diff
changeset
|
171 repo.rollback() |
3e4a944c0d04
destroyed: keep the filecache in sync with __dict__ (issue3335) (issue3693) (issue3743)
Idan Kamara <idankk86@gmail.com>
parents:
16688
diff
changeset
|
172 # 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
|
173 # 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
|
174 # it |
37900
b3ffa2faae04
tests: port test-filecache.py to Python 3
Augie Fackler <augie@google.com>
parents:
36781
diff
changeset
|
175 repo.commit(b'.') |
18313
3e4a944c0d04
destroyed: keep the filecache in sync with __dict__ (issue3335) (issue3693) (issue3743)
Idan Kamara <idankk86@gmail.com>
parents:
16688
diff
changeset
|
176 |
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
|
177 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
|
178 os.remove('x') |
20045
b3684fd2ff1a
scmutil.filecache: support watching over multiple files
Siddharth Agarwal <sid0@fb.com>
parents:
20041
diff
changeset
|
179 os.remove('y') |
20040
ed80cecdfc57
test-filecache.py: make setbeforeget test clearer
Siddharth Agarwal <sid0@fb.com>
parents:
18316
diff
changeset
|
180 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
|
181 repo.invalidate() |
28742
a08c90d622eb
py3: use print_function in test-filecache.py
Robert Stanca <robert.stanca7@gmail.com>
parents:
28741
diff
changeset
|
182 print("* neither file exists") |
a08c90d622eb
py3: use print_function in test-filecache.py
Robert Stanca <robert.stanca7@gmail.com>
parents:
28741
diff
changeset
|
183 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
|
184 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
|
185 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
|
186 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
|
187 f.close() |
28742
a08c90d622eb
py3: use print_function in test-filecache.py
Robert Stanca <robert.stanca7@gmail.com>
parents:
28741
diff
changeset
|
188 print("* file x created") |
a08c90d622eb
py3: use print_function in test-filecache.py
Robert Stanca <robert.stanca7@gmail.com>
parents:
28741
diff
changeset
|
189 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
|
190 |
20045
b3684fd2ff1a
scmutil.filecache: support watching over multiple files
Siddharth Agarwal <sid0@fb.com>
parents:
20041
diff
changeset
|
191 repo.cached = 'string 2 set externally' |
b3684fd2ff1a
scmutil.filecache: support watching over multiple files
Siddharth Agarwal <sid0@fb.com>
parents:
20041
diff
changeset
|
192 repo.invalidate() |
28742
a08c90d622eb
py3: use print_function in test-filecache.py
Robert Stanca <robert.stanca7@gmail.com>
parents:
28741
diff
changeset
|
193 print("* string set externally again") |
a08c90d622eb
py3: use print_function in test-filecache.py
Robert Stanca <robert.stanca7@gmail.com>
parents:
28741
diff
changeset
|
194 print(repo.cached) |
20045
b3684fd2ff1a
scmutil.filecache: support watching over multiple files
Siddharth Agarwal <sid0@fb.com>
parents:
20041
diff
changeset
|
195 |
b3684fd2ff1a
scmutil.filecache: support watching over multiple files
Siddharth Agarwal <sid0@fb.com>
parents:
20041
diff
changeset
|
196 repo.invalidate() |
b3684fd2ff1a
scmutil.filecache: support watching over multiple files
Siddharth Agarwal <sid0@fb.com>
parents:
20041
diff
changeset
|
197 f = open('y', 'w') |
b3684fd2ff1a
scmutil.filecache: support watching over multiple files
Siddharth Agarwal <sid0@fb.com>
parents:
20041
diff
changeset
|
198 f.write('b') |
b3684fd2ff1a
scmutil.filecache: support watching over multiple files
Siddharth Agarwal <sid0@fb.com>
parents:
20041
diff
changeset
|
199 f.close() |
28742
a08c90d622eb
py3: use print_function in test-filecache.py
Robert Stanca <robert.stanca7@gmail.com>
parents:
28741
diff
changeset
|
200 print("* file y created") |
a08c90d622eb
py3: use print_function in test-filecache.py
Robert Stanca <robert.stanca7@gmail.com>
parents:
28741
diff
changeset
|
201 print(repo.cached) |
20045
b3684fd2ff1a
scmutil.filecache: support watching over multiple files
Siddharth Agarwal <sid0@fb.com>
parents:
20041
diff
changeset
|
202 |
29995
57830bd0e787
scmutil: add file object wrapper class to check ambiguity at closing
FUJIWARA Katsunori <foozy@lares.dti.ne.jp>
parents:
28803
diff
changeset
|
203 def antiambiguity(): |
57830bd0e787
scmutil: add file object wrapper class to check ambiguity at closing
FUJIWARA Katsunori <foozy@lares.dti.ne.jp>
parents:
28803
diff
changeset
|
204 filename = 'ambigcheck' |
57830bd0e787
scmutil: add file object wrapper class to check ambiguity at closing
FUJIWARA Katsunori <foozy@lares.dti.ne.jp>
parents:
28803
diff
changeset
|
205 |
57830bd0e787
scmutil: add file object wrapper class to check ambiguity at closing
FUJIWARA Katsunori <foozy@lares.dti.ne.jp>
parents:
28803
diff
changeset
|
206 # try some times, because reproduction of ambiguity depends on |
57830bd0e787
scmutil: add file object wrapper class to check ambiguity at closing
FUJIWARA Katsunori <foozy@lares.dti.ne.jp>
parents:
28803
diff
changeset
|
207 # "filesystem time" |
57830bd0e787
scmutil: add file object wrapper class to check ambiguity at closing
FUJIWARA Katsunori <foozy@lares.dti.ne.jp>
parents:
28803
diff
changeset
|
208 for i in xrange(5): |
57830bd0e787
scmutil: add file object wrapper class to check ambiguity at closing
FUJIWARA Katsunori <foozy@lares.dti.ne.jp>
parents:
28803
diff
changeset
|
209 fp = open(filename, 'w') |
57830bd0e787
scmutil: add file object wrapper class to check ambiguity at closing
FUJIWARA Katsunori <foozy@lares.dti.ne.jp>
parents:
28803
diff
changeset
|
210 fp.write('FOO') |
57830bd0e787
scmutil: add file object wrapper class to check ambiguity at closing
FUJIWARA Katsunori <foozy@lares.dti.ne.jp>
parents:
28803
diff
changeset
|
211 fp.close() |
57830bd0e787
scmutil: add file object wrapper class to check ambiguity at closing
FUJIWARA Katsunori <foozy@lares.dti.ne.jp>
parents:
28803
diff
changeset
|
212 |
57830bd0e787
scmutil: add file object wrapper class to check ambiguity at closing
FUJIWARA Katsunori <foozy@lares.dti.ne.jp>
parents:
28803
diff
changeset
|
213 oldstat = os.stat(filename) |
36781
ffa3026d4196
cleanup: use stat_result[stat.ST_MTIME] instead of stat_result.st_mtime
Augie Fackler <augie@google.com>
parents:
36286
diff
changeset
|
214 if oldstat[stat.ST_CTIME] != oldstat[stat.ST_MTIME]: |
29995
57830bd0e787
scmutil: add file object wrapper class to check ambiguity at closing
FUJIWARA Katsunori <foozy@lares.dti.ne.jp>
parents:
28803
diff
changeset
|
215 # subsequent changing never causes ambiguity |
57830bd0e787
scmutil: add file object wrapper class to check ambiguity at closing
FUJIWARA Katsunori <foozy@lares.dti.ne.jp>
parents:
28803
diff
changeset
|
216 continue |
57830bd0e787
scmutil: add file object wrapper class to check ambiguity at closing
FUJIWARA Katsunori <foozy@lares.dti.ne.jp>
parents:
28803
diff
changeset
|
217 |
57830bd0e787
scmutil: add file object wrapper class to check ambiguity at closing
FUJIWARA Katsunori <foozy@lares.dti.ne.jp>
parents:
28803
diff
changeset
|
218 repetition = 3 |
57830bd0e787
scmutil: add file object wrapper class to check ambiguity at closing
FUJIWARA Katsunori <foozy@lares.dti.ne.jp>
parents:
28803
diff
changeset
|
219 |
57830bd0e787
scmutil: add file object wrapper class to check ambiguity at closing
FUJIWARA Katsunori <foozy@lares.dti.ne.jp>
parents:
28803
diff
changeset
|
220 # repeat changing via checkambigatclosing, to examine whether |
30332
318a24b52eeb
spelling: fixes of non-dictionary words
Mads Kiilerich <madski@unity3d.com>
parents:
29995
diff
changeset
|
221 # st_mtime is advanced multiple times as expected |
29995
57830bd0e787
scmutil: add file object wrapper class to check ambiguity at closing
FUJIWARA Katsunori <foozy@lares.dti.ne.jp>
parents:
28803
diff
changeset
|
222 for i in xrange(repetition): |
57830bd0e787
scmutil: add file object wrapper class to check ambiguity at closing
FUJIWARA Katsunori <foozy@lares.dti.ne.jp>
parents:
28803
diff
changeset
|
223 # explicit closing |
31251
34d57ddaf9f2
vfs: use 'vfs' module directly in 'test-filecache'
Pierre-Yves David <pierre-yves.david@ens-lyon.org>
parents:
31216
diff
changeset
|
224 fp = vfsmod.checkambigatclosing(open(filename, 'a')) |
29995
57830bd0e787
scmutil: add file object wrapper class to check ambiguity at closing
FUJIWARA Katsunori <foozy@lares.dti.ne.jp>
parents:
28803
diff
changeset
|
225 fp.write('FOO') |
57830bd0e787
scmutil: add file object wrapper class to check ambiguity at closing
FUJIWARA Katsunori <foozy@lares.dti.ne.jp>
parents:
28803
diff
changeset
|
226 fp.close() |
57830bd0e787
scmutil: add file object wrapper class to check ambiguity at closing
FUJIWARA Katsunori <foozy@lares.dti.ne.jp>
parents:
28803
diff
changeset
|
227 |
57830bd0e787
scmutil: add file object wrapper class to check ambiguity at closing
FUJIWARA Katsunori <foozy@lares.dti.ne.jp>
parents:
28803
diff
changeset
|
228 # implicit closing by "with" statement |
31251
34d57ddaf9f2
vfs: use 'vfs' module directly in 'test-filecache'
Pierre-Yves David <pierre-yves.david@ens-lyon.org>
parents:
31216
diff
changeset
|
229 with vfsmod.checkambigatclosing(open(filename, 'a')) as fp: |
29995
57830bd0e787
scmutil: add file object wrapper class to check ambiguity at closing
FUJIWARA Katsunori <foozy@lares.dti.ne.jp>
parents:
28803
diff
changeset
|
230 fp.write('BAR') |
57830bd0e787
scmutil: add file object wrapper class to check ambiguity at closing
FUJIWARA Katsunori <foozy@lares.dti.ne.jp>
parents:
28803
diff
changeset
|
231 |
57830bd0e787
scmutil: add file object wrapper class to check ambiguity at closing
FUJIWARA Katsunori <foozy@lares.dti.ne.jp>
parents:
28803
diff
changeset
|
232 newstat = os.stat(filename) |
36781
ffa3026d4196
cleanup: use stat_result[stat.ST_MTIME] instead of stat_result.st_mtime
Augie Fackler <augie@google.com>
parents:
36286
diff
changeset
|
233 if oldstat[stat.ST_CTIME] != newstat[stat.ST_CTIME]: |
29995
57830bd0e787
scmutil: add file object wrapper class to check ambiguity at closing
FUJIWARA Katsunori <foozy@lares.dti.ne.jp>
parents:
28803
diff
changeset
|
234 # timestamp ambiguity was naturally avoided while repetition |
57830bd0e787
scmutil: add file object wrapper class to check ambiguity at closing
FUJIWARA Katsunori <foozy@lares.dti.ne.jp>
parents:
28803
diff
changeset
|
235 continue |
57830bd0e787
scmutil: add file object wrapper class to check ambiguity at closing
FUJIWARA Katsunori <foozy@lares.dti.ne.jp>
parents:
28803
diff
changeset
|
236 |
57830bd0e787
scmutil: add file object wrapper class to check ambiguity at closing
FUJIWARA Katsunori <foozy@lares.dti.ne.jp>
parents:
28803
diff
changeset
|
237 # st_mtime should be advanced "repetition * 2" times, because |
30332
318a24b52eeb
spelling: fixes of non-dictionary words
Mads Kiilerich <madski@unity3d.com>
parents:
29995
diff
changeset
|
238 # all changes occurred at same time (in sec) |
36781
ffa3026d4196
cleanup: use stat_result[stat.ST_MTIME] instead of stat_result.st_mtime
Augie Fackler <augie@google.com>
parents:
36286
diff
changeset
|
239 expected = (oldstat[stat.ST_MTIME] + repetition * 2) & 0x7fffffff |
ffa3026d4196
cleanup: use stat_result[stat.ST_MTIME] instead of stat_result.st_mtime
Augie Fackler <augie@google.com>
parents:
36286
diff
changeset
|
240 if newstat[stat.ST_MTIME] != expected: |
ffa3026d4196
cleanup: use stat_result[stat.ST_MTIME] instead of stat_result.st_mtime
Augie Fackler <augie@google.com>
parents:
36286
diff
changeset
|
241 print("'newstat[stat.ST_MTIME] %s is not %s (as %s + %s * 2)" % |
ffa3026d4196
cleanup: use stat_result[stat.ST_MTIME] instead of stat_result.st_mtime
Augie Fackler <augie@google.com>
parents:
36286
diff
changeset
|
242 (newstat[stat.ST_MTIME], expected, |
ffa3026d4196
cleanup: use stat_result[stat.ST_MTIME] instead of stat_result.st_mtime
Augie Fackler <augie@google.com>
parents:
36286
diff
changeset
|
243 oldstat[stat.ST_MTIME], repetition)) |
29995
57830bd0e787
scmutil: add file object wrapper class to check ambiguity at closing
FUJIWARA Katsunori <foozy@lares.dti.ne.jp>
parents:
28803
diff
changeset
|
244 |
57830bd0e787
scmutil: add file object wrapper class to check ambiguity at closing
FUJIWARA Katsunori <foozy@lares.dti.ne.jp>
parents:
28803
diff
changeset
|
245 # no more examination is needed regardless of result |
57830bd0e787
scmutil: add file object wrapper class to check ambiguity at closing
FUJIWARA Katsunori <foozy@lares.dti.ne.jp>
parents:
28803
diff
changeset
|
246 break |
57830bd0e787
scmutil: add file object wrapper class to check ambiguity at closing
FUJIWARA Katsunori <foozy@lares.dti.ne.jp>
parents:
28803
diff
changeset
|
247 else: |
57830bd0e787
scmutil: add file object wrapper class to check ambiguity at closing
FUJIWARA Katsunori <foozy@lares.dti.ne.jp>
parents:
28803
diff
changeset
|
248 # This platform seems too slow to examine anti-ambiguity |
57830bd0e787
scmutil: add file object wrapper class to check ambiguity at closing
FUJIWARA Katsunori <foozy@lares.dti.ne.jp>
parents:
28803
diff
changeset
|
249 # of file timestamp (or test happened to be executed at |
57830bd0e787
scmutil: add file object wrapper class to check ambiguity at closing
FUJIWARA Katsunori <foozy@lares.dti.ne.jp>
parents:
28803
diff
changeset
|
250 # bad timing). Exit silently in this case, because running |
57830bd0e787
scmutil: add file object wrapper class to check ambiguity at closing
FUJIWARA Katsunori <foozy@lares.dti.ne.jp>
parents:
28803
diff
changeset
|
251 # on other faster platforms can detect problems |
57830bd0e787
scmutil: add file object wrapper class to check ambiguity at closing
FUJIWARA Katsunori <foozy@lares.dti.ne.jp>
parents:
28803
diff
changeset
|
252 pass |
57830bd0e787
scmutil: add file object wrapper class to check ambiguity at closing
FUJIWARA Katsunori <foozy@lares.dti.ne.jp>
parents:
28803
diff
changeset
|
253 |
28742
a08c90d622eb
py3: use print_function in test-filecache.py
Robert Stanca <robert.stanca7@gmail.com>
parents:
28741
diff
changeset
|
254 print('basic:') |
a08c90d622eb
py3: use print_function in test-filecache.py
Robert Stanca <robert.stanca7@gmail.com>
parents:
28741
diff
changeset
|
255 print() |
14928 | 256 basic(fakerepo()) |
28742
a08c90d622eb
py3: use print_function in test-filecache.py
Robert Stanca <robert.stanca7@gmail.com>
parents:
28741
diff
changeset
|
257 print() |
a08c90d622eb
py3: use print_function in test-filecache.py
Robert Stanca <robert.stanca7@gmail.com>
parents:
28741
diff
changeset
|
258 print('fakeuncacheable:') |
a08c90d622eb
py3: use print_function in test-filecache.py
Robert Stanca <robert.stanca7@gmail.com>
parents:
28741
diff
changeset
|
259 print() |
14928 | 260 fakeuncacheable() |
18313
3e4a944c0d04
destroyed: keep the filecache in sync with __dict__ (issue3335) (issue3693) (issue3743)
Idan Kamara <idankk86@gmail.com>
parents:
16688
diff
changeset
|
261 test_filecache_synced() |
28742
a08c90d622eb
py3: use print_function in test-filecache.py
Robert Stanca <robert.stanca7@gmail.com>
parents:
28741
diff
changeset
|
262 print() |
a08c90d622eb
py3: use print_function in test-filecache.py
Robert Stanca <robert.stanca7@gmail.com>
parents:
28741
diff
changeset
|
263 print('setbeforeget:') |
a08c90d622eb
py3: use print_function in test-filecache.py
Robert Stanca <robert.stanca7@gmail.com>
parents:
28741
diff
changeset
|
264 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
|
265 setbeforeget(fakerepo()) |
29995
57830bd0e787
scmutil: add file object wrapper class to check ambiguity at closing
FUJIWARA Katsunori <foozy@lares.dti.ne.jp>
parents:
28803
diff
changeset
|
266 print() |
57830bd0e787
scmutil: add file object wrapper class to check ambiguity at closing
FUJIWARA Katsunori <foozy@lares.dti.ne.jp>
parents:
28803
diff
changeset
|
267 print('antiambiguity:') |
57830bd0e787
scmutil: add file object wrapper class to check ambiguity at closing
FUJIWARA Katsunori <foozy@lares.dti.ne.jp>
parents:
28803
diff
changeset
|
268 print() |
57830bd0e787
scmutil: add file object wrapper class to check ambiguity at closing
FUJIWARA Katsunori <foozy@lares.dti.ne.jp>
parents:
28803
diff
changeset
|
269 antiambiguity() |