Skip to content

Commit

Permalink
fix doctests in py3
Browse files Browse the repository at this point in the history
  • Loading branch information
pbauer committed Sep 18, 2018
1 parent e5b403b commit ee53b27
Show file tree
Hide file tree
Showing 5 changed files with 29 additions and 12 deletions.
7 changes: 4 additions & 3 deletions plone/autoform/autoform.rst
Original file line number Diff line number Diff line change
Expand Up @@ -44,7 +44,8 @@ First, let's load this package's ZCML so that we can run the tests::
...
... </configure>
... """
>>> from StringIO import StringIO
>>> import six
>>> from six import StringIO
>>> from zope.configuration import xmlconfig
>>> xmlconfig.xmlconfig(StringIO(configuration))

Expand Down Expand Up @@ -313,9 +314,9 @@ has taken the label and description from the first definition::
>>> len(test_form.groups)
1
>>> test_form.groups[0].label
u'Fieldset one'
'Fieldset one'
>>> test_form.groups[0].description
u'Description of fieldset one'
'Description of fieldset one'
>>> test_form.groups[0].fields.keys()
['three', 'IOtherSchema.three']

Expand Down
3 changes: 2 additions & 1 deletion plone/autoform/supermodel.txt
Original file line number Diff line number Diff line change
Expand Up @@ -19,7 +19,8 @@ First, let's load this package's ZCML so that we can run the tests:
...
... </configure>
... """
>>> from StringIO import StringIO
>>> import six
>>> from six import StringIO
>>> from zope.configuration import xmlconfig
>>> xmlconfig.xmlconfig(StringIO(configuration))

Expand Down
3 changes: 2 additions & 1 deletion plone/autoform/tests/subform.txt
Original file line number Diff line number Diff line change
Expand Up @@ -32,7 +32,8 @@ First, let's load this package's ZCML so that we can run the tests:
...
... </configure>
... """
>>> from StringIO import StringIO
>>> import six
>>> from six import StringIO
>>> from zope.configuration import xmlconfig
>>> xmlconfig.xmlconfig(StringIO(configuration))

Expand Down
11 changes: 11 additions & 0 deletions plone/autoform/tests/test_doctests.py
Original file line number Diff line number Diff line change
Expand Up @@ -4,6 +4,8 @@
from plone.testing.zca import UNIT_TESTING

import doctest
import re
import six
import unittest


Expand All @@ -15,12 +17,21 @@
]


class Py23DocChecker(doctest.OutputChecker):
def check_output(self, want, got, optionflags):
if six.PY2:
got = re.sub("u'(.*?)'", "'\\1'", want)
# want = re.sub("b'(.*?)'", "'\\1'", want)
return doctest.OutputChecker.check_output(self, want, got, optionflags)


def test_suite():
tests = [
layered(
doctest.DocFileSuite(
test_file,
optionflags=optionflags,
checker=Py23DocChecker(),
),
layer=UNIT_TESTING,
)
Expand Down
17 changes: 10 additions & 7 deletions plone/autoform/view.txt
Original file line number Diff line number Diff line change
Expand Up @@ -15,7 +15,8 @@ First, let's load this package's ZCML so that we can run the tests:
...
... </configure>
... """
>>> from StringIO import StringIO
>>> import six
>>> from six import StringIO
>>> from zope.configuration import xmlconfig
>>> xmlconfig.xmlconfig(StringIO(configuration))

Expand Down Expand Up @@ -79,7 +80,7 @@ set up.
>>> context.summary = u"Summary"

>>> view = TestView(context, request)
>>> print view()
>>> print(view())
<div>My title widget says
<span id="form-widgets-title"
class="text-widget...textline-field">Test title</span>
Expand All @@ -96,9 +97,10 @@ updated, we have access to widgets in the default fieldset:
There is also a shortcut to allow access to any widget by (possibly prefixed)
name:

>>> view.w.items()
[('body', <TextAreaWidget 'form.widgets.body'>),
('ISecondarySchema.summary', <TextAreaWidget 'form.widgets.ISecondarySchema.summary'>),
>>> items = sorted(list(view.w.items()))
>>> items
[('ISecondarySchema.summary', <TextAreaWidget 'form.widgets.ISecondarySchema.summary'>),
('body', <TextAreaWidget 'form.widgets.body'>),
('title', <TextWidget 'form.widgets.title'>)]

You can also see fieldsets (groups) either in order:
Expand All @@ -108,7 +110,7 @@ You can also see fieldsets (groups) either in order:

or looked up by name:

>>> view.fieldsets.items()
>>> list(view.fieldsets.items())
[('secondary', <plone.z3cform.fieldsets.group.Group object at ...>)]

Note how the schema name is used as a prefix to all additional schemata. If
Expand All @@ -117,7 +119,8 @@ you wish to flatten the namespace, you can set ignorePrefix to true:
>>> view = TestView(context, request)
>>> view.ignorePrefix = True
>>> view.update()
>>> view.w.items()
>>> items = sorted(view.w.items())
>>> items
[('body', <TextAreaWidget 'form.widgets.body'>),
('summary', <TextAreaWidget 'form.widgets.summary'>),
('title', <TextWidget 'form.widgets.title'>)]
Expand Down

0 comments on commit ee53b27

Please sign in to comment.