[Checkins] SVN: z3c.form/trunk/src/z3c/form/converter.txt add some more coverage
Adam Groszer
agroszer at gmail.com
Sat Feb 14 06:26:00 EST 2009
Log message for revision 96522:
add some more coverage
Changed:
U z3c.form/trunk/src/z3c/form/converter.txt
-=-
Modified: z3c.form/trunk/src/z3c/form/converter.txt
===================================================================
--- z3c.form/trunk/src/z3c/form/converter.txt 2009-02-14 10:38:14 UTC (rev 96521)
+++ z3c.form/trunk/src/z3c/form/converter.txt 2009-02-14 11:26:00 UTC (rev 96522)
@@ -560,7 +560,7 @@
Let's now create a choice field (using a source) and a widget:
- >>> from zc.sourcefactory.basic import BasicSourceFactory
+ >>> from zc.sourcefactory.basic import BasicSourceFactory
>>> class GenderSourceFactory(BasicSourceFactory):
... _mapping = {0: u'male', 1: u'female'}
... def getValues(self):
@@ -715,6 +715,26 @@
>>> seqWidget.terms
<z3c.form.term.CollectionTermsVocabulary object ...>
+
+Corner case:
+Just in case the field has more ``_type``s:
+
+ >>> class myField(zope.schema.List):
+ ... _type = (list, tuple)
+
+ >>> genders = myField(value_type=gender)
+ >>> seqWidget = widget.SequenceWidget(TestRequest())
+ >>> seqWidget.field = genders
+
+We now use the field and widget to instantiate the converter:
+
+ >>> csdv = converter.CollectionSequenceDataConverter(genders, seqWidget)
+
+The converter uses the latter type (tuple) to convert:
+
+ >>> csdv.toFieldValue(['m'])
+ (0,)
+
Using source
~~~~~~~~~~~~
@@ -869,7 +889,7 @@
True
It also should work for schema fields that define their type as tuple,
-for instance zope.schema.Int declares its type as (int, long).
+for instance zope.schema.Int declares its type as (int, long).
>>> ids = zope.schema.List(
... value_type=zope.schema.Int(),
@@ -899,4 +919,32 @@
>>> tlc.toFieldValue('') is None
True
-
\ No newline at end of file
+
+Converting Missing value to Widget value returns '':
+
+ >>> tlc.toWidgetValue(tlc.field.missing_value)
+ u''
+
+Just in case the field has more ``_type``s:
+
+ >>> class myField(zope.schema.List):
+ ... _type = (list, tuple)
+
+ >>> ids = myField(
+ ... value_type=zope.schema.Int(),
+ ... )
+
+The converter will use the latter one.
+
+ >>> tlWidget.field = ids
+ >>> tlc = converter.TextLinesConverter(ids, tlWidget)
+
+Of course, it still can convert to the widget value:
+
+ >>> tlc.toWidgetValue([1,2,3])
+ u'1\n2\n3'
+
+And back:
+
+ >>> tlc.toFieldValue(u'1\n2\n3\n')
+ (1, 2, 3)
More information about the Checkins
mailing list