Skip to content

Commit

Permalink
Turn print statements in doctests into function calls.
Browse files Browse the repository at this point in the history
  • Loading branch information
hannosch committed May 13, 2017
1 parent 7db08c5 commit 5671856
Show file tree
Hide file tree
Showing 14 changed files with 116 additions and 114 deletions.
6 changes: 4 additions & 2 deletions src/OFS/tests/event.txt
Expand Up @@ -59,15 +59,17 @@ printed events will be in their "natural" order::
>>> from OFS.interfaces import IObjectClonedEvent
>>> from OFS.interfaces import IObjectWillBeMovedEvent
>>> def printObjectEvent(object, event):
... print event.__class__.__name__, object.getId()
... print(event.__class__.__name__)
... print(object.getId())
>>> def printObjectEventExceptSome(object, event):
... if (IObjectMovedEvent.providedBy(event) or
... IObjectCopiedEvent.providedBy(event) or
... IObjectWillBeMovedEvent.providedBy(event) or
... IObjectClonedEvent.providedBy(event) or
... IRegistrationEvent.providedBy(event)):
... return
... print event.__class__.__name__, object.getId()
... print(event.__class__.__name__)
... print(object.getId())

>>> from zope.component import provideHandler
>>> provideHandler(printObjectEvent, (IItem, IObjectMovedEvent))
Expand Down
18 changes: 9 additions & 9 deletions src/Products/Five/browser/tests/pages.txt
Expand Up @@ -103,7 +103,7 @@ ZPT-based browser pages
Test access to ``context`` from ZPTs:

>>> view = self.folder.unrestrictedTraverse('testoid/flamingo.html')
>>> print view()
>>> print(view())
<p>Hello world</p>
<p>Hello world</p>

Expand All @@ -116,7 +116,7 @@ Test macro access from ZPT pages:
test_zpt_things:

>>> view = self.folder.unrestrictedTraverse('testoid/condor.html')
>>> print view()
>>> print(view())
<p>Hello world</p>
<p>The eagle has landed</p>
<p>Hello world</p>
Expand All @@ -125,7 +125,7 @@ test_zpt_things:
Make sure that tal:repeat works in ZPT browser pages:

>>> view = self.folder.unrestrictedTraverse('testoid/ostrich.html')
>>> print view()
>>> print(view())
<ul>
<li>Alpha</li>
<li>Beta</li>
Expand All @@ -140,14 +140,14 @@ Make sure that tal:repeat works in ZPT browser pages:
Test TALES traversal in ZPT pages:

>>> view = self.folder.unrestrictedTraverse('testoid/tales_traversal.html')
>>> print view()
>>> print(view())
<p>testoid</p>
<p>test_folder_1_</p>

Make sure that global template variables in ZPT pages are correct:

>>> view = self.folder.unrestrictedTraverse('testoid/template_variables.html')
>>> print view()
>>> print(view())
View is a view: True
Context is testoid: True
Context.__parent__ is test_folder_1_: True
Expand All @@ -174,21 +174,21 @@ of course:
>>> allow_module('smtpd')
>>> self.logout()
>>> view = self.folder.unrestrictedTraverse('testoid/security.html')
>>> print view()
>>> print(view())
<div>NoneType</div>
<div>smtpd</div>
>>> self.login('manager')

Test pages registered through the <five:pagesFromDirectory /> directive:

>>> view = self.folder.unrestrictedTraverse('testoid/dirpage1')
>>> print view()
>>> print(view())
<html>
<p>This is page 1</p>
</html>

>>> view = self.folder.unrestrictedTraverse('testoid/dirpage2')
>>> print view()
>>> print(view())
<html>
<p>This is page 2</p>
</html>
Expand Down Expand Up @@ -315,7 +315,7 @@ Test traversal to resources from within ZPT pages:

>>> zcml.load_config('resource.zcml', package=Products.Five.browser.tests)
>>> view = self.folder.unrestrictedTraverse('testoid/parakeet.html')
>>> print view()
>>> print(view())
<html><body><img alt=""
src="http://nohost/test_folder_1_/testoid/++resource++pattern.png" /></body></html>

