[Zope3-checkins] CVS: Zope3/src/zope/app/form/tests - test_widget_geddon_deprecations.py:1.1.2.1 test_utility.py:1.13.10.1
Grégoire Weber
zope@i-con.ch
Sun, 22 Jun 2003 10:24:04 -0400
Update of /cvs-repository/Zope3/src/zope/app/form/tests
In directory cvs.zope.org:/tmp/cvs-serv24874/src/zope/app/form/tests
Modified Files:
Tag: cw-mail-branch
test_utility.py
Added Files:
Tag: cw-mail-branch
test_widget_geddon_deprecations.py
Log Message:
Synced up with HEAD
=== Added File Zope3/src/zope/app/form/tests/test_widget_geddon_deprecations.py ===
##############################################################################
#
# Copyright (c) 2003 Zope Corporation and Contributors.
# All Rights Reserved.
#
# This software is subject to the provisions of the Zope Public License,
# Version 2.0 (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.
#
##############################################################################
"""XXX short summary goes here.
$Id: test_widget_geddon_deprecations.py,v 1.1.2.1 2003/06/22 14:23:03 gregweb Exp $
"""
from zope.testing.doctestunit import DocTestSuite
from zope.publisher.browser import TestRequest
from zope.app.form import utility
from zope.app.form.widget import Widget, CustomWidget
from zope.schema import Text
from zope.schema.interfaces import IText
from zope.app.tests.placelesssetup import setUp, tearDown
from zope.component.view import provideView
from zope.publisher.interfaces.browser import IBrowserPresentation
import warnings
class TestView:
bar = CustomWidget(Widget, uncle='bob')
def __init__(self, context, request):
self.context, self.request = context, request
class TestWidget:
def __init__(self, context, request):
self.context, self.request = context, request
def __call__(self):
return '42'
theField = Text(__name__="foo")
def test_widget_in_wrong_name():
"""
>>> warned = None
>>> def fakewarn(*args, **kw):
... global warned
... warned = args
>>> utility.warn = fakewarn
>>> request = TestRequest()
>>> view = TestView(None, request)
>>> view.foo = Widget(theField, request)
>>> int(hasattr(view, 'foo_widget'))
0
>>> warned
>>> utility.setUpWidget(view, 'foo', Text())
>>> print warned[0]
View (TestView) saved a widget (foo) without a '_widget' suffix.
Url: http://127.0.0.1
>>> warned[1].__name__
'DeprecationWarning'
>>> int(hasattr(view, 'foo_widget'))
1
>>> utility.warn = warnings.warn
"""
def test_widget_gets_warning_w_custom_widget_in_wrong_name():
"""
>>> warned = None
>>> def fakewarn(*args, **kw):
... global warned
... warned = args
>>> utility.warn = fakewarn
>>> request = TestRequest()
>>> view = TestView(None, request)
>>> int(hasattr(view, 'bar_widget'))
0
>>> warned
>>> utility.setUpWidget(view, 'bar', Text())
>>> print warned[0]
View (TestView) saved a widget (bar) without a '_widget' suffix.
Url: http://127.0.0.1
>>> warned[1].__name__
'DeprecationWarning'
>>> view.bar_widget.uncle
'bob'
Make sure we updated the old attr:
>>> view.bar.uncle
'bob'
>>> utility.warn = warnings.warn
"""
def test_clients_using_wrong_name():
"""
>>> warned = None
>>> def fakewarn(*args, **kw):
... global warned
... warned = args
>>> utility.warn = fakewarn
>>> setUp()
>>> provideView(IText, 'test', IBrowserPresentation, TestWidget)
>>> request = TestRequest()
>>> view = TestView(None, request)
>>> utility.setUpWidget(view, 'foo', Text(), vname='test')
>>> view.foo_widget()
'42'
>>> warned
>>> view.foo()
'42'
>>> print warned[0]
View (TestView) saved a widget (foo) without a '_widget' suffix.
Url: http://127.0.0.1
>>> warned[1].__name__
'DeprecationWarning'
>>> tearDown()
"""
def test_suite(): return DocTestSuite()
if __name__ == '__main__': unittest.main()
=== Zope3/src/zope/app/form/tests/test_utility.py 1.13 => 1.13.10.1 ===
--- Zope3/src/zope/app/form/tests/test_utility.py:1.13 Thu May 1 15:35:17 2003
+++ Zope3/src/zope/app/form/tests/test_utility.py Sun Jun 22 10:23:03 2003
@@ -23,7 +23,7 @@
from zope.publisher.browser import BrowserView
from zope.publisher.browser import TestRequest
from zope.publisher.interfaces.browser import IBrowserPresentation
-from zope.interface import Interface, directlyProvides
+from zope.interface import Interface, directlyProvides, implements
from zope.schema import Text, accessors
from zope.app.browser.form.widget import TextWidget
from zope.component.view import provideView, setDefaultViewName
@@ -36,7 +36,6 @@
from zope.component.interfaces import IViewFactory
-
class I(Interface):
title = Text(title=u"Title", required = False)
description = Text(title=u"Description",
@@ -53,10 +52,10 @@
description = Text(title=u"Description", required = False)
class C:
- __implements__ = I
+ implements(I)
class C2:
- __implements__ = I2
+ implements(I2)
class Ia(Interface):
@@ -67,7 +66,7 @@
)
class Ca:
- __implements__ = Ia
+ implements(Ia)
def getTitle(self): return self._t
def setTitle(self, v): self._t = v
@@ -76,12 +75,12 @@
class ViewWithCustomTitleWidgetFactory(BrowserView):
- def title(self, context, request):
+ def title_widget(self, context, request):
w = W(context, request)
w.custom = 1
return w
- directlyProvides(title, IViewFactory)
+ directlyProvides(title_widget, IViewFactory)
def kw(**kw):
return kw
@@ -130,8 +129,8 @@
request = TestRequest()
view = BrowserView(c, request)
setUpWidget(view, 'title', I['title'])
- self.assertEqual(view.title(), u'title: ')
- self.assertEqual(view.title.getData(), None)
+ self.assertEqual(view.title_widget(), u'title: ')
+ self.assertEqual(view.title_widget.getData(), None)
def test_setUpWidget_w_request_data(self):
@@ -140,8 +139,8 @@
request.form['field.title'] = u'xxx'
view = BrowserView(c, request)
setUpWidget(view, 'title', I['title'])
- self.assertEqual(view.title(), u'title: xxx')
- self.assertEqual(view.title.getData(), u'xxx')
+ self.assertEqual(view.title_widget(), u'title: xxx')
+ self.assertEqual(view.title_widget.getData(), u'xxx')
def test_setUpWidget_w_request_data_and_initial_data(self):
c = C()
@@ -149,8 +148,8 @@
request.form['field.title'] = u'xxx'
view = BrowserView(c, request)
setUpWidget(view, 'title', I['title'], u'yyy')
- self.assertEqual(view.title(), u'title: xxx')
- self.assertEqual(view.title.getData(), u'xxx')
+ self.assertEqual(view.title_widget(), u'title: xxx')
+ self.assertEqual(view.title_widget.getData(), u'xxx')
def test_setUpWidget_w_request_data_and_initial_data_force(self):
c = C()
@@ -158,16 +157,16 @@
request.form['field.title'] = u'xxx'
view = BrowserView(c, request)
setUpWidget(view, 'title', I['title'], u'yyy', force=1)
- self.assertEqual(view.title(), u'title: yyy')
- self.assertEqual(view.title.getData(), u'xxx')
+ self.assertEqual(view.title_widget(), u'title: yyy')
+ self.assertEqual(view.title_widget.getData(), u'xxx')
def test_setUpWidget_w_initial_data(self):
c = C()
request = TestRequest()
view = BrowserView(c, request)
setUpWidget(view, 'title', I['title'], u'yyy')
- self.assertEqual(view.title(), u'title: yyy')
- self.assertEqual(view.title.getData(), None)
+ self.assertEqual(view.title_widget(), u'title: yyy')
+ self.assertEqual(view.title_widget.getData(), None)
def test_setUpWidget_w_bad_initial_data(self):
c = C()
@@ -180,35 +179,35 @@
c = C()
request = TestRequest()
view = BrowserView(c, request)
- view.title = w = W(I['title'], request)
+ view.title_widget = w = W(I['title'], request)
setUpWidget(view, 'title', I['title'], u'yyy')
- self.assertEqual(view.title(), u'title: yyy')
- self.assertEqual(view.title.getData(), None)
- self.assertEqual(view.title, w)
+ self.assertEqual(view.title_widget(), u'title: yyy')
+ self.assertEqual(view.title_widget.getData(), None)
+ self.assertEqual(view.title_widget, w)
def test_setUpWidget_w_Custom_widget(self):
c = C()
request = TestRequest()
view = ViewWithCustomTitleWidgetFactory(c, request)
setUpWidget(view, 'title', I['title'], u'yyy')
- self.assertEqual(view.title(), u'title: yyy')
- self.assertEqual(view.title.getData(), None)
- self.assertEqual(view.title.custom, 1)
+ self.assertEqual(view.title_widget(), u'title: yyy')
+ self.assertEqual(view.title_widget.getData(), None)
+ self.assertEqual(view.title_widget.custom, 1)
def test_setupWidgets(self):
c = C()
request = TestRequest()
view = BrowserView(c, request)
setUpWidgets(view, I)
- self.assertEqual(view.title(), u'title: ')
- self.assertEqual(view.description(), u'description: ')
+ self.assertEqual(view.title_widget(), u'title: ')
+ self.assertEqual(view.description_widget(), u'description: ')
def test_setupWidgets_via_names(self):
c = C()
request = TestRequest()
view = BrowserView(c, request)
setUpWidgets(view, I, names=['title'])
- self.assertEqual(view.title(), u'title: ')
+ self.assertEqual(view.title_widget(), u'title: ')
self.failIf(hasattr(view, 'description'))
def test_setupWidgets_bad_field_name(self):
@@ -226,18 +225,18 @@
request = TestRequest()
view = BrowserView(c, request)
setUpWidgets(view, I, prefix='spam')
- self.assertEqual(view.title.prefix, 'spam')
- self.assertEqual(view.description.prefix, 'spam')
+ self.assertEqual(view.title_widget.prefix, 'spam')
+ self.assertEqual(view.description_widget.prefix, 'spam')
def test_setupWidgets_w_initial_data_and_custom_widget(self):
c = C()
request = TestRequest()
view = BrowserView(c, request)
- view.title = w = W(I['title'], request)
+ view.title_widget = w = W(I['title'], request)
setUpWidgets(view, I, initial=kw(title=u"ttt", description=u"ddd"))
- self.assertEqual(view.title(), u'title: ttt')
- self.assertEqual(view.description(), u'description: ddd')
- self.assertEqual(view.title, w)
+ self.assertEqual(view.title_widget(), u'title: ttt')
+ self.assertEqual(view.description_widget(), u'description: ddd')
+ self.assertEqual(view.title_widget, w)
def test_setupWidgets_w_initial_data_and_request_data(self):
c = C()
@@ -245,7 +244,7 @@
request.form['field.title'] = u'yyy'
view = BrowserView(c, request)
setUpWidgets(view, I, initial=kw(title=u"ttt", description=u"ddd"))
- self.assertEqual(view.title(), u'title: yyy')
+ self.assertEqual(view.title_widget(), u'title: yyy')
def test_setupWidgets_w_initial_data_forced_and_request_data(self):
c = C()
@@ -254,7 +253,7 @@
view = BrowserView(c, request)
setUpWidgets(view, I, force=1,
initial=kw(title=u"ttt", description=u"ddd"))
- self.assertEqual(view.title(), u'title: ttt')
+ self.assertEqual(view.title_widget(), u'title: ttt')
def test_setupEditWidgets_w_custom_widget(self):
c = C()
@@ -262,11 +261,11 @@
c.description = u'cd'
request = TestRequest()
view = BrowserView(c, request)
- view.title = w = W(I['title'], request)
+ view.title_widget = w = W(I['title'], request)
setUpEditWidgets(view, I)
- self.assertEqual(view.title(), u'title: ct')
- self.assertEqual(view.description(), u'description: cd')
- self.assertEqual(view.title, w)
+ self.assertEqual(view.title_widget(), u'title: ct')
+ self.assertEqual(view.description_widget(), u'description: cd')
+ self.assertEqual(view.title_widget, w)
def test_setupEditWidgets_w_form_data(self):
c = C()
@@ -277,8 +276,8 @@
request.form['field.description'] = u'fd'
view = BrowserView(c, request)
setUpEditWidgets(view, I)
- self.assertEqual(view.title(), u'title: ft')
- self.assertEqual(view.description(), u'description: fd')
+ self.assertEqual(view.title_widget(), u'title: ft')
+ self.assertEqual(view.description_widget(), u'description: fd')
def test_setupEditWidgets_via_names(self):
c = C()
@@ -287,7 +286,7 @@
request.form['field.title'] = u'ft'
view = BrowserView(c, request)
setUpEditWidgets(view, I, names=['title'])
- self.assertEqual(view.title(), u'title: ft')
+ self.assertEqual(view.title_widget(), u'title: ft')
self.failIf(hasattr(view, 'description'))
def test_setupEditWidgets_and_accessors(self):
@@ -297,8 +296,8 @@
request = TestRequest()
view = BrowserView(c, request)
setUpEditWidgets(view, Ia)
- self.assertEqual(view.getTitle(), u'getTitle: ct')
- self.assertEqual(view.getDescription(), u'getDescription: cd')
+ self.assertEqual(view.getTitle_widget(), u'getTitle: ct')
+ self.assertEqual(view.getDescription_widget(), u'getDescription: cd')
def test_setupWidgets_bad_field_name(self):
c = C()
@@ -320,8 +319,8 @@
request.form['field.description'] = u'ft'
view = BrowserView(c, request)
setUpEditWidgets(view, I, force=1)
- self.assertEqual(view.title(), u'title: ct')
- self.assertEqual(view.description(), u'description: cd')
+ self.assertEqual(view.title_widget(), u'title: ct')
+ self.assertEqual(view.description_widget(), u'description: cd')
def test_setupEditWidgets_w_custom_widget_and_prefix(self):
c = C()
@@ -329,11 +328,11 @@
c.description = u'cd'
request = TestRequest()
view = BrowserView(c, request)
- view.title = w = W(I['title'], request)
+ view.title_widget = w = W(I['title'], request)
setUpEditWidgets(view, I, prefix='eggs')
- self.assertEqual(view.title.prefix, 'eggs')
- self.assertEqual(view.description.prefix, 'eggs')
- self.assertEqual(view.title, w)
+ self.assertEqual(view.title_widget.prefix, 'eggs')
+ self.assertEqual(view.description_widget.prefix, 'eggs')
+ self.assertEqual(view.title_widget, w)
def test_setupEditWidgets_w_other_data(self):
c = C()
@@ -343,16 +342,16 @@
request = TestRequest()
view = BrowserView(c, request)
setUpEditWidgets(view, I)
- self.assertEqual(view.title(), u'title: ')
- self.assertEqual(view.description(), u'description: ')
+ self.assertEqual(view.title_widget(), u'title: ')
+ self.assertEqual(view.description_widget(), u'description: ')
setUpEditWidgets(view, I, c2)
- self.assertEqual(view.title(), u'title: ct')
- self.assertEqual(view.description(), u'description: cd')
+ self.assertEqual(view.title_widget(), u'title: ct')
+ self.assertEqual(view.description_widget(), u'description: cd')
view = BrowserView(c2, request)
setUpEditWidgets(view, I)
- self.assertEqual(view.title(), u'title: ct')
- self.assertEqual(view.description(), u'description: cd')
+ self.assertEqual(view.title_widget(), u'title: ct')
+ self.assertEqual(view.description_widget(), u'description: cd')
def test_setupEditWidgets_w_bad_data(self):
class Forbidden(AttributeError): pass
@@ -377,8 +376,8 @@
request.form['field.title'] = u'ft'
view = BrowserView(c, request)
setUpWidgets(view, I, initial=kw(title=u"ttt", description=u"ddd"))
- self.assertEqual(view.title(), u'title: ft')
- self.assertEqual(view.description(), u'description: ddd')
+ self.assertEqual(view.title_widget(), u'title: ft')
+ self.assertEqual(view.description_widget(), u'description: ddd')
def test_getWidgetsData(self):