Skip to content

Commit

Permalink
make doctest ReST to increase readability.
Browse files Browse the repository at this point in the history
  • Loading branch information
jensens committed Aug 10, 2020
1 parent 8482ee7 commit 71851c8
Show file tree
Hide file tree
Showing 2 changed files with 27 additions and 27 deletions.
52 changes: 26 additions & 26 deletions src/z3c/jbot/README.txt → src/z3c/jbot/README.rst
Original file line number Diff line number Diff line change
Expand Up @@ -4,7 +4,7 @@ z3c.jbot
The z3c.jbot (or "Just a bunch of templates") package allows drop-in
page template overrides.

It works with templates which are defined as an attribute on a view.
It works with templates which are defined as an attribute on a view::

>>> from zope.pagetemplate.pagetemplatefile import PageTemplateFile
>>> class View(object):
Expand All @@ -25,59 +25,59 @@ template override directories.

If we register the directory where it's placed with the global template
manager, it will be used when rendering this template object instead
of the original filename.
of the original filename::

>>> import z3c.jbot.tests
>>> directory = z3c.jbot.tests.__path__[0]

Register overrides directory (by default for any request); we confirm
that it's registered for the same template manager.
that it's registered for the same template manager::

>>> from z3c.jbot.metaconfigure import handler
>>> manager = handler("%s/overrides/interface" % directory, interface.Interface)

We make sure that the presence of an additional, trivial manager, does
not affect the result. We register the system temporary directory:
not affect the result. We register the system temporary directory::

>>> import tempfile
>>> handler(tempfile.tempdir, interface.Interface)
<z3c.jbot.manager.TemplateManager object at ...>

We should now see that the new filename will be used for rendering:
We should now see that the new filename will be used for rendering::

>>> view.template()
u'Override from ./interface.\n'

Before we proceed we'll clean up.
Before we proceed we'll clean up::

>>> manager.unregisterAllDirectories()

The template does indeed render the original template.
The template does indeed render the original template::

>>> view.template()
u'This is an example page template.\n'

Upon rendering, the global template manager will have reverted the
template filename to the original.
template filename to the original::

>>> view.template.filename
'.../z3c/jbot/tests/templates/example.pt'

Overrides can be registered for a specific layer. Let's register three
more overrides, one for the general-purpose ``IRequest`` layer, one
for the ``IHTTPRequest`` layer and one for a made-up ``IHTTPSRequest``
layer.
layer::

>>> from zope.publisher.interfaces import IRequest
>>> from zope.publisher.interfaces.http import IHTTPRequest
>>> class IHTTPSRequest(IRequest):
... """An HTTPS request."""

Next we register an overrides directory for the ``IRequest`` layer.
Next we register an overrides directory for the ``IRequest`` layer::

>>> general = handler("%s/overrides/request" % directory, IRequest)

Let's set up an interaction with a trivial participation.
Let's set up an interaction with a trivial participation::

>>> class Participation:
... interaction = None
Expand All @@ -86,17 +86,17 @@ Let's set up an interaction with a trivial participation.
>>> import zope.security.management
>>> zope.security.management.newInteraction(participation)

This participation does not provide even the basic request interface.
This participation does not provide even the basic request interface::

>>> IRequest.providedBy(participation)
False

We don't expect the template to be overriden for this interaction.
We don't expect the template to be overriden for this interaction::

>>> view.template()
u'This is an example page template.\n'

Let's upgrade it.
Let's upgrade it::

>>> request = participation
>>> interface.alsoProvides(request, IRequest)
Expand All @@ -107,13 +107,13 @@ Let's upgrade it.
>>> view.template._v_cooked
1

Going back to a basic request.
Going back to a basic request::

>>> interface.noLongerProvides(request, IRequest)
>>> view.template()
u'This is an example page template.\n'

Let's verify that we only cook once per template source.
Let's verify that we only cook once per template source::

>>> output = view.template()
>>> view.template._v_last_read and view.template._v_cooked
Expand All @@ -127,7 +127,7 @@ Let's verify that we only cook once per template source.
>>> view.template()
u'Override from ./request.\n'

Now, if we switch to the HTTP-layer.
Now, if we switch to the HTTP-layer::

>>> interface.noLongerProvides(request, IRequest)
>>> interface.alsoProvides(request, IHTTPRequest)
Expand All @@ -146,7 +146,7 @@ Now, if we switch to the HTTP-layer.
>>> view.template()
u'Override from ./http.\n'

Switching to HTTPS.
Switching to HTTPS::

>>> interface.noLongerProvides(request, IHTTPRequest)
>>> interface.alsoProvides(request, IHTTPSRequest)
Expand All @@ -156,15 +156,15 @@ Switching to HTTPS.

>>> interface.noLongerProvides(request, IHTTPSRequest)

Unregister all directories (cleanup).
Unregister all directories (cleanup)::

>>> for manager, layer in ((http, IHTTPRequest), (https, IHTTPSRequest)):
... interface.alsoProvides(request, layer)
... _ = view.template()
... manager.unregisterAllDirectories()
... interface.noLongerProvides(request, layer)

The override is no longer in effect.
The override is no longer in effect::

>>> view.template()
u'This is an example page template.\n'
Expand All @@ -179,35 +179,35 @@ to register template overrides directories in configuration files.
>>> from zope.configuration import xmlconfig
>>> xmlconfig.XMLConfig('meta.zcml', z3c.jbot)()

Let's try registering the directory again.
Let's try registering the directory again::

>>> xmlconfig.xmlconfig(StringIO("""
... <configure xmlns="http://namespaces.zope.org/browser">
... <jbot directory="%s/overrides/interface" />
... </configure>
... """ % directory))

Once again, the override will be in effect.
Once again, the override will be in effect::

>>> view.template()
u'Override from ./interface.\n'

Providing the HTTP-request layer does not change this.
Providing the HTTP-request layer does not change this::

>>> interface.alsoProvides(request, IHTTPRequest)

>>> view.template()
u'Override from ./interface.\n'

Unregister overrides.
Unregister overrides::

>>> for manager in z3c.jbot.utility.getManagers(IHTTPRequest):
... manager.unregisterAllDirectories()

>>> view.template()
u'This is an example page template.\n'

Let's register overrides for the HTTP-request layer.
Let's register overrides for the HTTP-request layer::

>>> xmlconfig.xmlconfig(StringIO("""
... <configure xmlns="http://namespaces.zope.org/browser">
Expand All @@ -217,7 +217,7 @@ Let's register overrides for the HTTP-request layer.
... </configure>
... """ % directory))

Since we now provide the HTTP-request layer, the override is used.
Since we now provide the HTTP-request layer, the override is used::

>>> view.template()
u'Override from ./http.\n'
2 changes: 1 addition & 1 deletion src/z3c/jbot/tests/test_doctests.py
Original file line number Diff line number Diff line change
Expand Up @@ -40,7 +40,7 @@ def test_suite():

return unittest.TestSuite((
doctest.DocFileSuite(
'README.txt',
'README.rst',
optionflags=OPTIONFLAGS,
setUp=setUp,
tearDown=tearDown,
Expand Down

0 comments on commit 71851c8

Please sign in to comment.