Show More
@@ -0,0 +1,94 b'' | |||||
|
1 | """test behavior of propertycache and unfiltered propertycache | |||
|
2 | ||||
|
3 | The repoview overlay is quite complexe. We test the behavior of | |||
|
4 | property cache of both localrepo and repoview to prevent | |||
|
5 | regression.""" | |||
|
6 | ||||
|
7 | import os, subprocess | |||
|
8 | import mercurial.localrepo | |||
|
9 | import mercurial.repoview | |||
|
10 | import mercurial.util | |||
|
11 | import mercurial.hg | |||
|
12 | import mercurial.ui as uimod | |||
|
13 | ||||
|
14 | ||||
|
15 | # create some special property cache that trace they call | |||
|
16 | ||||
|
17 | calllog = [] | |||
|
18 | @mercurial.util.propertycache | |||
|
19 | def testcachedfoobar(repo): | |||
|
20 | name = repo.filtername | |||
|
21 | if name is None: | |||
|
22 | name = '' | |||
|
23 | val = len(name) | |||
|
24 | calllog.append(val) | |||
|
25 | return val | |||
|
26 | ||||
|
27 | #plug them on repo | |||
|
28 | mercurial.localrepo.localrepository.testcachedfoobar = testcachedfoobar | |||
|
29 | ||||
|
30 | ||||
|
31 | # create an empty repo. and instanciate it. It is important to run | |||
|
32 | # those test on the real object to detect regression. | |||
|
33 | repopath = os.path.join(os.environ['TESTTMP'], 'repo') | |||
|
34 | subprocess.check_call(['hg', 'init', repopath]) | |||
|
35 | ui = uimod.ui() | |||
|
36 | repo = mercurial.hg.repository(ui, path=repopath).unfiltered() | |||
|
37 | ||||
|
38 | ||||
|
39 | print '' | |||
|
40 | print '=== property cache ===' | |||
|
41 | print '' | |||
|
42 | print 'calllog:', calllog | |||
|
43 | print 'cached value (unfiltered):', | |||
|
44 | print vars(repo).get('testcachedfoobar', 'NOCACHE') | |||
|
45 | ||||
|
46 | print '' | |||
|
47 | print '= first access on unfiltered, should do a call' | |||
|
48 | print 'access:', repo.testcachedfoobar | |||
|
49 | print 'calllog:', calllog | |||
|
50 | print 'cached value (unfiltered):', | |||
|
51 | print vars(repo).get('testcachedfoobar', 'NOCACHE') | |||
|
52 | ||||
|
53 | print '' | |||
|
54 | print '= second access on unfiltered, should not do call' | |||
|
55 | print 'access', repo.testcachedfoobar | |||
|
56 | print 'calllog:', calllog | |||
|
57 | print 'cached value (unfiltered):', | |||
|
58 | print vars(repo).get('testcachedfoobar', 'NOCACHE') | |||
|
59 | ||||
|
60 | print '' | |||
|
61 | print '= first access on "visible" view, should do a call' | |||
|
62 | visibleview = repo.filtered('visible') | |||
|
63 | print 'cached value ("visible" view):', | |||
|
64 | print vars(visibleview).get('testcachedfoobar', 'NOCACHE') | |||
|
65 | print 'access:', visibleview.testcachedfoobar | |||
|
66 | print 'calllog:', calllog | |||
|
67 | print 'cached value (unfiltered):', | |||
|
68 | print vars(repo).get('testcachedfoobar', 'NOCACHE') | |||
|
69 | print 'cached value ("visible" view):', | |||
|
70 | print vars(visibleview).get('testcachedfoobar', 'NOCACHE') | |||
|
71 | ||||
|
72 | print '' | |||
|
73 | print '= second access on "visible view", should not do call' | |||
|
74 | print 'access:', visibleview.testcachedfoobar | |||
|
75 | print 'calllog:', calllog | |||
|
76 | print 'cached value (unfiltered):', | |||
|
77 | print vars(repo).get('testcachedfoobar', 'NOCACHE') | |||
|
78 | print 'cached value ("visible" view):', | |||
|
79 | print vars(visibleview).get('testcachedfoobar', 'NOCACHE') | |||
|
80 | ||||
|
81 | print '' | |||
|
82 | print '= no effect on other view' | |||
|
83 | immutableview = repo.filtered('immutable') | |||
|
84 | print 'cached value ("immutable" view):', | |||
|
85 | print vars(immutableview).get('testcachedfoobar', 'NOCACHE') | |||
|
86 | print 'access:', immutableview.testcachedfoobar | |||
|
87 | print 'calllog:', calllog | |||
|
88 | print 'cached value (unfiltered):', | |||
|
89 | print vars(repo).get('testcachedfoobar', 'NOCACHE') | |||
|
90 | print 'cached value ("visible" view):', | |||
|
91 | print vars(visibleview).get('testcachedfoobar', 'NOCACHE') | |||
|
92 | print 'cached value ("immutable" view):', | |||
|
93 | print vars(immutableview).get('testcachedfoobar', 'NOCACHE') | |||
|
94 |
@@ -0,0 +1,36 b'' | |||||
|
1 | ||||
|
2 | === property cache === | |||
|
3 | ||||
|
4 | calllog: [] | |||
|
5 | cached value (unfiltered): NOCACHE | |||
|
6 | ||||
|
7 | = first access on unfiltered, should do a call | |||
|
8 | access: 0 | |||
|
9 | calllog: [0] | |||
|
10 | cached value (unfiltered): 0 | |||
|
11 | ||||
|
12 | = second access on unfiltered, should not do call | |||
|
13 | access 0 | |||
|
14 | calllog: [0] | |||
|
15 | cached value (unfiltered): 0 | |||
|
16 | ||||
|
17 | = first access on "visible" view, should do a call | |||
|
18 | cached value ("visible" view): NOCACHE | |||
|
19 | access: 7 | |||
|
20 | calllog: [0, 7] | |||
|
21 | cached value (unfiltered): 0 | |||
|
22 | cached value ("visible" view): 7 | |||
|
23 | ||||
|
24 | = second access on "visible view", should not do call | |||
|
25 | access: 7 | |||
|
26 | calllog: [0, 7] | |||
|
27 | cached value (unfiltered): 0 | |||
|
28 | cached value ("visible" view): 7 | |||
|
29 | ||||
|
30 | = no effect on other view | |||
|
31 | cached value ("immutable" view): NOCACHE | |||
|
32 | access: 9 | |||
|
33 | calllog: [0, 7, 9] | |||
|
34 | cached value (unfiltered): 0 | |||
|
35 | cached value ("visible" view): 7 | |||
|
36 | cached value ("immutable" view): 9 |
@@ -279,7 +279,8 b' class propertycache(object):' | |||||
279 | return result |
|
279 | return result | |
280 |
|
280 | |||
281 | def cachevalue(self, obj, value): |
|
281 | def cachevalue(self, obj, value): | |
282 | setattr(obj, self.name, value) |
|
282 | # __dict__ assigment required to bypass __setattr__ (eg: repoview) | |
|
283 | obj.__dict__[self.name] = value | |||
283 |
|
284 | |||
284 | def pipefilter(s, cmd): |
|
285 | def pipefilter(s, cmd): | |
285 | '''filter string S through command CMD, returning its output''' |
|
286 | '''filter string S through command CMD, returning its output''' |
General Comments 0
You need to be logged in to leave comments.
Login now