Back to index

plone3  3.1.7
test_encoding.py
Go to the documentation of this file.
00001 """
00002     Encoding tests.
00003 """
00004 
00005 import unittest
00006 
00007 def test_encoding():
00008     r"""
00009     Test message encoding:
00010 
00011       >>> from Products.statusmessages.message import Message
00012       >>> from Products.statusmessages.message import decode
00013 
00014       >>> m = Message(u'spam', u'eggs')
00015       >>> m.encode()
00016       '\x00\x84spameggs'
00017 
00018       >>> decode(m.encode())[0] == m
00019       True
00020 
00021       >>> m = Message(u'spam')
00022       >>> m.encode()
00023       '\x00\x80spam'
00024 
00025       >>> decode(m.encode())[0] == m
00026       True
00027     """
00028 
00029 def test_decoding():
00030     r"""
00031     Test message decoding:
00032 
00033       >>> from Products.statusmessages.message import Message
00034       >>> from Products.statusmessages.message import decode
00035 
00036     Craft a wrong value:
00037 
00038       >>> m, rem = decode('\x01\x84spameggs')
00039       >>> m.message, m.type
00040       (u'spameggs', u'')
00041 
00042       >>> rem
00043       ''
00044 
00045     Craft another wrong value:
00046 
00047       >>> m, rem = decode('\x00\x24spameggs')
00048       >>> m.message, m.type
00049       (u's', u'pame')
00050 
00051       >>> rem
00052       'ggs'
00053 
00054     And another wrong value:
00055 
00056       >>> m, rem = decode('\x00spameggs')
00057       >>> m.message, m.type
00058       (u'pam', u'eggs')
00059 
00060       >>> rem
00061       ''
00062 
00063     And yet another wrong value:
00064 
00065       >>> m, rem = decode('')
00066       >>> m is None, rem is ''
00067       (True, True)
00068     """
00069 
00070 
00071 def test_suite():
00072     from Testing.ZopeTestCase import ZopeDocTestSuite
00073     return ZopeDocTestSuite()
00074 
00075 if __name__ == '__main__':
00076     unittest.main(defaultTest="test_suite")