Back to index

moin  1.9.0~rc2
test_marshal.py
Go to the documentation of this file.
00001 # -*- coding: iso-8859-1 -*-
00002 """
00003     MoinMoin - MoinMoin.wikixml.marshal Tests
00004 
00005     @copyright: 2002-2004 by Juergen Hermann <jh@web.de>,
00006                 2007 by MoinMoin:ThomasWaldmann
00007     @license: GNU GPL, see COPYING for details.
00008 """
00009 
00010 import array
00011 from MoinMoin.wikixml import marshal
00012 
00013 class TestMarshal(object):
00014     """Testing Marshal used for ...XXX"""
00015 
00016     class Data:
00017         cvar = 'Class Variable'
00018         def __init__(self, value):
00019             self.ivar = value
00020 
00021     prop = (
00022         # value, xml representation in a marshal object
00023         (None, '<data><prop><none/></prop></data>'),
00024         ("string", '<data><prop>string</prop></data>'),
00025         ([1, "abc"], '<data><prop><item>1</item><item>abc</item></prop></data>'),
00026         ((1, "abc"), '<data><prop><item>1</item><item>abc</item></prop></data>'),
00027         ({"abc": 1}, '<data><prop><abc>1</abc></prop></data>'),
00028         (1, '<data><prop>1</prop></data>'),
00029         (Data('value'), '<data><prop><data><ivar>value</ivar></data></prop></data>'),
00030         (array.array("i", [42]), "<data><prop>array('i', [42])</prop></data>"),
00031         (buffer("0123456789", 2, 3), "<data><prop>234</prop></data>"),
00032         )
00033 
00034     def setup_method(self, method):
00035         self.obj = marshal.Marshal()
00036 
00037     def testCreateMarshal(self):
00038         """wikixml.marshal: create new marshal"""
00039         self._checkData(self.obj, '<data></data>')
00040 
00041     def testSetMarshalProperty(self):
00042         """wikixml.marshal: setting marshal property"""
00043         for value, xml in self.prop:
00044             self.obj.prop = value
00045             self._checkData(self.obj, xml)
00046 
00047     def _canonize(self, xml):
00048         xml = xml.replace('\n', '')
00049         return xml
00050 
00051     def _checkData(self, obj, xml):
00052         objXML = self._canonize(obj.toXML())
00053         expected = self._canonize(xml)
00054         assert objXML == expected
00055 
00056 
00057 coverage_modules = ['MoinMoin.wikixml.marshal']
00058