[Checkins]
SVN: martian/branches/jw-philipp-using-ndir-directives/src/martian/directive.
Fix bug where MULTIPLE and DICT store didn't work for module
Jan-Wijbrand Kolman
janwijbrand at gmail.com
Sat May 3 14:41:28 EDT 2008
Log message for revision 86264:
Fix bug where MULTIPLE and DICT store didn't work for module
level directives.
Changed:
U martian/branches/jw-philipp-using-ndir-directives/src/martian/directive.py
U martian/branches/jw-philipp-using-ndir-directives/src/martian/directive.txt
-=-
Modified: martian/branches/jw-philipp-using-ndir-directives/src/martian/directive.py
===================================================================
--- martian/branches/jw-philipp-using-ndir-directives/src/martian/directive.py 2008-05-03 18:40:03 UTC (rev 86263)
+++ martian/branches/jw-philipp-using-ndir-directives/src/martian/directive.py 2008-05-03 18:41:27 UTC (rev 86264)
@@ -34,6 +34,9 @@
if getattr(component, directive.dotted_name(), default) is default:
return default
+ if getattr(component, 'mro', None) is None:
+ return getattr(component, directive.dotted_name())
+
result = []
for base in reversed(component.mro()):
list = getattr(base, directive.dotted_name(), default)
@@ -57,6 +60,9 @@
if getattr(component, directive.dotted_name(), default) is default:
return default
+ if getattr(component, 'mro', None) is None:
+ return getattr(component, directive.dotted_name())
+
result = {}
for base in reversed(component.mro()):
mapping = getattr(base, directive.dotted_name(), default)
Modified: martian/branches/jw-philipp-using-ndir-directives/src/martian/directive.txt
===================================================================
--- martian/branches/jw-philipp-using-ndir-directives/src/martian/directive.txt 2008-05-03 18:40:03 UTC (rev 86263)
+++ martian/branches/jw-philipp-using-ndir-directives/src/martian/directive.txt 2008-05-03 18:41:27 UTC (rev 86264)
@@ -195,7 +195,7 @@
[]
Whenever the directive is used on a sub class of a component, the values set by
-directives on the base classes are concatenated::
+directives on the base classes are combined::
>>> class Qux(Foo):
... multi(u'Triple')
@@ -258,6 +258,9 @@
GrokImportError: The factory method for the 'wrongmulti2' directive should
return a key-value pair.
+Like with MULTIPLE store, values set by directives using the DICT store are
+combined::
+
>>> class multi(Directive):
... scope = CLASS
... store = DICT
@@ -277,6 +280,43 @@
>>> print sorted(d.items())
[(1, 'CCC'), (2, 'BBB'), (3, 'DDD'), (4, 'EEE')]
+Using MULTIPLE and DICT can also work on a module level, even though
+inheritance has no meaning there::
+
+ >>> from martian import MODULE
+ >>> class multi(MultipleTimesDirective):
+ ... scope = MODULE
+ ...
+ >>> multi.__module__ = 'somethingelse'
+ >>> class module_with_directive(FakeModule):
+ ... fake_module = True
+ ...
+ ... multi('One')
+ ... multi('Two')
+ ...
+ >>> module_with_directive = fake_import(module_with_directive)
+ >>> print multi.get(module_with_directive)
+ ['One', 'Two']
+
+ >>> from martian import MODULE
+ >>> class multi(Directive):
+ ... scope = MODULE
+ ... store = DICT
+ ... def factory(self, value, andanother):
+ ... return value, andanother
+ ...
+ >>> multi.__module__ = 'somethingelse'
+ >>> class module_with_directive(FakeModule):
+ ... fake_module = True
+ ...
+ ... multi(1, 'One')
+ ... multi(2, 'Two')
+ ...
+ >>> module_with_directive = fake_import(module_with_directive)
+ >>> d = multi.get(module_with_directive)
+ >>> print sorted(d.items())
+ [(1, 'One'), (2, 'Two')]
+
Calculated defaults
-------------------
More information about the Checkins
mailing list