# -*- coding: iso-8859-1 -*- """ MoinMoin - MoinMoin.wikixml.marshal Tests @copyright: 2002-2004 by Jürgen Hermann @license: GNU GPL, see COPYING for details. """ import unittest import array from MoinMoin.wikixml import marshal class MarshalTestCase(unittest.TestCase): """Testing Marshal used for ...XXX""" class Data: cvar = 'Class Variable' def __init__(self, value): self.ivar = value prop = ( # value, xml representation in a marshal object (None, ''), ("string", 'string'), ([1, "abc"], '1abc'), ((1, "abc"), '1abc'), ({"abc": 1}, '1'), (1, '1'), (Data('value'), 'value'), (array.array("i", [42]), "array('i', [42])"), (buffer("0123456789", 2, 3),"234"), ) def setUp(self): self.obj = marshal.Marshal() def testCreateMarshal(self): """wikixml.marshal: create new marshal""" self._checkData(self.obj, '') def testSetMarshalProperty(self): """wikixml.marshal: setting marshal property""" for value, xml in self.prop: self.obj.prop = value self._checkData(self.obj, xml) def _canonize(self, xml): xml = xml.replace('\n', '') return xml def _checkData(self, obj, xml): objXML = self._canonize(obj.toXML()) expected = self._canonize(xml) self.assertEqual(objXML, expected, 'Expected "%(expected)s" but got "%(objXML)s"' % locals())