Expand Down
20 changes: 10 additions & 10 deletions src/Products/Five/browser/tests/pages_ftest.txt
Expand Up @@ -26,23 +26,23 @@ still published through ZPublisher.
We see that even though the callables have no docstring, they are
published nevertheless:

>>> print http(r"""
>>> print(http(r"""
... GET /test_folder_1_/testoid/nodoc-function HTTP/1.1
... """)
... """))
HTTP/1.1 200 OK
...
No docstring

>>> print http(r"""
>>> print(http(r"""
... GET /test_folder_1_/testoid/nodoc-method HTTP/1.1
... """)
... """))
HTTP/1.1 200 OK
...
No docstring

>>> print http(r"""
>>> print(http(r"""
... GET /test_folder_1_/testoid/nodoc-object HTTP/1.1
... """)
... """))
HTTP/1.1 200 OK
...
No docstring
Expand Down Expand Up @@ -137,18 +137,18 @@ Zope 2 always wants objects in the traversal graph to have a __name__.
That is also true for views, e.g. a view constructed from a simple
class bearing only a __call__ method:

>>> print http(r'''
>>> print(http(r'''
... GET /test_folder_1_/testoid/callview.html HTTP/1.1
... ''')
... '''))
HTTP/1.1 200 OK
...
I was __call__()'ed

or a __call__ object that's callable, such as a ViewPageTemplateFile:

>>> print http(r'''
>>> print(http(r'''
... GET /test_folder_1_/testoid/calltemplate.html HTTP/1.1
... ''')
... '''))
HTTP/1.1 200 OK
...
<p>The falcon has taken flight</p>
Expand Down
20 changes: 10 additions & 10 deletions src/Products/Five/browser/tests/provider.txt
Expand Up @@ -79,9 +79,9 @@ uses the name to look up the provider at run time.

Finally we publish the view:

>>> print http(r'''
>>> print(http(r'''
... GET /test_folder_1_/content_obj/main.html HTTP/1.1
... ''')
... '''))
HTTP/1.1 200 OK
...
<html>
Expand All @@ -99,9 +99,9 @@ Finally we publish the view:
Failure to lookup a Content Provider
~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~

>>> print http(r'''
>>> print(http(r'''
... GET /test_folder_1_/content_obj/error.html HTTP/1.1
... ''', handle_errors=False)
... ''', handle_errors=False))
Traceback (most recent call last):
...
ContentProviderLookupError: ...mypage.UnknownName...
Expand Down Expand Up @@ -133,9 +133,9 @@ Now the message box can receive its text from the TAL environment:

Now we should get two message boxes with different text:

>>> print http(r'''
>>> print(http(r'''
... GET /test_folder_1_/content_obj/namespace.html HTTP/1.1
... ''')
... '''))
HTTP/1.1 200 OK
...
<html>
Expand Down Expand Up @@ -173,9 +173,9 @@ information is used:
... BetterDynamicMessageBox, provides=interfaces.IContentProvider,
... name='mypage.MessageBox')

>>> print http(r'''
>>> print(http(r'''
... GET /test_folder_1_/content_obj/namespace2.html HTTP/1.1
... ''')
... '''))
HTTP/1.1 200 OK
...
<html>
Expand Down Expand Up @@ -218,9 +218,9 @@ Now we test a provider using a PageTemplateFile to render itself:
... my_property = 'A string for you'

>>> zope.component.provideAdapter(TemplateProvider, name='mypage.TemplateProvider', provides=interfaces.IContentProvider)
>>> print http(r'''
>>> print(http(r'''
... GET /test_folder_1_/content_obj/template_based.html HTTP/1.1
... ''')
... '''))
HTTP/1.1 200 OK
...
A simple template: A string for you
Expand Down
40 changes: 20 additions & 20 deletions src/Products/Five/browser/tests/resource_ftest.txt
Expand Up @@ -26,57 +26,57 @@ Set up the test fixtures:
Image resource
~~~~~~~~~~~~~~

>>> print http(r'''
>>> print(http(r'''
... GET /test_folder_1_/testoid/++resource++pattern.png HTTP/1.1
... Authorization: Basic manager:r00t
... ''')
... '''))
HTTP/1.1 200 OK
...

Image resources can't be traversed further:

