comparison tests/test-propertycache.py @ 43076:2372284d9457

formatting: blacken the codebase This is using my patch to black (https://github.com/psf/black/pull/826) so we don't un-wrap collection literals. Done with: hg files 'set:**.py - mercurial/thirdparty/** - "contrib/python-zstandard/**"' | xargs black -S # skip-blame mass-reformatting only # no-check-commit reformats foo_bar functions Differential Revision: https://phab.mercurial-scm.org/D6971
author Augie Fackler <augie@google.com>
date Sun, 06 Oct 2019 09:45:02 -0400
parents e5d74742d00e
children 6000f5b25c9b
comparison
equal deleted inserted replaced
43075:57875cf423c9 43076:2372284d9457
14 pycompat, 14 pycompat,
15 ui as uimod, 15 ui as uimod,
16 util, 16 util,
17 ) 17 )
18 18
19 from mercurial.utils import ( 19 from mercurial.utils import procutil
20 procutil,
21 )
22 20
23 # create some special property cache that trace they call 21 # create some special property cache that trace they call
24 22
25 calllog = [] 23 calllog = []
24
25
26 @util.propertycache 26 @util.propertycache
27 def testcachedfoobar(repo): 27 def testcachedfoobar(repo):
28 name = repo.filtername 28 name = repo.filtername
29 if name is None: 29 if name is None:
30 name = '' 30 name = ''
31 val = len(name) 31 val = len(name)
32 calllog.append(val) 32 calllog.append(val)
33 return val 33 return val
34 34
35
35 unficalllog = [] 36 unficalllog = []
37
38
36 @localrepo.unfilteredpropertycache 39 @localrepo.unfilteredpropertycache
37 def testcachedunfifoobar(repo): 40 def testcachedunfifoobar(repo):
38 name = repo.filtername 41 name = repo.filtername
39 if name is None: 42 if name is None:
40 name = '' 43 name = ''
41 val = 100 + len(name) 44 val = 100 + len(name)
42 unficalllog.append(val) 45 unficalllog.append(val)
43 return val 46 return val
44 47
45 #plug them on repo 48
49 # plug them on repo
46 localrepo.localrepository.testcachedfoobar = testcachedfoobar 50 localrepo.localrepository.testcachedfoobar = testcachedfoobar
47 localrepo.localrepository.testcachedunfifoobar = testcachedunfifoobar 51 localrepo.localrepository.testcachedunfifoobar = testcachedunfifoobar
48 52
49 53
50 # Create an empty repo and instantiate it. It is important to run 54 # Create an empty repo and instantiate it. It is important to run
51 # these tests on the real object to detect regression. 55 # these tests on the real object to detect regression.
52 repopath = pycompat.fsencode(os.path.join(os.environ['TESTTMP'], 'repo')) 56 repopath = pycompat.fsencode(os.path.join(os.environ['TESTTMP'], 'repo'))
53 assert subprocess.call(pycompat.rapply(procutil.tonativestr, 57 assert (
54 [b'hg', b'init', repopath])) == 0 58 subprocess.call(
59 pycompat.rapply(procutil.tonativestr, [b'hg', b'init', repopath])
60 )
61 == 0
62 )
55 63
56 ui = uimod.ui.load() 64 ui = uimod.ui.load()
57 repo = hg.repository(ui, path=repopath).unfiltered() 65 repo = hg.repository(ui, path=repopath).unfiltered()
58 66
59 67
60 print('') 68 print('')
61 print('=== property cache ===') 69 print('=== property cache ===')
62 print('') 70 print('')
63 print('calllog:', calllog) 71 print('calllog:', calllog)
64 print('cached value (unfiltered):', 72 print(
65 vars(repo).get('testcachedfoobar', 'NOCACHE')) 73 'cached value (unfiltered):', vars(repo).get('testcachedfoobar', 'NOCACHE')
74 )
66 75
67 print('') 76 print('')
68 print('= first access on unfiltered, should do a call') 77 print('= first access on unfiltered, should do a call')
69 print('access:', repo.testcachedfoobar) 78 print('access:', repo.testcachedfoobar)
70 print('calllog:', calllog) 79 print('calllog:', calllog)
71 print('cached value (unfiltered):', 80 print(
72 vars(repo).get('testcachedfoobar', 'NOCACHE')) 81 'cached value (unfiltered):', vars(repo).get('testcachedfoobar', 'NOCACHE')
82 )
73 83
74 print('') 84 print('')
75 print('= second access on unfiltered, should not do call') 85 print('= second access on unfiltered, should not do call')
76 print('access', repo.testcachedfoobar) 86 print('access', repo.testcachedfoobar)
77 print('calllog:', calllog) 87 print('calllog:', calllog)
78 print('cached value (unfiltered):', 88 print(
79 vars(repo).get('testcachedfoobar', 'NOCACHE')) 89 'cached value (unfiltered):', vars(repo).get('testcachedfoobar', 'NOCACHE')
90 )
80 91
81 print('') 92 print('')
82 print('= first access on "visible" view, should do a call') 93 print('= first access on "visible" view, should do a call')
83 visibleview = repo.filtered('visible') 94 visibleview = repo.filtered('visible')
84 print('cached value ("visible" view):', 95 print(
85 vars(visibleview).get('testcachedfoobar', 'NOCACHE')) 96 'cached value ("visible" view):',
97 vars(visibleview).get('testcachedfoobar', 'NOCACHE'),
98 )
86 print('access:', visibleview.testcachedfoobar) 99 print('access:', visibleview.testcachedfoobar)
87 print('calllog:', calllog) 100 print('calllog:', calllog)
88 print('cached value (unfiltered):', 101 print(
89 vars(repo).get('testcachedfoobar', 'NOCACHE')) 102 'cached value (unfiltered):', vars(repo).get('testcachedfoobar', 'NOCACHE')
90 print('cached value ("visible" view):', 103 )
91 vars(visibleview).get('testcachedfoobar', 'NOCACHE')) 104 print(
105 'cached value ("visible" view):',
106 vars(visibleview).get('testcachedfoobar', 'NOCACHE'),
107 )
92 108
93 print('') 109 print('')
94 print('= second access on "visible view", should not do call') 110 print('= second access on "visible view", should not do call')
95 print('access:', visibleview.testcachedfoobar) 111 print('access:', visibleview.testcachedfoobar)
96 print('calllog:', calllog) 112 print('calllog:', calllog)
97 print('cached value (unfiltered):', 113 print(
98 vars(repo).get('testcachedfoobar', 'NOCACHE')) 114 'cached value (unfiltered):', vars(repo).get('testcachedfoobar', 'NOCACHE')
99 print('cached value ("visible" view):', 115 )
100 vars(visibleview).get('testcachedfoobar', 'NOCACHE')) 116 print(
117 'cached value ("visible" view):',
118 vars(visibleview).get('testcachedfoobar', 'NOCACHE'),
119 )
101 120
102 print('') 121 print('')
103 print('= no effect on other view') 122 print('= no effect on other view')
104 immutableview = repo.filtered('immutable') 123 immutableview = repo.filtered('immutable')
105 print('cached value ("immutable" view):', 124 print(
106 vars(immutableview).get('testcachedfoobar', 'NOCACHE')) 125 'cached value ("immutable" view):',
126 vars(immutableview).get('testcachedfoobar', 'NOCACHE'),
127 )
107 print('access:', immutableview.testcachedfoobar) 128 print('access:', immutableview.testcachedfoobar)
108 print('calllog:', calllog) 129 print('calllog:', calllog)
109 print('cached value (unfiltered):', 130 print(
110 vars(repo).get('testcachedfoobar', 'NOCACHE')) 131 'cached value (unfiltered):', vars(repo).get('testcachedfoobar', 'NOCACHE')
111 print('cached value ("visible" view):', 132 )
112 vars(visibleview).get('testcachedfoobar', 'NOCACHE')) 133 print(
113 print('cached value ("immutable" view):', 134 'cached value ("visible" view):',
114 vars(immutableview).get('testcachedfoobar', 'NOCACHE')) 135 vars(visibleview).get('testcachedfoobar', 'NOCACHE'),
136 )
137 print(
138 'cached value ("immutable" view):',
139 vars(immutableview).get('testcachedfoobar', 'NOCACHE'),
140 )
115 141
116 # unfiltered property cache test 142 # unfiltered property cache test
117 print('') 143 print('')
118 print('') 144 print('')
119 print('=== unfiltered property cache ===') 145 print('=== unfiltered property cache ===')
120 print('') 146 print('')
121 print('unficalllog:', unficalllog) 147 print('unficalllog:', unficalllog)
122 print('cached value (unfiltered): ', 148 print(
123 vars(repo).get('testcachedunfifoobar', 'NOCACHE')) 149 'cached value (unfiltered): ',
124 print('cached value ("visible" view): ', 150 vars(repo).get('testcachedunfifoobar', 'NOCACHE'),
125 vars(visibleview).get('testcachedunfifoobar', 'NOCACHE')) 151 )
126 print('cached value ("immutable" view):', 152 print(
127 vars(immutableview).get('testcachedunfifoobar', 'NOCACHE')) 153 'cached value ("visible" view): ',
154 vars(visibleview).get('testcachedunfifoobar', 'NOCACHE'),
155 )
156 print(
157 'cached value ("immutable" view):',
158 vars(immutableview).get('testcachedunfifoobar', 'NOCACHE'),
159 )
128 160
129 print('') 161 print('')
130 print('= first access on unfiltered, should do a call') 162 print('= first access on unfiltered, should do a call')
131 print('access (unfiltered):', repo.testcachedunfifoobar) 163 print('access (unfiltered):', repo.testcachedunfifoobar)
132 print('unficalllog:', unficalllog) 164 print('unficalllog:', unficalllog)
133 print('cached value (unfiltered): ', 165 print(
134 vars(repo).get('testcachedunfifoobar', 'NOCACHE')) 166 'cached value (unfiltered): ',
167 vars(repo).get('testcachedunfifoobar', 'NOCACHE'),
168 )
135 169
136 print('') 170 print('')
137 print('= second access on unfiltered, should not do call') 171 print('= second access on unfiltered, should not do call')
138 print('access (unfiltered):', repo.testcachedunfifoobar) 172 print('access (unfiltered):', repo.testcachedunfifoobar)
139 print('unficalllog:', unficalllog) 173 print('unficalllog:', unficalllog)
140 print('cached value (unfiltered): ', 174 print(
141 vars(repo).get('testcachedunfifoobar', 'NOCACHE')) 175 'cached value (unfiltered): ',
176 vars(repo).get('testcachedunfifoobar', 'NOCACHE'),
177 )
142 178
143 print('') 179 print('')
144 print('= access on view should use the unfiltered cache') 180 print('= access on view should use the unfiltered cache')
145 print('access (unfiltered): ', repo.testcachedunfifoobar) 181 print('access (unfiltered): ', repo.testcachedunfifoobar)
146 print('access ("visible" view): ', visibleview.testcachedunfifoobar) 182 print('access ("visible" view): ', visibleview.testcachedunfifoobar)
147 print('access ("immutable" view):', immutableview.testcachedunfifoobar) 183 print('access ("immutable" view):', immutableview.testcachedunfifoobar)
148 print('unficalllog:', unficalllog) 184 print('unficalllog:', unficalllog)
149 print('cached value (unfiltered): ', 185 print(
150 vars(repo).get('testcachedunfifoobar', 'NOCACHE')) 186 'cached value (unfiltered): ',
151 print('cached value ("visible" view): ', 187 vars(repo).get('testcachedunfifoobar', 'NOCACHE'),
152 vars(visibleview).get('testcachedunfifoobar', 'NOCACHE')) 188 )
153 print('cached value ("immutable" view):', 189 print(
154 vars(immutableview).get('testcachedunfifoobar', 'NOCACHE')) 190 'cached value ("visible" view): ',
191 vars(visibleview).get('testcachedunfifoobar', 'NOCACHE'),
192 )
193 print(
194 'cached value ("immutable" view):',
195 vars(immutableview).get('testcachedunfifoobar', 'NOCACHE'),
196 )
155 197
156 print('') 198 print('')
157 print('= even if we clear the unfiltered cache') 199 print('= even if we clear the unfiltered cache')
158 del repo.__dict__['testcachedunfifoobar'] 200 del repo.__dict__['testcachedunfifoobar']
159 print('cached value (unfiltered): ', 201 print(
160 vars(repo).get('testcachedunfifoobar', 'NOCACHE')) 202 'cached value (unfiltered): ',
161 print('cached value ("visible" view): ', 203 vars(repo).get('testcachedunfifoobar', 'NOCACHE'),
162 vars(visibleview).get('testcachedunfifoobar', 'NOCACHE')) 204 )
163 print('cached value ("immutable" view):', 205 print(
164 vars(immutableview).get('testcachedunfifoobar', 'NOCACHE')) 206 'cached value ("visible" view): ',
207 vars(visibleview).get('testcachedunfifoobar', 'NOCACHE'),
208 )
209 print(
210 'cached value ("immutable" view):',
211 vars(immutableview).get('testcachedunfifoobar', 'NOCACHE'),
212 )
165 print('unficalllog:', unficalllog) 213 print('unficalllog:', unficalllog)
166 print('access ("visible" view): ', visibleview.testcachedunfifoobar) 214 print('access ("visible" view): ', visibleview.testcachedunfifoobar)
167 print('unficalllog:', unficalllog) 215 print('unficalllog:', unficalllog)
168 print('cached value (unfiltered): ', 216 print(
169 vars(repo).get('testcachedunfifoobar', 'NOCACHE')) 217 'cached value (unfiltered): ',
170 print('cached value ("visible" view): ', 218 vars(repo).get('testcachedunfifoobar', 'NOCACHE'),
171 vars(visibleview).get('testcachedunfifoobar', 'NOCACHE')) 219 )
172 print('cached value ("immutable" view):', 220 print(
173 vars(immutableview).get('testcachedunfifoobar', 'NOCACHE')) 221 'cached value ("visible" view): ',
222 vars(visibleview).get('testcachedunfifoobar', 'NOCACHE'),
223 )
224 print(
225 'cached value ("immutable" view):',
226 vars(immutableview).get('testcachedunfifoobar', 'NOCACHE'),
227 )
174 print('access ("immutable" view):', immutableview.testcachedunfifoobar) 228 print('access ("immutable" view):', immutableview.testcachedunfifoobar)
175 print('unficalllog:', unficalllog) 229 print('unficalllog:', unficalllog)
176 print('cached value (unfiltered): ', 230 print(
177 vars(repo).get('testcachedunfifoobar', 'NOCACHE')) 231 'cached value (unfiltered): ',
178 print('cached value ("visible" view): ', 232 vars(repo).get('testcachedunfifoobar', 'NOCACHE'),
179 vars(visibleview).get('testcachedunfifoobar', 'NOCACHE')) 233 )
180 print('cached value ("immutable" view):', 234 print(
181 vars(immutableview).get('testcachedunfifoobar', 'NOCACHE')) 235 'cached value ("visible" view): ',
236 vars(visibleview).get('testcachedunfifoobar', 'NOCACHE'),
237 )
238 print(
239 'cached value ("immutable" view):',
240 vars(immutableview).get('testcachedunfifoobar', 'NOCACHE'),
241 )
182 print('access (unfiltered): ', repo.testcachedunfifoobar) 242 print('access (unfiltered): ', repo.testcachedunfifoobar)
183 print('unficalllog:', unficalllog) 243 print('unficalllog:', unficalllog)
184 print('cached value (unfiltered): ', 244 print(
185 vars(repo).get('testcachedunfifoobar', 'NOCACHE')) 245 'cached value (unfiltered): ',
186 print('cached value ("visible" view): ', 246 vars(repo).get('testcachedunfifoobar', 'NOCACHE'),
187 vars(visibleview).get('testcachedunfifoobar', 'NOCACHE')) 247 )
188 print('cached value ("immutable" view):', 248 print(
189 vars(immutableview).get('testcachedunfifoobar', 'NOCACHE')) 249 'cached value ("visible" view): ',
250 vars(visibleview).get('testcachedunfifoobar', 'NOCACHE'),
251 )
252 print(
253 'cached value ("immutable" view):',
254 vars(immutableview).get('testcachedunfifoobar', 'NOCACHE'),
255 )