1
from test import test_support
4
from cStringIO import StringIO
10
Here's a bunch of special=20
12
=A1=A2=A3=A4=A5=A6=A7=A8=A9
13
=AA=AB=AC=AD=AE=AF=B0=B1=B2=B3
14
=B4=B5=B6=B7=B8=B9=BA=BB=BC=BD=BE
15
=BF=C0=C1=C2=C3=C4=C5=C6
16
=C7=C8=C9=CA=CB=CC=CD=CE=CF
17
=D0=D1=D2=D3=D4=D5=D6=D7
18
=D8=D9=DA=DB=DC=DD=DE=DF
19
=E0=E1=E2=E3=E4=E5=E6=E7
20
=E8=E9=EA=EB=EC=ED=EE=EF
21
=F0=F1=F2=F3=F4=F5=F6=F7
22
=F8=F9=FA=FB=FC=FD=FE=FF
24
characters... have fun!
27
# First line ends with a space
28
DECSAMPLE = "Here's a bunch of special \n" + \
31
\xa1\xa2\xa3\xa4\xa5\xa6\xa7\xa8\xa9
32
\xaa\xab\xac\xad\xae\xaf\xb0\xb1\xb2\xb3
33
\xb4\xb5\xb6\xb7\xb8\xb9\xba\xbb\xbc\xbd\xbe
34
\xbf\xc0\xc1\xc2\xc3\xc4\xc5\xc6
35
\xc7\xc8\xc9\xca\xcb\xcc\xcd\xce\xcf
36
\xd0\xd1\xd2\xd3\xd4\xd5\xd6\xd7
37
\xd8\xd9\xda\xdb\xdc\xdd\xde\xdf
38
\xe0\xe1\xe2\xe3\xe4\xe5\xe6\xe7
39
\xe8\xe9\xea\xeb\xec\xed\xee\xef
40
\xf0\xf1\xf2\xf3\xf4\xf5\xf6\xf7
41
\xf8\xf9\xfa\xfb\xfc\xfd\xfe\xff
43
characters... have fun!
48
class QuopriTestCase(unittest.TestCase):
49
# Each entry is a tuple of (plaintext, encoded string). These strings are
50
# used in the "quotetabs=0" tests.
66
('\201\202\203', '=81=82=83'),
67
# Add some trailing MUST QUOTE strings
68
('hello ', 'hello=20'),
69
('hello\t', 'hello=09'),
70
# Some long lines. First, a single line of 108 characters
71
('xxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxx\xd8\xd9\xda\xdb\xdc\xdd\xde\xdfxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxx',
72
'''xxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxx=D8=D9=DA=DB=DC=DD=DE=DFx=
73
xxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxx'''),
74
# A line of exactly 76 characters, no soft line break should be needed
75
('yyyyyyyyyyyyyyyyyyyyyyyyyyyyyyyyyyyyyyyyyyyyyyyyyyyyyyyyyyyyyyyyyyyyyyyyyyyy',
76
'yyyyyyyyyyyyyyyyyyyyyyyyyyyyyyyyyyyyyyyyyyyyyyyyyyyyyyyyyyyyyyyyyyyyyyyyyyyy'),
77
# A line of 77 characters, forcing a soft line break at position 75,
78
# and a second line of exactly 2 characters (because the soft line
79
# break `=' sign counts against the line length limit).
80
('zzzzzzzzzzzzzzzzzzzzzzzzzzzzzzzzzzzzzzzzzzzzzzzzzzzzzzzzzzzzzzzzzzzzzzzzzzzzz',
81
'''zzzzzzzzzzzzzzzzzzzzzzzzzzzzzzzzzzzzzzzzzzzzzzzzzzzzzzzzzzzzzzzzzzzzzzzzzzz=
83
# A line of 151 characters, forcing a soft line break at position 75,
84
# with a second line of exactly 76 characters and no trailing =
85
('zzzzzzzzzzzzzzzzzzzzzzzzzzzzzzzzzzzzzzzzzzzzzzzzzzzzzzzzzzzzzzzzzzzzzzzzzzzzzzzzzzzzzzzzzzzzzzzzzzzzzzzzzzzzzzzzzzzzzzzzzzzzzzzzzzzzzzzzzzzzzzzzzzzzzzz',
86
'''zzzzzzzzzzzzzzzzzzzzzzzzzzzzzzzzzzzzzzzzzzzzzzzzzzzzzzzzzzzzzzzzzzzzzzzzzzz=
87
zzzzzzzzzzzzzzzzzzzzzzzzzzzzzzzzzzzzzzzzzzzzzzzzzzzzzzzzzzzzzzzzzzzzzzzzzzzz'''),
88
# A string containing a hard line break, but which the first line is
89
# 151 characters and the second line is exactly 76 characters. This
90
# should leave us with three lines, the first which has a soft line
91
# break, and which the second and third do not.
92
('''yyyyyyyyyyyyyyyyyyyyyyyyyyyyyyyyyyyyyyyyyyyyyyyyyyyyyyyyyyyyyyyyyyyyyyyyyyyyyyyyyyyyyyyyyyyyyyyyyyyyyyyyyyyyyyyyyyyyyyyyyyyyyyyyyyyyyyyyyyyyyyyyyyyyyyy
93
zzzzzzzzzzzzzzzzzzzzzzzzzzzzzzzzzzzzzzzzzzzzzzzzzzzzzzzzzzzzzzzzzzzzzzzzzzzz''',
94
'''yyyyyyyyyyyyyyyyyyyyyyyyyyyyyyyyyyyyyyyyyyyyyyyyyyyyyyyyyyyyyyyyyyyyyyyyyyy=
95
yyyyyyyyyyyyyyyyyyyyyyyyyyyyyyyyyyyyyyyyyyyyyyyyyyyyyyyyyyyyyyyyyyyyyyyyyyyy
96
zzzzzzzzzzzzzzzzzzzzzzzzzzzzzzzzzzzzzzzzzzzzzzzzzzzzzzzzzzzzzzzzzzzzzzzzzzzz'''),
97
# Now some really complex stuff ;)
98
(DECSAMPLE, ENCSAMPLE),
101
# These are used in the "quotetabs=1" tests.
103
('hello world', 'hello=20world'),
104
('hello\tworld', 'hello=09world'),
107
# These are used in the "header=1" tests.
109
('hello world', 'hello_world'),
110
('hello_world', 'hello=5Fworld'),
113
def test_encodestring(self):
114
for p, e in self.STRINGS:
115
self.assert_(encodestring(p) == e)
117
def test_decodestring(self):
118
for p, e in self.STRINGS:
119
self.assert_(decodestring(e) == p)
121
def test_idempotent_string(self):
122
for p, e in self.STRINGS:
123
self.assert_(decodestring(encodestring(e)) == e)
125
def test_encode(self):
126
for p, e in self.STRINGS:
129
encode(infp, outfp, quotetabs=0)
130
self.assert_(outfp.getvalue() == e)
132
def test_decode(self):
133
for p, e in self.STRINGS:
137
self.assert_(outfp.getvalue() == p)
139
def test_embedded_ws(self):
140
for p, e in self.ESTRINGS:
141
self.assert_(encodestring(p, quotetabs=1) == e)
142
self.assert_(decodestring(e) == p)
144
def test_encode_header(self):
145
for p, e in self.HSTRINGS:
146
self.assert_(encodestring(p, header = 1) == e)
148
def test_decode_header(self):
149
for p, e in self.HSTRINGS:
150
self.assert_(decodestring(e, header = 1) == p)
153
test_support.run_unittest(QuopriTestCase)
156
if __name__ == "__main__":