Skip to content

HTTPS clone URL

Subversion checkout URL

You can clone with HTTPS or Subversion.

Download ZIP
Browse files

test volatile invalidate on child factory using node

  • Loading branch information...
commit d05f4e52721bf05e85a791319f831eae36772b36 1 parent 97ee741
@rnixx rnixx authored
View
2  README.rst
@@ -256,7 +256,7 @@ Summary of the test coverage report::
11 100% node.behaviors.__init__
107 100% node.behaviors.alias
38 100% node.behaviors.attributes
- 60 100% node.behaviors.cache
+ 65 100% node.behaviors.cache
118 100% node.behaviors.common
49 100% node.behaviors.lifecycle
114 100% node.behaviors.mapping
View
12 src/node/behaviors/cache.py
@@ -26,7 +26,6 @@ def invalidate(self, key=None):
if key is not None:
del self[key]
else:
- # need to use keys instead of iter here
for key in self.keys():
del self[key]
@@ -43,10 +42,15 @@ def invalidate(self, key=None):
"""
storage = self.storage
if key is not None:
- del storage[key]
+ if key in self.keys():
+ try:
+ del storage[key]
+ except KeyError, e:
+ pass # ignore, key is valid, but not on storage right now
+ else:
+ raise KeyError(key)
else:
- # need to use keys instead of iter here
- for key in self.keys():
+ for key in storage.keys():
del storage[key]
View
42 src/node/behaviors/cache.rst
@@ -16,6 +16,7 @@ Required Imports::
... DefaultInit,
... Nodify,
... OdictStorage,
+ ... ChildFactory,
... )
@@ -136,6 +137,47 @@ Active invalidation of all children::
<class 'Node'>: None
<class 'Node'>: c2
+Check for ChildFactory Node::
+
+ >>> class Node(object):
+ ... __metaclass__ = plumber
+ ... __plumbing__ = (
+ ... Adopt,
+ ... VolatileStorageInvalidate,
+ ... DefaultInit,
+ ... Nodify,
+ ... ChildFactory,
+ ... OdictStorage,
+ ... )
+ ... factories = {
+ ... 'foo': Node,
+ ... 'bar': Node,
+ ... }
+ >>> node = Node()
+ >>> node.items()
+ [('foo', <Node object 'foo' at ...>),
+ ('bar', <Node object 'bar' at ...>)]
+
+ >>> node.invalidate('foo')
+ >>> node.keys()
+ ['foo', 'bar']
+
+ >>> node.storage.items()
+ [('bar', <Node object 'bar' at ...>)]
+
+ >>> node.invalidate('foo')
+ >>> node.storage.items()
+ [('bar', <Node object 'bar' at ...>)]
+
+ >>> node.invalidate()
+ >>> node.storage.items()
+ []
+
+ >>> node.invalidate('baz')
+ Traceback (most recent call last):
+ ...
+ KeyError: 'baz'
+
Caching
-------
Please sign in to comment.
Something went wrong with that request. Please try again.