view MoinMoin/_tests/ @ 2006:1339d6fdc4ff

Changed tests to use py.test. Also changed the semantics a bit - the test wiki directory is only created freshly if it does not exist.
author Alexander Schremmer <alex AT alexanderweb DOT de>
date Fri, 20 Apr 2007 00:12:50 +0200
parents bb2e053067fb
children ff428fa12e3c
line wrap: on
line source
# -*- coding: iso-8859-1 -*-
    MoinMoin - MoinMoin.wikixml.marshal Tests

    @copyright: 2002-2004 by Juergen Hermann <>
    @license: GNU GPL, see COPYING for details.

import unittest
import array
from MoinMoin.wikixml import marshal

class TestMarshal(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, '<data><prop><none/></prop></data>'),
        ("string", '<data><prop>string</prop></data>'),
        ([1, "abc"], '<data><prop><item>1</item><item>abc</item></prop></data>'),
        ((1, "abc"), '<data><prop><item>1</item><item>abc</item></prop></data>'),
        ({"abc": 1}, '<data><prop><abc>1</abc></prop></data>'),
        (1, '<data><prop>1</prop></data>'),
        (Data('value'), '<data><prop><data><ivar>value</ivar></data></prop></data>'),
        (array.array("i", [42]), "<data><prop>array('i', [42])</prop></data>"),
        (buffer("0123456789", 2, 3), "<data><prop>234</prop></data>"),

    def setUp(self):
        self.obj = marshal.Marshal()

    def testCreateMarshal(self):
        """wikixml.marshal: create new marshal"""
        self._checkData(self.obj, '<data></data>')

    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())