diff tests/test-propertycache.py @ 19846:9789670992d6 stable

repoview: have unfilteredpropertycache using the underlying cache A `unfilteredpropertycache` is a kind of `propertycache` used on `localrepo` to unsure it will always be run against unfiltered repo and stored only once. As the cached value is never stored in the repoview instance, the descriptor will always be called. Before this patch such calls always result in a call to the `__get__` method of the `propertycache` on the unfiltered repo. That was recomputing a new value on every access through a repoview. We can't prevent the repoview's `unfilteredpropertycache` to get called on every access. In that case the new code makes a standard attribute access to the property. If a value is cached it will be used. The `propertycache` test file have been augmented with test about this issue.
author Pierre-Yves David <pierre-yves.david@ens-lyon.org>
date Mon, 30 Sep 2013 14:23:14 +0200
parents a1237a4b437d
children 21de61bc2ab5
line wrap: on
line diff
--- a/tests/test-propertycache.py	Mon Sep 30 14:36:11 2013 +0200
+++ b/tests/test-propertycache.py	Mon Sep 30 14:23:14 2013 +0200
@@ -24,8 +24,19 @@
     calllog.append(val)
     return val
 
+unficalllog = []
+@mercurial.localrepo.unfilteredpropertycache
+def testcachedunfifoobar(repo):
+    name = repo.filtername
+    if name is None:
+        name = ''
+    val = 100 + len(name)
+    unficalllog.append(val)
+    return val
+
 #plug them on repo
 mercurial.localrepo.localrepository.testcachedfoobar = testcachedfoobar
+mercurial.localrepo.localrepository.testcachedunfifoobar = testcachedunfifoobar
 
 
 # create an empty repo. and instanciate it. It is important to run
@@ -92,3 +103,77 @@
 print 'cached value ("immutable" view):',
 print vars(immutableview).get('testcachedfoobar', 'NOCACHE')
 
+# unfiltered property cache test
+print ''
+print ''
+print '=== unfiltered property cache ==='
+print ''
+print 'unficalllog:', unficalllog
+print 'cached value (unfiltered):      ',
+print vars(repo).get('testcachedunfifoobar', 'NOCACHE')
+print 'cached value ("visible" view):  ',
+print vars(visibleview).get('testcachedunfifoobar', 'NOCACHE')
+print 'cached value ("immutable" view):',
+print vars(immutableview).get('testcachedunfifoobar', 'NOCACHE')
+
+print ''
+print '= first access on unfiltered, should do a call'
+print 'access (unfiltered):', repo.testcachedunfifoobar
+print 'unficalllog:', unficalllog
+print 'cached value (unfiltered):      ',
+print vars(repo).get('testcachedunfifoobar', 'NOCACHE')
+
+print ''
+print '= second access on unfiltered, should not do call'
+print 'access (unfiltered):', repo.testcachedunfifoobar
+print 'unficalllog:', unficalllog
+print 'cached value (unfiltered):      ',
+print vars(repo).get('testcachedunfifoobar', 'NOCACHE')
+
+print ''
+print '= access on view should use the unfiltered cache'
+print 'access (unfiltered):      ', repo.testcachedunfifoobar
+print 'access ("visible" view):  ', visibleview.testcachedunfifoobar
+print 'access ("immutable" view):', immutableview.testcachedunfifoobar
+print 'unficalllog:', unficalllog
+print 'cached value (unfiltered):      ',
+print vars(repo).get('testcachedunfifoobar', 'NOCACHE')
+print 'cached value ("visible" view):  ',
+print vars(visibleview).get('testcachedunfifoobar', 'NOCACHE')
+print 'cached value ("immutable" view):',
+print vars(immutableview).get('testcachedunfifoobar', 'NOCACHE')
+
+print ''
+print '= even if we clear the unfiltered cache'
+del repo.__dict__['testcachedunfifoobar']
+print 'cached value (unfiltered):      ',
+print vars(repo).get('testcachedunfifoobar', 'NOCACHE')
+print 'cached value ("visible" view):  ',
+print vars(visibleview).get('testcachedunfifoobar', 'NOCACHE')
+print 'cached value ("immutable" view):',
+print vars(immutableview).get('testcachedunfifoobar', 'NOCACHE')
+print 'unficalllog:', unficalllog
+print 'access ("visible" view):  ', visibleview.testcachedunfifoobar
+print 'unficalllog:', unficalllog
+print 'cached value (unfiltered):      ',
+print vars(repo).get('testcachedunfifoobar', 'NOCACHE')
+print 'cached value ("visible" view):  ',
+print vars(visibleview).get('testcachedunfifoobar', 'NOCACHE')
+print 'cached value ("immutable" view):',
+print vars(immutableview).get('testcachedunfifoobar', 'NOCACHE')
+print 'access ("immutable" view):', immutableview.testcachedunfifoobar
+print 'unficalllog:', unficalllog
+print 'cached value (unfiltered):      ',
+print vars(repo).get('testcachedunfifoobar', 'NOCACHE')
+print 'cached value ("visible" view):  ',
+print vars(visibleview).get('testcachedunfifoobar', 'NOCACHE')
+print 'cached value ("immutable" view):',
+print vars(immutableview).get('testcachedunfifoobar', 'NOCACHE')
+print 'access (unfiltered):      ', repo.testcachedunfifoobar
+print 'unficalllog:', unficalllog
+print 'cached value (unfiltered):      ',
+print vars(repo).get('testcachedunfifoobar', 'NOCACHE')
+print 'cached value ("visible" view):  ',
+print vars(visibleview).get('testcachedunfifoobar', 'NOCACHE')
+print 'cached value ("immutable" view):',
+print vars(immutableview).get('testcachedunfifoobar', 'NOCACHE')