[Checkins] SVN: zope.schema/branches/jinty-native_string/src/zope/schema/ Add tests and fix a bug that crept in
Brian Sutherland
cvs-admin at zope.org
Wed Apr 11 07:21:48 UTC 2012
Log message for revision 125127:
Add tests and fix a bug that crept in
Changed:
U zope.schema/branches/jinty-native_string/src/zope/schema/_field.py
A zope.schema/branches/jinty-native_string/src/zope/schema/tests/test_native_string.py
A zope.schema/branches/jinty-native_string/src/zope/schema/tests/test_uri.py
-=-
Modified: zope.schema/branches/jinty-native_string/src/zope/schema/_field.py
===================================================================
--- zope.schema/branches/jinty-native_string/src/zope/schema/_field.py 2012-04-10 17:55:00 UTC (rev 125126)
+++ zope.schema/branches/jinty-native_string/src/zope/schema/_field.py 2012-04-11 07:21:44 UTC (rev 125127)
@@ -627,20 +627,7 @@
raise InvalidURI(value)
def fromUnicode(self, value):
- """
- >>> uri = URI(__name__='test')
- >>> uri.fromUnicode("http://www.python.org/foo/bar")
- 'http://www.python.org/foo/bar'
- >>> uri.fromUnicode(" http://www.python.org/foo/bar")
- 'http://www.python.org/foo/bar'
- >>> uri.fromUnicode(" \\n http://www.python.org/foo/bar\\n")
- 'http://www.python.org/foo/bar'
- >>> uri.fromUnicode("http://www.python.org/ foo/bar")
- Traceback (most recent call last):
- ...
- InvalidURI: http://www.python.org/ foo/bar
- """
- v = value.strip()
+ v = str(value.strip())
self.validate(v)
return v
Added: zope.schema/branches/jinty-native_string/src/zope/schema/tests/test_native_string.py
===================================================================
--- zope.schema/branches/jinty-native_string/src/zope/schema/tests/test_native_string.py (rev 0)
+++ zope.schema/branches/jinty-native_string/src/zope/schema/tests/test_native_string.py 2012-04-11 07:21:44 UTC (rev 125127)
@@ -0,0 +1,38 @@
+##############################################################################
+#
+# Copyright (c) 2012 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.
+#
+##############################################################################
+import unittest
+
+import six
+
+from zope.schema import Text, Bytes, NativeString
+from zope.schema import TextLine, BytesLine, NativeStringLine
+
+class TestNativeString(unittest.TestCase):
+
+ def test_string_py2(self):
+ if six.PY3:
+ return
+ self.assertTrue(NativeString is Bytes)
+ self.assertTrue(NativeStringLine is BytesLine)
+
+ def test_string_py3(self):
+ if not six.PY3:
+ return
+ self.assertTrue(NativeString is Text)
+ self.assertTrue(NativeStringLine is TextLine)
+
+def test_suite():
+ suite = unittest.TestSuite()
+ suite.addTest(unittest.makeSuite(TestNativeString))
+ return suite
Property changes on: zope.schema/branches/jinty-native_string/src/zope/schema/tests/test_native_string.py
___________________________________________________________________
Added: svn:eol-style
+ native
Added: zope.schema/branches/jinty-native_string/src/zope/schema/tests/test_uri.py
===================================================================
--- zope.schema/branches/jinty-native_string/src/zope/schema/tests/test_uri.py (rev 0)
+++ zope.schema/branches/jinty-native_string/src/zope/schema/tests/test_uri.py 2012-04-11 07:21:44 UTC (rev 125127)
@@ -0,0 +1,67 @@
+##############################################################################
+#
+# Copyright (c) 2012 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.
+#
+##############################################################################
+"""URI field tests
+"""
+from unittest import main, makeSuite
+
+from six import u
+from zope.schema import URI
+from zope.schema.tests.test_field import FieldTestBase
+from zope.schema.interfaces import RequiredMissing
+from zope.schema.interfaces import InvalidURI, WrongType
+
+class URITest(FieldTestBase):
+ """Test the URI Field."""
+
+ _Field_Factory = URI
+
+ def testValidate(self):
+ field = self._Field_Factory(
+ title=u('Not required field'), description=u(''),
+ readonly=False, required=False)
+ field.validate(None)
+ field.validate('http://www.example.com')
+ self.assertRaises(WrongType, field.validate, 2)
+
+ def testValidateRequired(self):
+ field = self._Field_Factory(
+ title=u('Required field'), description=u(''),
+ readonly=False, required=True)
+ field.validate('http://www.example.com')
+ self.assertRaises(RequiredMissing, field.validate, None)
+
+ def testFromUnicode(self):
+ field = self._Field_Factory()
+ # result is a native string
+ self.assertEqual(
+ field.fromUnicode(u("http://www.python.org/foo/bar")),
+ 'http://www.python.org/foo/bar')
+ # leading/trailing whitespace is stripped
+ self.assertEqual(
+ field.fromUnicode(u(" http://www.python.org/foo/bar")),
+ 'http://www.python.org/foo/bar')
+ self.assertEqual(
+ field.fromUnicode(u(" \n http://www.python.org/foo/bar\n")),
+ 'http://www.python.org/foo/bar')
+ # but not in the middle
+ self.assertRaises(InvalidURI,
+ field.fromUnicode,
+ u("http://www.python.org/ foo/bar"))
+
+def test_suite():
+ suite = makeSuite(URITest)
+ return suite
+
+if __name__ == '__main__':
+ main(defaultTest='test_suite')
Property changes on: zope.schema/branches/jinty-native_string/src/zope/schema/tests/test_uri.py
___________________________________________________________________
Added: svn:eol-style
+ native
More information about the checkins
mailing list