##// END OF EJS Templates
tests: import mercurial modules by name in test-propertycache...
Yuya Nishihara -
r28839:de7802c3 default
parent child Browse files
Show More
@@ -1,180 +1,182 b''
1 """test behavior of propertycache and unfiltered propertycache
1 """test behavior of propertycache and unfiltered propertycache
2
2
3 The repoview overlay is quite complex. We test the behavior of
3 The repoview overlay is quite complex. We test the behavior of
4 property cache of both localrepo and repoview to prevent
4 property cache of both localrepo and repoview to prevent
5 regression."""
5 regression."""
6
6
7 from __future__ import absolute_import, print_function
7 from __future__ import absolute_import, print_function
8 import os
8 import os
9 import subprocess
9 import subprocess
10 import mercurial.localrepo
11 import mercurial.util
12 import mercurial.hg
13 import mercurial.ui as uimod
14
10
11 from mercurial import (
12 hg,
13 localrepo,
14 ui as uimod,
15 util,
16 )
15
17
16 # create some special property cache that trace they call
18 # create some special property cache that trace they call
17
19
18 calllog = []
20 calllog = []
19 @mercurial.util.propertycache
21 @util.propertycache
20 def testcachedfoobar(repo):
22 def testcachedfoobar(repo):
21 name = repo.filtername
23 name = repo.filtername
22 if name is None:
24 if name is None:
23 name = ''
25 name = ''
24 val = len(name)
26 val = len(name)
25 calllog.append(val)
27 calllog.append(val)
26 return val
28 return val
27
29
28 unficalllog = []
30 unficalllog = []
29 @mercurial.localrepo.unfilteredpropertycache
31 @localrepo.unfilteredpropertycache
30 def testcachedunfifoobar(repo):
32 def testcachedunfifoobar(repo):
31 name = repo.filtername
33 name = repo.filtername
32 if name is None:
34 if name is None:
33 name = ''
35 name = ''
34 val = 100 + len(name)
36 val = 100 + len(name)
35 unficalllog.append(val)
37 unficalllog.append(val)
36 return val
38 return val
37
39
38 #plug them on repo
40 #plug them on repo
39 mercurial.localrepo.localrepository.testcachedfoobar = testcachedfoobar
41 localrepo.localrepository.testcachedfoobar = testcachedfoobar
40 mercurial.localrepo.localrepository.testcachedunfifoobar = testcachedunfifoobar
42 localrepo.localrepository.testcachedunfifoobar = testcachedunfifoobar
41
43
42
44
43 # Create an empty repo and instantiate it. It is important to run
45 # Create an empty repo and instantiate it. It is important to run
44 # these tests on the real object to detect regression.
46 # these tests on the real object to detect regression.
45 repopath = os.path.join(os.environ['TESTTMP'], 'repo')
47 repopath = os.path.join(os.environ['TESTTMP'], 'repo')
46 assert subprocess.call(['hg', 'init', repopath]) == 0
48 assert subprocess.call(['hg', 'init', repopath]) == 0
47 ui = uimod.ui()
49 ui = uimod.ui()
48 repo = mercurial.hg.repository(ui, path=repopath).unfiltered()
50 repo = hg.repository(ui, path=repopath).unfiltered()
49
51
50
52
51 print('')
53 print('')
52 print('=== property cache ===')
54 print('=== property cache ===')
53 print('')
55 print('')
54 print('calllog:', calllog)
56 print('calllog:', calllog)
55 print('cached value (unfiltered):',
57 print('cached value (unfiltered):',
56 vars(repo).get('testcachedfoobar', 'NOCACHE'))
58 vars(repo).get('testcachedfoobar', 'NOCACHE'))
57
59
58 print('')
60 print('')
59 print('= first access on unfiltered, should do a call')
61 print('= first access on unfiltered, should do a call')
60 print('access:', repo.testcachedfoobar)
62 print('access:', repo.testcachedfoobar)
61 print('calllog:', calllog)
63 print('calllog:', calllog)
62 print('cached value (unfiltered):',
64 print('cached value (unfiltered):',
63 vars(repo).get('testcachedfoobar', 'NOCACHE'))
65 vars(repo).get('testcachedfoobar', 'NOCACHE'))
64
66
65 print('')
67 print('')
66 print('= second access on unfiltered, should not do call')
68 print('= second access on unfiltered, should not do call')
67 print('access', repo.testcachedfoobar)
69 print('access', repo.testcachedfoobar)
68 print('calllog:', calllog)
70 print('calllog:', calllog)
69 print('cached value (unfiltered):',
71 print('cached value (unfiltered):',
70 vars(repo).get('testcachedfoobar', 'NOCACHE'))
72 vars(repo).get('testcachedfoobar', 'NOCACHE'))
71
73
72 print('')
74 print('')
73 print('= first access on "visible" view, should do a call')
75 print('= first access on "visible" view, should do a call')
74 visibleview = repo.filtered('visible')
76 visibleview = repo.filtered('visible')
75 print('cached value ("visible" view):',
77 print('cached value ("visible" view):',
76 vars(visibleview).get('testcachedfoobar', 'NOCACHE'))
78 vars(visibleview).get('testcachedfoobar', 'NOCACHE'))
77 print('access:', visibleview.testcachedfoobar)
79 print('access:', visibleview.testcachedfoobar)
78 print('calllog:', calllog)
80 print('calllog:', calllog)
79 print('cached value (unfiltered):',
81 print('cached value (unfiltered):',
80 vars(repo).get('testcachedfoobar', 'NOCACHE'))
82 vars(repo).get('testcachedfoobar', 'NOCACHE'))
81 print('cached value ("visible" view):',
83 print('cached value ("visible" view):',
82 vars(visibleview).get('testcachedfoobar', 'NOCACHE'))
84 vars(visibleview).get('testcachedfoobar', 'NOCACHE'))
83
85
84 print('')
86 print('')
85 print('= second access on "visible view", should not do call')
87 print('= second access on "visible view", should not do call')
86 print('access:', visibleview.testcachedfoobar)
88 print('access:', visibleview.testcachedfoobar)
87 print('calllog:', calllog)
89 print('calllog:', calllog)
88 print('cached value (unfiltered):',
90 print('cached value (unfiltered):',
89 vars(repo).get('testcachedfoobar', 'NOCACHE'))
91 vars(repo).get('testcachedfoobar', 'NOCACHE'))
90 print('cached value ("visible" view):',
92 print('cached value ("visible" view):',
91 vars(visibleview).get('testcachedfoobar', 'NOCACHE'))
93 vars(visibleview).get('testcachedfoobar', 'NOCACHE'))
92
94
93 print('')
95 print('')
94 print('= no effect on other view')
96 print('= no effect on other view')
95 immutableview = repo.filtered('immutable')
97 immutableview = repo.filtered('immutable')
96 print('cached value ("immutable" view):',
98 print('cached value ("immutable" view):',
97 vars(immutableview).get('testcachedfoobar', 'NOCACHE'))
99 vars(immutableview).get('testcachedfoobar', 'NOCACHE'))
98 print('access:', immutableview.testcachedfoobar)
100 print('access:', immutableview.testcachedfoobar)
99 print('calllog:', calllog)
101 print('calllog:', calllog)
100 print('cached value (unfiltered):',
102 print('cached value (unfiltered):',
101 vars(repo).get('testcachedfoobar', 'NOCACHE'))
103 vars(repo).get('testcachedfoobar', 'NOCACHE'))
102 print('cached value ("visible" view):',
104 print('cached value ("visible" view):',
103 vars(visibleview).get('testcachedfoobar', 'NOCACHE'))
105 vars(visibleview).get('testcachedfoobar', 'NOCACHE'))
104 print('cached value ("immutable" view):',
106 print('cached value ("immutable" view):',
105 vars(immutableview).get('testcachedfoobar', 'NOCACHE'))
107 vars(immutableview).get('testcachedfoobar', 'NOCACHE'))
106
108
107 # unfiltered property cache test
109 # unfiltered property cache test
108 print('')
110 print('')
109 print('')
111 print('')
110 print('=== unfiltered property cache ===')
112 print('=== unfiltered property cache ===')
111 print('')
113 print('')
112 print('unficalllog:', unficalllog)
114 print('unficalllog:', unficalllog)
113 print('cached value (unfiltered): ',
115 print('cached value (unfiltered): ',
114 vars(repo).get('testcachedunfifoobar', 'NOCACHE'))
116 vars(repo).get('testcachedunfifoobar', 'NOCACHE'))
115 print('cached value ("visible" view): ',
117 print('cached value ("visible" view): ',
116 vars(visibleview).get('testcachedunfifoobar', 'NOCACHE'))
118 vars(visibleview).get('testcachedunfifoobar', 'NOCACHE'))
117 print('cached value ("immutable" view):',
119 print('cached value ("immutable" view):',
118 vars(immutableview).get('testcachedunfifoobar', 'NOCACHE'))
120 vars(immutableview).get('testcachedunfifoobar', 'NOCACHE'))
119
121
120 print('')
122 print('')
121 print('= first access on unfiltered, should do a call')
123 print('= first access on unfiltered, should do a call')
122 print('access (unfiltered):', repo.testcachedunfifoobar)
124 print('access (unfiltered):', repo.testcachedunfifoobar)
123 print('unficalllog:', unficalllog)
125 print('unficalllog:', unficalllog)
124 print('cached value (unfiltered): ',
126 print('cached value (unfiltered): ',
125 vars(repo).get('testcachedunfifoobar', 'NOCACHE'))
127 vars(repo).get('testcachedunfifoobar', 'NOCACHE'))
126
128
127 print('')
129 print('')
128 print('= second access on unfiltered, should not do call')
130 print('= second access on unfiltered, should not do call')
129 print('access (unfiltered):', repo.testcachedunfifoobar)
131 print('access (unfiltered):', repo.testcachedunfifoobar)
130 print('unficalllog:', unficalllog)
132 print('unficalllog:', unficalllog)
131 print('cached value (unfiltered): ',
133 print('cached value (unfiltered): ',
132 vars(repo).get('testcachedunfifoobar', 'NOCACHE'))
134 vars(repo).get('testcachedunfifoobar', 'NOCACHE'))
133
135
134 print('')
136 print('')
135 print('= access on view should use the unfiltered cache')
137 print('= access on view should use the unfiltered cache')
136 print('access (unfiltered): ', repo.testcachedunfifoobar)
138 print('access (unfiltered): ', repo.testcachedunfifoobar)
137 print('access ("visible" view): ', visibleview.testcachedunfifoobar)
139 print('access ("visible" view): ', visibleview.testcachedunfifoobar)
138 print('access ("immutable" view):', immutableview.testcachedunfifoobar)
140 print('access ("immutable" view):', immutableview.testcachedunfifoobar)
139 print('unficalllog:', unficalllog)
141 print('unficalllog:', unficalllog)
140 print('cached value (unfiltered): ',
142 print('cached value (unfiltered): ',
141 vars(repo).get('testcachedunfifoobar', 'NOCACHE'))
143 vars(repo).get('testcachedunfifoobar', 'NOCACHE'))
142 print('cached value ("visible" view): ',
144 print('cached value ("visible" view): ',
143 vars(visibleview).get('testcachedunfifoobar', 'NOCACHE'))
145 vars(visibleview).get('testcachedunfifoobar', 'NOCACHE'))
144 print('cached value ("immutable" view):',
146 print('cached value ("immutable" view):',
145 vars(immutableview).get('testcachedunfifoobar', 'NOCACHE'))
147 vars(immutableview).get('testcachedunfifoobar', 'NOCACHE'))
146
148
147 print('')
149 print('')
148 print('= even if we clear the unfiltered cache')
150 print('= even if we clear the unfiltered cache')
149 del repo.__dict__['testcachedunfifoobar']
151 del repo.__dict__['testcachedunfifoobar']
150 print('cached value (unfiltered): ',
152 print('cached value (unfiltered): ',
151 vars(repo).get('testcachedunfifoobar', 'NOCACHE'))
153 vars(repo).get('testcachedunfifoobar', 'NOCACHE'))
152 print('cached value ("visible" view): ',
154 print('cached value ("visible" view): ',
153 vars(visibleview).get('testcachedunfifoobar', 'NOCACHE'))
155 vars(visibleview).get('testcachedunfifoobar', 'NOCACHE'))
154 print('cached value ("immutable" view):',
156 print('cached value ("immutable" view):',
155 vars(immutableview).get('testcachedunfifoobar', 'NOCACHE'))
157 vars(immutableview).get('testcachedunfifoobar', 'NOCACHE'))
156 print('unficalllog:', unficalllog)
158 print('unficalllog:', unficalllog)
157 print('access ("visible" view): ', visibleview.testcachedunfifoobar)
159 print('access ("visible" view): ', visibleview.testcachedunfifoobar)
158 print('unficalllog:', unficalllog)
160 print('unficalllog:', unficalllog)
159 print('cached value (unfiltered): ',
161 print('cached value (unfiltered): ',
160 vars(repo).get('testcachedunfifoobar', 'NOCACHE'))
162 vars(repo).get('testcachedunfifoobar', 'NOCACHE'))
161 print('cached value ("visible" view): ',
163 print('cached value ("visible" view): ',
162 vars(visibleview).get('testcachedunfifoobar', 'NOCACHE'))
164 vars(visibleview).get('testcachedunfifoobar', 'NOCACHE'))
163 print('cached value ("immutable" view):',
165 print('cached value ("immutable" view):',
164 vars(immutableview).get('testcachedunfifoobar', 'NOCACHE'))
166 vars(immutableview).get('testcachedunfifoobar', 'NOCACHE'))
165 print('access ("immutable" view):', immutableview.testcachedunfifoobar)
167 print('access ("immutable" view):', immutableview.testcachedunfifoobar)
166 print('unficalllog:', unficalllog)
168 print('unficalllog:', unficalllog)
167 print('cached value (unfiltered): ',
169 print('cached value (unfiltered): ',
168 vars(repo).get('testcachedunfifoobar', 'NOCACHE'))
170 vars(repo).get('testcachedunfifoobar', 'NOCACHE'))
169 print('cached value ("visible" view): ',
171 print('cached value ("visible" view): ',
170 vars(visibleview).get('testcachedunfifoobar', 'NOCACHE'))
172 vars(visibleview).get('testcachedunfifoobar', 'NOCACHE'))
171 print('cached value ("immutable" view):',
173 print('cached value ("immutable" view):',
172 vars(immutableview).get('testcachedunfifoobar', 'NOCACHE'))
174 vars(immutableview).get('testcachedunfifoobar', 'NOCACHE'))
173 print('access (unfiltered): ', repo.testcachedunfifoobar)
175 print('access (unfiltered): ', repo.testcachedunfifoobar)
174 print('unficalllog:', unficalllog)
176 print('unficalllog:', unficalllog)
175 print('cached value (unfiltered): ',
177 print('cached value (unfiltered): ',
176 vars(repo).get('testcachedunfifoobar', 'NOCACHE'))
178 vars(repo).get('testcachedunfifoobar', 'NOCACHE'))
177 print('cached value ("visible" view): ',
179 print('cached value ("visible" view): ',
178 vars(visibleview).get('testcachedunfifoobar', 'NOCACHE'))
180 vars(visibleview).get('testcachedunfifoobar', 'NOCACHE'))
179 print('cached value ("immutable" view):',
181 print('cached value ("immutable" view):',
180 vars(immutableview).get('testcachedunfifoobar', 'NOCACHE'))
182 vars(immutableview).get('testcachedunfifoobar', 'NOCACHE'))
General Comments 0
You need to be logged in to leave comments. Login now