[Zope3-checkins] CVS: Zope3/src/zope/app/form/tests - test_widget.py:1.5.4.1

Garrett Smith garrett at mojave-corp.com
Sat Feb 7 21:12:27 EST 2004


Update of /cvs-repository/Zope3/src/zope/app/form/tests
In directory cvs.zope.org:/tmp/cvs-serv3100/src/zope/app/form/tests

Modified Files:
      Tag: ozzope-widgets-branch
	test_widget.py 
Log Message:

Created branch for widget work at ozzope sprint.


=== Zope3/src/zope/app/form/tests/test_widget.py 1.5 => 1.5.4.1 ===
--- Zope3/src/zope/app/form/tests/test_widget.py:1.5	Fri Jan 16 08:09:07 2004
+++ Zope3/src/zope/app/form/tests/test_widget.py	Sat Feb  7 21:11:57 2004
@@ -18,70 +18,83 @@
 $Id$
 """
 
-from unittest import TestCase, TestSuite, main, makeSuite
+import doctest
+from unittest import TestSuite, main, makeSuite
 from zope.app.form.widget import Widget, CustomWidgetFactory
 from zope.app.interfaces.form import IWidget
-from zope.interface.verify import verifyObject
+from zope.interface.verify import verifyClass, verifyObject
 from zope.schema import Text
 from zope.publisher.browser import TestRequest
 from zope.component.interfaces import IViewFactory
 
-class TestWidget(TestCase):
-
-    def test_name(self):
-        w = Widget(Text(__name__='foo', title=u'Foo title'), TestRequest())
-        self.assertEqual(w.name, 'field.foo')
-
-    def test_setPrefix(self):
-        w = Widget(Text(__name__='foo', title=u'Foo title'), TestRequest())
-        w.setPrefix('test')
-        self.assertEqual(w.name, 'test.foo')
-
-    def test_title(self):
-        from zope.app.tests.placelesssetup import setUp, tearDown
-        setUp()
-        w = Widget(Text(__name__='foo', title=u'Foo title'), TestRequest())
-        self.assertEqual(w.title, 'Foo title')
-        tearDown()
-
-    def test_description(self):
-        from zope.app.tests.placelesssetup import setUp, tearDown
-        setUp()
-        w = Widget(Text(__name__='foo', description=u'Foo desc'),
-                   TestRequest())
-        self.assertEqual(w.description, 'Foo desc')
-        tearDown()
-
-    def test_IWidget(self):
-        from zope.app.tests.placelesssetup import setUp, tearDown
-        setUp()
-        w = Widget(Text(__name__='foo', title=u'Foo title'), TestRequest())
-        verifyObject(IWidget, w)
-        tearDown()
-
-    # XXX Don't test getValue. It's silly and will go away.
-
-class TestCustomWidgetFactory(TestCase):
-
-    # XXX this test should be rewritten once we've refactored widget properties
-
-    def test(self):
-        from zope.app.tests.placelesssetup import setUp, tearDown
-        setUp()
-        cw = CustomWidgetFactory(Widget, width=60)
-        verifyObject(IViewFactory, cw)
-        w = cw(Text(__name__='foo', title=u'Foo title'), TestRequest())
-        self.assertEqual(w.name, 'field.foo')
-        self.assertEqual(w.width, 60)
-        verifyObject(IWidget, w)
-        tearDown()
-
-
+class TestContext:
+    __name__ = 'Test'
+    title = 'My Test Context'
+    description = 'A test context.'
+
+class FooWidget(Widget):
+    pass
+    
+context = TestContext()
+request = TestRequest()
+
+class TestWidget:
+    """
+    Widget implements IWidget:
+
+        >>> verifyClass(IWidget, Widget)
+        True
+        >>> widget = Widget(context, request)
+        >>> verifyObject(IWidget, widget)
+        True
+        
+    The default values for widget are:
+        
+        >>> widget.name
+        'field.Test'
+        >>> widget.title
+        'My Test Context'
+        >>> widget.description
+        'A test context.'
+        >>> widget.visible
+        True
+        >>> widget.propertyNames
+        []
+        
+    In the last example, the widget name consists of a prefix, a dot, and the
+    field name. You can change the prefix used by the widget as follows:
+        
+        >>> widget.setPrefix('newprefix')
+        >>> widget.name
+        'newprefix.Test'
+        
+    To configure a widget, call setRenderedValue with a value that the
+    widget should display:
+        
+        >>> widget.setRenderedValue('Render Me')
+        
+    The way a widget renders a value depends on the type of widget. E.g. a
+    browser widget will render the specified value in HTML.
+    """
+
+class TestCustomWidgetFactory:
+    """
+    Custom widgets can be created using a custom widget factory. Factories
+    are used to assign attribute values to widgets they create:
+        
+        >>> factory = CustomWidgetFactory(FooWidget, bar='baz')
+        >>> widget = factory(context, request)
+        >>> type(widget)
+        <class 'zope.app.form.tests.test_widget.FooWidget'>
+        >>> widget.bar
+        'baz'
+    """
 
 def test_suite():
     return TestSuite((
         makeSuite(TestWidget),
         makeSuite(TestCustomWidgetFactory),
+        doctest.DocTestSuite(),
         ))
 
 if __name__=='__main__':




More information about the Zope3-Checkins mailing list