[Moin-devel] CVS: MoinMoin/_tests .cvsignore,NONE,1.1 __init__.py,NONE,1.1 test_marshal.py,NONE,1.1
J?rgen Hermann
jhermann at users.sourceforge.net
Tue May 14 13:25:03 EDT 2002
Update of /cvsroot/moin/MoinMoin/_tests
In directory usw-pr-cvs1:/tmp/cvs-serv18227/MoinMoin/_tests
Added Files:
.cvsignore __init__.py test_marshal.py
Log Message:
XML serialization and unit tests
--- NEW FILE: .cvsignore ---
*.pyc
--- NEW FILE: __init__.py ---
"""
MoinMoin - Unit tests
Copyright (c) 2002 by Jürgen Hermann <jh at web.de>
All rights reserved, see COPYING for details.
Subpackage containing all unit tests. This is currently NOT
installed.
$Id: __init__.py,v 1.1 2002/05/14 20:24:55 jhermann Exp $
"""
import unittest
def makeSuite():
from MoinMoin._tests import test_marshal
suite = unittest.TestSuite()
suite.addTests([
test_marshal.makeSuite(),
])
return suite
def run():
suite = makeSuite()
unittest.TextTestRunner(verbosity=2).run(suite)
--- NEW FILE: test_marshal.py ---
"""
MoinMoin - MoinMoin.wikixml.marshal Tests
Copyright (c) 2002 by Jürgen Hermann <jh at web.de>
All rights reserved, see COPYING for details.
$Id: test_marshal.py,v 1.1 2002/05/14 20:24:55 jhermann Exp $
"""
import unittest
from MoinMoin.wikixml import marshal
class MarshalTestCase(unittest.TestCase):
def _canonize(self, xml):
xml = xml.replace('\n', '')
return xml
def _checkData(self, data, xml):
xml1 = self._canonize(data.toXML())
xml2 = self._canonize(xml)
self.failUnlessEqual(xml1, xml2)
def runTest(self):
obj = marshal.Marshal()
self._checkData(obj, '<data></data>')
obj.prop = None
self._checkData(obj, '<data><prop><none/></prop></data>')
obj.prop = "abc"
self._checkData(obj, '<data><prop>abc</prop></data>')
obj.prop = [1, "abc"]
self._checkData(obj, '<data><prop><item>1</item><item>abc</item></prop></data>')
obj.prop = (1, "abc")
self._checkData(obj, '<data><prop><item>1</item><item>abc</item></prop></data>')
obj.prop = {"abc": 1}
self._checkData(obj, '<data><prop><abc>1</abc></prop></data>')
obj.prop = 1
self._checkData(obj, '<data><prop>1</prop></data>')
class TestData:
x = 1
def __init__(self):
self.y = 2
obj.prop = TestData()
self._checkData(obj, '<data><prop><data><y>2</y></data></prop></data>')
import array
obj.prop = array.array("i", [42])
self._checkData(obj, "<data><prop>array('i', [42])</prop></data>")
obj.prop = buffer("0123456789", 2, 3)
self._checkData(obj, "<data><prop>234</prop></data>")
def makeSuite():
suite = unittest.TestSuite()
suite.addTest(MarshalTestCase())
return suite
More information about the Moin-devel
mailing list