/usr/lib/python2.7/dist-packages/zope/formlib/tests/test_displaywidget.py is in python-zope.formlib 4.3.0a2-0ubuntu1.
This file is owned by root:root, with mode 0o644.
The actual contents of the file can be viewed below.
1 2 3 4 5 6 7 8 9 10 11 12 13 14 15 16 17 18 19 20 21 22 23 24 25 26 27 28 29 30 31 32 33 34 35 36 37 38 39 40 41 42 43 44 45 46 47 48 49 50 51 52 53 54 55 56 57 58 59 60 61 62 63 64 65 66 67 68 69 70 71 72 73 74 75 76 77 78 79 80 81 82 83 84 85 86 87 88 89 90 91 92 93 94 95 96 97 98 99 100 101 102 103 104 105 106 107 108 109 110 111 112 113 114 115 116 117 118 119 120 121 122 123 124 125 126 127 128 | ##############################################################################
#
# Copyright (c) 2001, 2002 Zope Foundation and Contributors.
# All Rights Reserved.
#
# This software is subject to the provisions of the Zope Public License,
# Version 2.1 (ZPL). A copy of the ZPL should accompany this distribution.
# THIS SOFTWARE IS PROVIDED "AS IS" AND ANY AND ALL EXPRESS OR IMPLIED
# WARRANTIES ARE DISCLAIMED, INCLUDING, BUT NOT LIMITED TO, THE IMPLIED
# WARRANTIES OF TITLE, MERCHANTABILITY, AGAINST INFRINGEMENT, AND FITNESS
# FOR A PARTICULAR PURPOSE.
#
##############################################################################
"""Generic Text Widgets tests
"""
import unittest
from zope.interface.verify import verifyClass
from zope.interface.exceptions import DoesNotImplement
from zope.publisher.browser import TestRequest
from zope.schema import TextLine
from doctest import DocTestSuite
from zope.formlib.widget import DisplayWidget, UnicodeDisplayWidget
from .support import checker
def test_implemented_interfaces():
"""Make sure that the display widget implements the correct interfaces.
Like all browser-used widgets, DisplayWidget must implement
`IBrowserWidget`.
>>> from zope.formlib.interfaces import IBrowserWidget
>>> verifyClass(IBrowserWidget, DisplayWidget)
True
But unlike most other widgets in this package, the display widget is *not*
an `IInputWidget`.
>>> from zope.formlib.interfaces import IInputWidget
>>> try:
... verifyClass(IInputWidget, DisplayWidget)
... except DoesNotImplement:
... 'not implemented'
'not implemented'
"""
def test_not_required():
"""Make sure that display widgets are not required
>>> field = TextLine(title = u'Title',
... __name__ = u'title',
... default = u'<My Title>')
>>> widget = DisplayWidget(field, TestRequest())
>>> widget.required
False
"""
def test_value_escaping():
"""Make sure that the returned values are correctly escaped.
First we need to create a field that is the context of the display widget.
>>> field = TextLine(title = u'Title',
... __name__ = u'title',
... default = u'<My Title>')
>>> field = field.bind(None)
Now we are ready to instantiate our widget.
>>> widget = DisplayWidget(field, TestRequest())
If no data was specified in the widget, the field's default value will be
chosen.
>>> widget()
u'<My Title>'
Now let's set a value and make sure that, when output, it is also
correctly escaped.
>>> widget.setRenderedValue(u'<Another Title>')
>>> widget()
u'<Another Title>'
When the value is the missing_value, the empty string should be
displayed::
>>> field = TextLine(title = u'Title',
... __name__ = u'title',
... required = False)
>>> field = field.bind(None)
>>> widget = DisplayWidget(field, TestRequest())
>>> widget.setRenderedValue(field.missing_value)
>>> widget()
''
If there's no default for the field and the value is missing on
the bound object, the empty string should still be displayed::
>>> field = TextLine(title=u'Title',
... __name__=u'title',
... required=False)
>>> class Thing:
... title = field.missing_value
>>> field = field.bind(Thing())
>>> widget = DisplayWidget(field, TestRequest())
>>> widget()
''
"""
def test_suite():
suite = unittest.TestSuite()
suite.addTest(DocTestSuite(checker=checker))
suite.addTest(DocTestSuite(
checker=checker,
extraglobs={"DisplayWidget": UnicodeDisplayWidget}))
return suite
if __name__ == '__main__':
unittest.main(defaultTest='test_suite')
|