Commit
This commit does not belong to any branch on this repository, and may belong to a fork outside of the repository.
Backport grok_component() in doctest fix to Grok 0.11 branch.
- Loading branch information
Showing
4 changed files
with
53 additions
and
1 deletion.
There are no files selected for viewing
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,41 @@ | ||
Test grok_component() in an ordinary doctest. | ||
|
||
We already have tests for grok_component(), but these were placed | ||
inside a module. We will now test grok_component() in a pure doctest | ||
context. This used to demonstrate an error in martian when dealing | ||
with the __builtin__ module (fixed in martian 0.9.2). | ||
|
||
grok.testing.grok_component() can be used to grok individual | ||
components within a doctest, such as adapters. It sets up just enough | ||
context for some grokking to work, though more complicated grokkers | ||
which need module context (such as view grokkers) might not work. | ||
|
||
This defines the object we want to provide an adapter for:: | ||
|
||
>>> class Bar(object): | ||
... pass | ||
|
||
This is the interface that we want to adapt to:: | ||
|
||
>>> from zope.interface import Interface | ||
>>> class IFoo(Interface): | ||
... pass | ||
|
||
This is the adapter itself:: | ||
|
||
>>> import grok | ||
>>> class MyAdapter(grok.Adapter): | ||
... grok.provides(IFoo) | ||
... grok.context(Bar) | ||
|
||
Now we will register the adapter using grok_component():: | ||
|
||
>>> from grok.testing import grok_component | ||
>>> grok_component('MyAdapter', MyAdapter) | ||
True | ||
|
||
The adapter should now be available:: | ||
|
||
>>> adapted = IFoo(Bar()) | ||
>>> isinstance(adapted, MyAdapter) | ||
True |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters