-
Notifications
You must be signed in to change notification settings - Fork 4
Commit
This commit does not belong to any branch on this repository, and may belong to a fork outside of the repository.
Added application from Grok. Changed the tests and imports.
Removed the use of WrongType.
- Loading branch information
Showing
13 changed files
with
241 additions
and
19 deletions.
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
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
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 @@ | ||
# this is a package |
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,52 @@ | ||
""" | ||
An application is a mixin for grok application objects. | ||
You can get the current application by using the | ||
grok.getApplication() function. Typically this will return the same | ||
object as grok.getSite(), but it is possible to have sub-Site objects | ||
which will be returned for grok.getSite(), where-as grok.getApplication | ||
will walk up the tree until it reaches the top-level site object. | ||
Let's create an application, then get it using grok.getApplication(): | ||
>>> import grokcore.site | ||
>>> import zope.site.hooks | ||
>>> root = getRootFolder() | ||
>>> app = grokcore.site.util.create_application(Cave, root, 'mycave') | ||
>>> root['cave'] = app | ||
>>> zope.site.hooks.setSite(app) | ||
>>> grokcore.site.getApplication() | ||
<grokcore.site.ftests.application.application.Cave object at ...> | ||
Or get it using getSite(): | ||
>>> from zope.component.hooks import getSite | ||
>>> getSite() | ||
<grokcore.site.ftests.application.application.Cave object at ...> | ||
Now we can create a container with a sub-site. When we call grok.getSite() | ||
we'll get the box: | ||
>>> root['cave']['box'] = WoodBox() | ||
>>> zope.site.hooks.setSite(root['cave']['box']) | ||
>>> getSite() | ||
<grokcore.site.ftests.application.application.WoodBox object at ...> | ||
But when we call grokcore.site.util.getApplication() we get the cave: | ||
>>> grokcore.site.getApplication() | ||
<grokcore.site.ftests.application.application.Cave object at ...> | ||
""" | ||
import grokcore.content | ||
import grokcore.site | ||
|
||
|
||
class Cave(grokcore.content.Container, grokcore.site.Application): | ||
"""A shelter for homeless cavemen. | ||
""" | ||
|
||
|
||
class WoodBox(grokcore.content.Container, grokcore.site.Site): | ||
"""A prehistoric container for holding ZCA registries. | ||
""" |
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
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 @@ | ||
# this is a package |
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,37 @@ | ||
""" | ||
After grokking a module that defines an application, the application factory is | ||
available as a utility:: | ||
>>> from grokcore.site import testing | ||
>>> testing.grok(__name__) | ||
>>> import zope.component | ||
>>> import grokcore.site.interfaces | ||
>>> calendar_app = zope.component.getUtility( | ||
... grokcore.site.interfaces.IApplication, | ||
... name='grokcore.site.tests.application.application.Calendar') | ||
>>> calendar_app | ||
<class 'grokcore.site.tests.application.application.Calendar'> | ||
Applications are both containers and sites:: | ||
>>> issubclass(calendar_app, grokcore.site.Site) | ||
True | ||
Applications can be instanciated without any arguments:: | ||
>>> calendar = calendar_app() | ||
>>> calendar | ||
<grokcore.site.tests.application.application.Calendar object at 0x...> | ||
""" | ||
|
||
import grokcore.site | ||
|
||
|
||
class Calendar(grokcore.site.Application): | ||
"""A calendar application that knows about ancient | ||
calendar systems from the stone age. | ||
""" |
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,50 @@ | ||
import re | ||
import unittest | ||
from pkg_resources import resource_listdir | ||
from zope.testing import doctest, cleanup, renormalizing | ||
import zope.component.eventtesting | ||
|
||
def setUpZope(test): | ||
zope.component.eventtesting.setUp(test) | ||
|
||
def cleanUpZope(test): | ||
cleanup.cleanUp() | ||
|
||
checker = renormalizing.RENormalizing([ | ||
# str(Exception) has changed from Python 2.4 to 2.5 (due to | ||
# Exception now being a new-style class). This changes the way | ||
# exceptions appear in traceback printouts. | ||
(re.compile(r"ConfigurationExecutionError: <class '([\w.]+)'>:"), | ||
r'ConfigurationExecutionError: \1:'), | ||
]) | ||
|
||
def suiteFromPackage(name): | ||
files = resource_listdir(__name__, name) | ||
suite = unittest.TestSuite() | ||
for filename in files: | ||
if not filename.endswith('.py'): | ||
continue | ||
if filename.endswith('_fixture.py'): | ||
continue | ||
if filename == '__init__.py': | ||
continue | ||
|
||
dottedname = 'grokcore.site.tests.%s.%s' % (name, filename[:-3]) | ||
test = doctest.DocTestSuite(dottedname, | ||
setUp=setUpZope, | ||
tearDown=cleanUpZope, | ||
checker=checker, | ||
optionflags=doctest.ELLIPSIS+ | ||
doctest.NORMALIZE_WHITESPACE) | ||
|
||
suite.addTest(test) | ||
return suite | ||
|
||
def test_suite(): | ||
suite = unittest.TestSuite() | ||
for name in ['utility', 'application']: | ||
suite.addTest(suiteFromPackage(name)) | ||
return suite | ||
|
||
if __name__ == '__main__': | ||
unittest.main(defaultTest='test_suite') |
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