view MoinMoin/_tests/test_error.py @ 0:77665d8e2254

tag of nonpublic@localhost--archive/moin--enterprise--1.5--base-0 (automatically generated log message) imported from: moin--main--1.5--base-0
author Thomas Waldmann <tw-public@gmx.de>
date Thu, 22 Sep 2005 15:09:50 +0000
parents
children 9931a09387b0
line wrap: on
line source

# -*- coding: utf-8 -*-
"""
    MoinMoin - MoinMoin.error Tests

@copyright: 2003-2004 by Nir Soffer <nirs AT freeshell DOT org>
@license: GNU GPL, see COPYING for details.
"""

import unittest
from MoinMoin import error
from MoinMoin._tests import TestConfig


class EncodingTestCase(unittest.TestCase):
    """ MoinMoin errors do work with unicode transparently """

    def testCreateWithUnicode(self):
        """ error: create with unicode """
        err = error.Error(u'טעות')
        self.assertEqual(unicode(err), u'טעות')
        self.assertEqual(str(err), 'טעות')
        
    def testCreateWithEncodedString(self):
        """ error: create with encoded string """
        err = error.Error('טעות')
        self.assertEqual(unicode(err), u'טעות')
        self.assertEqual(str(err), 'טעות')
         
    def testCreateWithObject(self):
        """ error: create with any object """
        class Foo:
            def __unicode__(self):
                return u'טעות'
            def __str__(self):
                return 'טעות'
        
        err = error.Error(Foo())
        self.assertEqual(unicode(err), u'טעות')
        self.assertEqual(str(err), 'טעות')
         
    def testAccessLikeDict(self):
        """ error: access error like a dict """
        test = 'value'
        err = error.Error(test)
        self.assertEqual('%(message)s' % err, test)