>>> print http(r'''
>>> print(http(r'''
... GET /test_folder_1_/testoid/++resource++pattern.png/more HTTP/1.1
... Authorization: Basic manager:r00t
... ''')
... '''))
HTTP/1.1 404 Not Found
...

File resource
~~~~~~~~~~~~~

>>> print http(r'''
>>> print(http(r'''
... GET /test_folder_1_/testoid/++resource++style.css HTTP/1.1
... Authorization: Basic manager:r00t
... ''')
... '''))
HTTP/1.1 200 OK
...

File resources can't be traversed further:

>>> print http(r'''
>>> print(http(r'''
... GET /test_folder_1_/testoid/++resource++style.css/more HTTP/1.1
... Authorization: Basic manager:r00t
... ''')
... '''))
HTTP/1.1 404 Not Found
...

Template resource
~~~~~~~~~~~~~~~~~

>>> print http(r'''
>>> print(http(r'''
... GET /test_folder_1_/testoid/++resource++cockatiel.html HTTP/1.1
... Authorization: Basic manager:r00t
... ''')
... '''))
HTTP/1.1 200 OK
...

Template resources can't be traversed further:

>>> print http(r'''
>>> print(http(r'''
... GET /test_folder_1_/testoid/++resource++cockatiel.html/more HTTP/1.1
... Authorization: Basic manager:r00t
... ''')
... '''))
HTTP/1.1 404 Not Found
...

Expand All @@ -92,10 +92,10 @@ Page templates aren't guaranteed to render, so exclude them from the test:
... response = self.publish(base_url % r, basic='manager:r00t')
... self.assertEquals(200, response.getStatus())

>>> print http(r'''
>>> print(http(r'''
... GET /test_folder_1_/testoid/++resource++fivetest_resources/resource_subdir/resource.htm HTTP/1.1
... Authorization: Basic manager:r00t
... ''')
... '''))
HTTP/1.1 200 OK
...
<html>
Expand All @@ -110,19 +110,19 @@ Page templates aren't guaranteed to render, so exclude them from the test:

We also can traverse into sub-directories:

>>> print http(r'''
>>> print(http(r'''
... GET /test_folder_1_/testoid/++resource++fivetest_resources/resource_subdir/resource.txt HTTP/1.1
... Authorization: Basic manager:r00t
... ''')
... '''))
HTTP/1.1 200 OK
...
This is a resource in a subdirectory of a normal resource to test traversal.
<BLANKLINE>

>>> print http(r'''
>>> print(http(r'''
... GET /test_folder_1_/testoid/++resource++fivetest_resources/resource_subdir/resource.html HTTP/1.1
... Authorization: Basic manager:r00t
... ''')
... '''))
HTTP/1.1 200 OK
...
<html>
Expand All @@ -135,10 +135,10 @@ We also can traverse into sub-directories:
</html>
<BLANKLINE>

>>> print http(r'''
>>> print(http(r'''
... GET /test_folder_1_/testoid/++resource++fivetest_resources/resource_subdir/not-existant HTTP/1.1
... Authorization: Basic manager:r00t
... ''')
... '''))
HTTP/1.1 404 Not Found
...

Expand Down
12 changes: 6 additions & 6 deletions src/Products/Five/browser/tests/skin.txt
Expand Up @@ -16,17 +16,17 @@ Let's add a test object that we'll access the test page from:
The view was registered on a different layer than 'default', that's
why we can't access it straight away:

>>> print http(r"""
>>> print(http(r"""
... GET /test_folder_1_/testoid/eagle.html HTTP/1.1
... """)
... """))
HTTP/1.1 404 Not Found
...

It works when we explicitly use the skin that includes that layer:

>>> print http(r"""
>>> print(http(r"""
... GET /++skin++TestSkin/test_folder_1_/testoid/eagle.html HTTP/1.1
... """)
... """))
HTTP/1.1 200 OK
...
The eagle has landed:
Expand All @@ -40,9 +40,9 @@ Or when we make that skin the default skin:
... name="TestSkin" />
... ''')

>>> print http(r"""
>>> print(http(r"""
... GET /test_folder_1_/testoid/eagle.html HTTP/1.1
... """)
... """))
HTTP/1.1 200 OK
...
The eagle has landed:
Expand Down

0 comments on commit 5671856

Please sign in to comment.