Skip to content
This repository has been archived by the owner on Apr 9, 2019. It is now read-only.

Commit

Permalink
fix tests for py3
Browse files Browse the repository at this point in the history
  • Loading branch information
pbauer committed Jun 15, 2018
1 parent 9b8f40a commit 6279f2a
Show file tree
Hide file tree
Showing 4 changed files with 33 additions and 33 deletions.
34 changes: 17 additions & 17 deletions src/plone/z3cform/crud/README.txt
Expand Up @@ -59,7 +59,7 @@ This is all that we need to render a combined edit add form containing
all our items:

>>> from plone.z3cform.tests import TestRequest
>>> print MyForm(None, TestRequest())() \
>>> print(MyForm(None, TestRequest())()) \
... # doctest: +ELLIPSIS +NORMALIZE_WHITESPACE
<div class="crud-form">...Martha...Peter...</div>

Expand Down Expand Up @@ -107,7 +107,7 @@ Now that we renamed Peter to Franz, it would be also nice to have
Franz use 'Franz' as the id in the storage, wouldn't it?

>>> storage['Peter']
<Person with name=u'Franz', age=16>
<Person with name='Franz', age=16>

We can override the CrudForm's ``before_update`` method to perform a
rename whenever the name of a person is changed:
Expand Down Expand Up @@ -186,7 +186,7 @@ clicking the "Delete" button:
>>> 'Franz' in html
False
>>> storage
{'Maria': <Person with name=u'Maria', age=50>}
{'Maria': <Person with name='Maria', age=50>}

Add an item with our form
-------------------------
Expand All @@ -209,7 +209,7 @@ Added items should show up right away:
True

>>> storage['Daniel']
<Person with name=u'Daniel', age=28>
<Person with name='Daniel', age=28>
>>> log.pop().object == storage['Daniel']
True
>>> log
Expand Down Expand Up @@ -262,7 +262,7 @@ wanted the name of our persons to be viewable only in the table:
... view_schema = field.Fields(IPerson).select('name')
... add_schema = IPerson

>>> print MyAdvancedForm(None, TestRequest())() \
>>> print(MyAdvancedForm(None, TestRequest())()) \
... # doctest: +ELLIPSIS +NORMALIZE_WHITESPACE
<div class="crud-form">...Daniel...Maria...</div>

Expand Down Expand Up @@ -293,7 +293,7 @@ We can still add a Person using both name and age:
>>> len(storage)
3
>>> storage['Thomas']
<Person with name=u'Thomas', age=28>
<Person with name='Thomas', age=28>

Our form can also contain links to our items:

Expand All @@ -302,7 +302,7 @@ Our form can also contain links to our items:
... if field == 'name':
... return 'http://en.wikipedia.org/wiki/%s' % item.name

>>> print MyAdvancedLinkingForm(None, TestRequest())() \
>>> print(MyAdvancedLinkingForm(None, TestRequest())()) \
... # doctest: +ELLIPSIS +NORMALIZE_WHITESPACE
<div class="crud-form">...
...<a href="http://en.wikipedia.org/wiki/Daniel"...
Expand All @@ -318,7 +318,7 @@ What if we wanted the name to be both used for linking to the item
... view_schema = field.Fields(IPerson).select('name')
... add_schema = IPerson

>>> print MyAdvancedLinkingForm(None, TestRequest())() \
>>> print(MyAdvancedLinkingForm(None, TestRequest())()) \
... # doctest: +ELLIPSIS +NORMALIZE_WHITESPACE
<div class="crud-form">...
...<a href="http://en.wikipedia.org/wiki/Thomas"...Thomas...</a>...
Expand All @@ -329,12 +329,12 @@ Wikipedia link immediately:

>>> request = TestRequest()
>>> for name in 'Daniel', 'Maria', 'Thomas':
... request.form['crud-edit.%s.widgets.name' % name] = unicode(storage[name].name)
... request.form['crud-edit.%s.widgets.age' % name] = unicode(storage[name].age)
... request.form['crud-edit.%s.widgets.name' % name] = storage[name].name
... request.form['crud-edit.%s.widgets.age' % name] = storage[name].age
>>> request.form['crud-edit.Thomas.widgets.name'] = u'Dracula'
>>> request.form['crud-edit.form.buttons.edit'] = u'Apply Changes'

>>> print MyAdvancedLinkingForm(None, request)() \
>>> print(MyAdvancedLinkingForm(None, request)()) \
... # doctest: +ELLIPSIS +NORMALIZE_WHITESPACE
<div class="crud-form">...
...<a href="http://en.wikipedia.org/wiki/Dracula"...Dracula...</a>...
Expand Down Expand Up @@ -401,19 +401,19 @@ than the 'edit' and 'delete' ones:
>>> "Delete" in html, "Apply changes" in html, "Capitalize" in html
(False, False, True)
>>> pprint(storage)
{'Daniel': <Person with name=u'Daniel', age=35>,
'Maria': <Person with name=u'Maria', age=40>,
'Thomas': <Person with name=u'Thomas', age=28>}
{'Daniel': <Person with name='Daniel', age=35>,
'Maria': <Person with name='Maria', age=40>,
'Thomas': <Person with name='Thomas', age=28>}

