[Checkins] SVN: z3c.json/trunk/src/z3c/json/ Added test setup helper
Roger Ineichen
roger at projekt01.ch
Tue Dec 4 23:59:18 EST 2007
Log message for revision 82136:
Added test setup helper
Added test for this helper
Changed:
A z3c.json/trunk/src/z3c/json/README.txt
A z3c.json/trunk/src/z3c/json/testing.py
U z3c.json/trunk/src/z3c/json/tests.py
-=-
Added: z3c.json/trunk/src/z3c/json/README.txt
===================================================================
--- z3c.json/trunk/src/z3c/json/README.txt (rev 0)
+++ z3c.json/trunk/src/z3c/json/README.txt 2007-12-05 04:59:16 UTC (rev 82136)
@@ -0,0 +1,41 @@
+======
+README
+======
+
+We can use the JSONReader and JSONWriter if we need to convert something from
+or to JSON. Let's check the utilities:
+
+ >>> import zope.component
+ >>> from z3c.json import interfaces
+ >>> from z3c.json import testing
+ >>> testing.setUpJSONConverter()
+
+JSONWRiter
+----------
+
+ >>> jsonWriter = zope.component.getUtility(interfaces.IJSONWriter)
+ >>> jsonWriter
+ <z3c.json.converter.JSONWriter object at ...>
+
+Read some data:
+
+ >>> input = {u'a':['fred',7],u'b':['mary',1.234]}
+ >>> jsonStr = jsonWriter.write(input)
+ >>> jsonStr
+ u'{"a":["fred",7],"b":["mary",1.234]}'
+
+JSONReader
+----------
+
+ >>> jsonReader = zope.component.getUtility(interfaces.IJSONReader)
+ >>> jsonReader
+ <z3c.json.converter.JSONReader object at ...>
+
+Conver the data back to python:
+
+ >>> output = jsonReader.read(jsonStr)
+ >>> output
+ {u'a': [u'fred', 7], u'b': [u'mary', 1.234]}
+
+ >>> input == output
+ True
Property changes on: z3c.json/trunk/src/z3c/json/README.txt
___________________________________________________________________
Name: svn:eol-style
+ native
Added: z3c.json/trunk/src/z3c/json/testing.py
===================================================================
--- z3c.json/trunk/src/z3c/json/testing.py (rev 0)
+++ z3c.json/trunk/src/z3c/json/testing.py 2007-12-05 04:59:16 UTC (rev 82136)
@@ -0,0 +1,30 @@
+##############################################################################
+#
+# Copyright (c) 2007 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.
+#
+##############################################################################
+"""
+$Id:$
+"""
+__docformat__ = "reStructuredText"
+
+import zope.component
+
+from z3c.json import interfaces
+from z3c.json import converter
+
+
+def setUpJSONConverter():
+ zope.component.provideUtility(converter.JSONReader(), interfaces.IJSONReader)
+ zope.component.provideUtility(converter.JSONWriter(), interfaces.IJSONWriter)
+ zope.component.provideAdapter(converter.ListPreMarshaller, (list,))
+ zope.component.provideAdapter(converter.ListPreMarshaller, (tuple,))
+ zope.component.provideAdapter(converter.DictPreMarshaller, (dict,))
Property changes on: z3c.json/trunk/src/z3c/json/testing.py
___________________________________________________________________
Name: svn:eol-style
+ native
Modified: z3c.json/trunk/src/z3c/json/tests.py
===================================================================
--- z3c.json/trunk/src/z3c/json/tests.py 2007-12-04 23:12:02 UTC (rev 82135)
+++ z3c.json/trunk/src/z3c/json/tests.py 2007-12-05 04:59:16 UTC (rev 82136)
@@ -25,7 +25,9 @@
import cgi
import pprint
-from zope.app.testing import ztapi
+import zope.component
+from zope.testing import doctest
+from zope.testing.doctestunit import DocFileSuite
from z3c.json import minjson as json
from z3c.json.minjson import ReadException
@@ -624,8 +626,8 @@
class JSONRPCProxyLiveTester(unittest.TestCase):
def setUp(self):
- ztapi.provideUtility(IJSONWriter, JSONWriter())
- ztapi.provideUtility(IJSONReader, JSONReader())
+ zope.component.provideUtility(JSONWriter(), IJSONWriter)
+ zope.component.provideUtility(JSONReader(), IJSONReader)
setUpServer(self)
@@ -750,6 +752,9 @@
def test_suite():
return unittest.TestSuite((
+ DocFileSuite('README.txt',
+ optionflags=doctest.NORMALIZE_WHITESPACE|doctest.ELLIPSIS,
+ ),
unittest.makeSuite(JSONTests),
unittest.makeSuite(JSONRPCProxyLiveTester),
))
More information about the Checkins
mailing list