PyXR

c:\python24\lib \ test \ test_quopri.py



0001 from test import test_support
0002 import unittest
0003 
0004 from cStringIO import StringIO
0005 from quopri import *
0006 
0007 
0008 
0009 ENCSAMPLE = """\
0010 Here's a bunch of special=20
0011 
0012 =A1=A2=A3=A4=A5=A6=A7=A8=A9
0013 =AA=AB=AC=AD=AE=AF=B0=B1=B2=B3
0014 =B4=B5=B6=B7=B8=B9=BA=BB=BC=BD=BE
0015 =BF=C0=C1=C2=C3=C4=C5=C6
0016 =C7=C8=C9=CA=CB=CC=CD=CE=CF
0017 =D0=D1=D2=D3=D4=D5=D6=D7
0018 =D8=D9=DA=DB=DC=DD=DE=DF
0019 =E0=E1=E2=E3=E4=E5=E6=E7
0020 =E8=E9=EA=EB=EC=ED=EE=EF
0021 =F0=F1=F2=F3=F4=F5=F6=F7
0022 =F8=F9=FA=FB=FC=FD=FE=FF
0023 
0024 characters... have fun!
0025 """
0026 
0027 # First line ends with a space
0028 DECSAMPLE = "Here's a bunch of special \n" + \
0029 """\
0030 
0031 \xa1\xa2\xa3\xa4\xa5\xa6\xa7\xa8\xa9
0032 \xaa\xab\xac\xad\xae\xaf\xb0\xb1\xb2\xb3
0033 \xb4\xb5\xb6\xb7\xb8\xb9\xba\xbb\xbc\xbd\xbe
0034 \xbf\xc0\xc1\xc2\xc3\xc4\xc5\xc6
0035 \xc7\xc8\xc9\xca\xcb\xcc\xcd\xce\xcf
0036 \xd0\xd1\xd2\xd3\xd4\xd5\xd6\xd7
0037 \xd8\xd9\xda\xdb\xdc\xdd\xde\xdf
0038 \xe0\xe1\xe2\xe3\xe4\xe5\xe6\xe7
0039 \xe8\xe9\xea\xeb\xec\xed\xee\xef
0040 \xf0\xf1\xf2\xf3\xf4\xf5\xf6\xf7
0041 \xf8\xf9\xfa\xfb\xfc\xfd\xfe\xff
0042 
0043 characters... have fun!
0044 """
0045 
0046 
0047 
0048 class QuopriTestCase(unittest.TestCase):
0049     # Each entry is a tuple of (plaintext, encoded string).  These strings are
0050     # used in the "quotetabs=0" tests.
0051     STRINGS = (
0052         # Some normal strings
0053         ('hello', 'hello'),
0054         ('''hello
0055         there
0056         world''', '''hello
0057         there
0058         world'''),
0059         ('''hello
0060         there
0061         world
0062 ''', '''hello
0063         there
0064         world
0065 '''),
0066         ('\201\202\203', '=81=82=83'),
0067         # Add some trailing MUST QUOTE strings
0068         ('hello ', 'hello=20'),
0069         ('hello\t', 'hello=09'),
0070         # Some long lines.  First, a single line of 108 characters
0071         ('xxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxx\xd8\xd9\xda\xdb\xdc\xdd\xde\xdfxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxx',
0072          '''xxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxx=D8=D9=DA=DB=DC=DD=DE=DFx=
0073 xxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxx'''),
0074         # A line of exactly 76 characters, no soft line break should be needed
0075         ('yyyyyyyyyyyyyyyyyyyyyyyyyyyyyyyyyyyyyyyyyyyyyyyyyyyyyyyyyyyyyyyyyyyyyyyyyyyy',
0076         'yyyyyyyyyyyyyyyyyyyyyyyyyyyyyyyyyyyyyyyyyyyyyyyyyyyyyyyyyyyyyyyyyyyyyyyyyyyy'),
0077         # A line of 77 characters, forcing a soft line break at position 75,
0078         # and a second line of exactly 2 characters (because the soft line
0079         # break `=' sign counts against the line length limit).
0080         ('zzzzzzzzzzzzzzzzzzzzzzzzzzzzzzzzzzzzzzzzzzzzzzzzzzzzzzzzzzzzzzzzzzzzzzzzzzzzz',
0081          '''zzzzzzzzzzzzzzzzzzzzzzzzzzzzzzzzzzzzzzzzzzzzzzzzzzzzzzzzzzzzzzzzzzzzzzzzzzz=
0082 zz'''),
0083         # A line of 151 characters, forcing a soft line break at position 75,
0084         # with a second line of exactly 76 characters and no trailing =
0085         ('zzzzzzzzzzzzzzzzzzzzzzzzzzzzzzzzzzzzzzzzzzzzzzzzzzzzzzzzzzzzzzzzzzzzzzzzzzzzzzzzzzzzzzzzzzzzzzzzzzzzzzzzzzzzzzzzzzzzzzzzzzzzzzzzzzzzzzzzzzzzzzzzzzzzzzz',
0086          '''zzzzzzzzzzzzzzzzzzzzzzzzzzzzzzzzzzzzzzzzzzzzzzzzzzzzzzzzzzzzzzzzzzzzzzzzzzz=
0087 zzzzzzzzzzzzzzzzzzzzzzzzzzzzzzzzzzzzzzzzzzzzzzzzzzzzzzzzzzzzzzzzzzzzzzzzzzzz'''),
0088         # A string containing a hard line break, but which the first line is
0089         # 151 characters and the second line is exactly 76 characters.  This
0090         # should leave us with three lines, the first which has a soft line
0091         # break, and which the second and third do not.
0092         ('''yyyyyyyyyyyyyyyyyyyyyyyyyyyyyyyyyyyyyyyyyyyyyyyyyyyyyyyyyyyyyyyyyyyyyyyyyyyyyyyyyyyyyyyyyyyyyyyyyyyyyyyyyyyyyyyyyyyyyyyyyyyyyyyyyyyyyyyyyyyyyyyyyyyyyyy
0093 zzzzzzzzzzzzzzzzzzzzzzzzzzzzzzzzzzzzzzzzzzzzzzzzzzzzzzzzzzzzzzzzzzzzzzzzzzzz''',
0094          '''yyyyyyyyyyyyyyyyyyyyyyyyyyyyyyyyyyyyyyyyyyyyyyyyyyyyyyyyyyyyyyyyyyyyyyyyyyy=
0095 yyyyyyyyyyyyyyyyyyyyyyyyyyyyyyyyyyyyyyyyyyyyyyyyyyyyyyyyyyyyyyyyyyyyyyyyyyyy
0096 zzzzzzzzzzzzzzzzzzzzzzzzzzzzzzzzzzzzzzzzzzzzzzzzzzzzzzzzzzzzzzzzzzzzzzzzzzzz'''),
0097         # Now some really complex stuff ;)
0098         (DECSAMPLE, ENCSAMPLE),
0099         )
0100 
0101     # These are used in the "quotetabs=1" tests.
0102     ESTRINGS = (
0103         ('hello world', 'hello=20world'),
0104         ('hello\tworld', 'hello=09world'),
0105         )
0106 
0107     # These are used in the "header=1" tests.
0108     HSTRINGS = (
0109         ('hello world', 'hello_world'),
0110         ('hello_world', 'hello=5Fworld'),
0111         )
0112 
0113     def test_encodestring(self):
0114         for p, e in self.STRINGS:
0115             self.assert_(encodestring(p) == e)
0116 
0117     def test_decodestring(self):
0118         for p, e in self.STRINGS:
0119             self.assert_(decodestring(e) == p)
0120 
0121     def test_idempotent_string(self):
0122         for p, e in self.STRINGS:
0123             self.assert_(decodestring(encodestring(e)) == e)
0124 
0125     def test_encode(self):
0126         for p, e in self.STRINGS:
0127             infp = StringIO(p)
0128             outfp = StringIO()
0129             encode(infp, outfp, quotetabs=0)
0130             self.assert_(outfp.getvalue() == e)
0131 
0132     def test_decode(self):
0133         for p, e in self.STRINGS:
0134             infp = StringIO(e)
0135             outfp = StringIO()
0136             decode(infp, outfp)
0137             self.assert_(outfp.getvalue() == p)
0138 
0139     def test_embedded_ws(self):
0140         for p, e in self.ESTRINGS:
0141             self.assert_(encodestring(p, quotetabs=1) == e)
0142             self.assert_(decodestring(e) == p)
0143 
0144     def test_encode_header(self):
0145         for p, e in self.HSTRINGS:
0146             self.assert_(encodestring(p, header = 1) == e)
0147 
0148     def test_decode_header(self):
0149         for p, e in self.HSTRINGS:
0150             self.assert_(decodestring(e, header = 1) == p)
0151 
0152 def test_main():
0153     test_support.run_unittest(QuopriTestCase)
0154 
0155 
0156 if __name__ == "__main__":
0157     test_main()
0158 

Generated by PyXR 0.9.4
SourceForge.net Logo