>>> request.form['crud-edit.Thomas.widgets.select'] = ['selected']
>>> request.form['crud-edit.form.buttons.capitalize'] = u'Capitalize'
>>> html = MyCustomForm(None, request)()
>>> "Capitalized items" in html
True
>>> pprint(storage)
{'Daniel': <Person with name=u'Daniel', age=35>,
'Maria': <Person with name=u'Maria', age=40>,
'Thomas': <Person with name=u'THOMAS', age=28>}
{'Daniel': <Person with name='Daniel', age=35>,
'Maria': <Person with name='Maria', age=40>,
'Thomas': <Person with name='THOMAS', age=28>}

We *cannot* use any of the other buttons:

Expand Down
6 changes: 3 additions & 3 deletions src/plone/z3cform/inputs.txt
Expand Up @@ -68,20 +68,20 @@ Let's now look this up with some form data that is not encoded:
>>> testForm.update()
>>> data, errors = testForm.extractData()
>>> data
{'text': u'foo'}
{'text': 'foo'}
>>> errors
()

Let's now try with some encoded data. The default encoding is utf-8.

>>> context = Bar()
>>> request = make_request(form={'form.widgets.text': 'fo\xc3\xb8'})
>>> request = make_request(form={'form.widgets.text': b'fo\xc3\xb8'})

>>> testForm = getMultiAdapter((context, request), name=u"test-form")
>>> testForm.update()
>>> data, errors = testForm.extractData()
>>> data
{'text': u'fo\xf8'}
{'text': 'foø'}
>>> errors
()

2 changes: 1 addition & 1 deletion src/plone/z3cform/layout.txt
Expand Up @@ -91,7 +91,7 @@ layout. We define a custom layout template first:
>>> from Products.Five.browser.pagetemplatefile import ViewPageTemplateFile
>>> fd, path = tempfile.mkstemp()
>>> f = os.fdopen(fd, 'w')
>>> f.write("""
>>> _ = f.write("""
... <html>Hello, this is your layout speaking:
... <h1 tal:content="view/label">View Title</h1>
... <div tal:content="structure view/contents"></div>
Expand Down
24 changes: 12 additions & 12 deletions src/plone/z3cform/traversal.txt
Expand Up @@ -11,10 +11,10 @@ may get an error if you mix in Explicit in Zope 2.12 and the parent view
the case. To be compatible with both Zope 2.10 and 2.12, you'll need to
mix in Acquisition.Explicit, but make sure the widget does *not* provide the
IAcquirer interface. One way to do that is by using implementsOnly(), e.g.::

class MyWidget(Aquisition.Explicit):
implementsOnly(IMyWidget)

...

If you are only targeting Zope 2.12 and later, you can avoid mixing in any
Expand Down Expand Up @@ -86,7 +86,7 @@ adapter. For example, let's say we'd traversed to
>>> age_widget
<TextWidget 'form.widgets.age'>
>>> age_widget.value
u'48'
'48'

Can also specify form.widgets.age and get the same result.

Expand All @@ -96,7 +96,7 @@ Can also specify form.widgets.age and get the same result.
>>> age_widget
<TextWidget 'form.widgets.age'>
>>> age_widget.value
u'48'
'48'

Please note that this point, the form has been updated, but not rendered.

Expand Down Expand Up @@ -144,31 +144,31 @@ And traverse through to individual items.
>>> age_widget
<TextWidget 'form.widgets.list_field.1'>
>>> age_widget.value
u'49'
'49'

>>> traverser = get_traverser(Bar(),u"test-list-form")
>>> age_widget = traverser.traverse('list_field.2', [])
Updating test form
>>> age_widget
<TextWidget 'form.widgets.list_field.2'>
>>> age_widget.value
u'50'
'50'

Out of range errors are LocationErrors

>>> traverser = get_traverser(Bar(),u"test-list-form")
>>> age_widget = traverser.traverse('list_field.9', [])
Traceback (most recent call last):
File "<stdin>", line 1, in ?
LocationError: "'9' not in range"
zope.location.interfaces.LocationError: "'9' not in range"

Non-integer values are also LocationErrors

>>> traverser = get_traverser(Bar(),u"test-list-form")
>>> age_widget = traverser.traverse('list_field.camel', [])
Traceback (most recent call last):
File "<stdin>", line 1, in ?
LocationError: "'camel' not valid index"
zope.location.interfaces.LocationError: "'camel' not valid index"

Traversing object types
-----------------------
Expand Down Expand Up @@ -225,23 +225,23 @@ And traverse through to the form within
>>> age_widget
<TextWidget 'form.widgets.obj_field.widgets.list_field.0'>
>>> age_widget.value
u'48'
'48'

Missing widgets are LocationErrors

>>> traverser = get_traverser(Bar(),u"test-parent-form")
>>> list_widget = traverser.traverse('obj_field.widgets.camel_field', [])
Traceback (most recent call last):
File "<stdin>", line 1, in ?
LocationError: 'camel_field'
zope.location.interfaces.LocationError: 'camel_field'

Looking for anything other than 'widgets' is also an error

>>> traverser = get_traverser(Bar(),u"test-parent-form")
>>> list_widget = traverser.traverse('obj_field.wodgets', [])
Traceback (most recent call last):
File "<stdin>", line 1, in ?
LocationError: 'wodgets'
zope.location.interfaces.LocationError: 'wodgets'

Traversal on a layout wrapper view
-----------------------------------
Expand Down Expand Up @@ -320,4 +320,4 @@ When a form field does not exist a LocationError is raised.
>>> traverser.traverse('missing', [])
Traceback (most recent call last):
...
LocationError: 'missing'
zope.location.interfaces.LocationError: 'missing'

0 comments on commit 6279f2a

Please sign in to comment.