summaryrefslogtreecommitdiffstats
path: root/Lib/email/test
diff options
context:
space:
mode:
authorR David Murray <rdmurray@bitdance.com>2011-03-24 16:19:26 (GMT)
committerR David Murray <rdmurray@bitdance.com>2011-03-24 16:19:26 (GMT)
commitb938c8c25316b69f1d5df2c7880a9f6b87e7c2fa (patch)
treeb46f58b371152a639e294676f2d6f0c329828b78 /Lib/email/test
parent29943aa120adf77407504ca6421bd13af922c93e (diff)
downloadcpython-b938c8c25316b69f1d5df2c7880a9f6b87e7c2fa.zip
cpython-b938c8c25316b69f1d5df2c7880a9f6b87e7c2fa.tar.gz
cpython-b938c8c25316b69f1d5df2c7880a9f6b87e7c2fa.tar.bz2
#11606: improved body_encode algorithm, no longer produces overlong lines
Algorithm and initial patch by Michael Henry.
Diffstat (limited to 'Lib/email/test')
-rw-r--r--Lib/email/test/test_email.py19
1 files changed, 18 insertions, 1 deletions
diff --git a/Lib/email/test/test_email.py b/Lib/email/test/test_email.py
index cb3b0b3..d602913 100644
--- a/Lib/email/test/test_email.py
+++ b/Lib/email/test/test_email.py
@@ -3041,6 +3041,14 @@ class TestQuopri(unittest.TestCase):
def test_encode_one_line_one_space(self):
self._test_encode(' \n', '=20\n')
+# XXX: body_encode() expect strings, but uses ord(char) from these strings
+# to index into a 256-entry list. For code points above 255, this will fail.
+# Should there be a check for 8-bit only ord() values in body, or at least
+# a comment about the expected input?
+
+ def test_encode_two_lines_one_space(self):
+ self._test_encode(' \n \n', '=20\n=20\n')
+
def test_encode_one_word_trailing_spaces(self):
self._test_encode('hello ', 'hello =20')
@@ -3056,8 +3064,14 @@ class TestQuopri(unittest.TestCase):
def test_encode_trailing_space_before_maxlinelen(self):
self._test_encode('abcd \n1234', 'abcd =\n\n1234', maxlinelen=6)
+ def test_encode_trailing_space_at_maxlinelen(self):
+ self._test_encode('abcd \n1234', 'abcd=\n=20\n1234', maxlinelen=5)
+
def test_encode_trailing_space_beyond_maxlinelen(self):
- self._test_encode('abcd \n1234', 'abc=\nd =\n\n1234', maxlinelen=4)
+ self._test_encode('abcd \n1234', 'abc=\nd=20\n1234', maxlinelen=4)
+
+ def test_encode_whitespace_lines(self):
+ self._test_encode(' \n' * 5, '=20\n' * 5)
def test_encode_quoted_equals(self):
self._test_encode('a = b', 'a =3D b')
@@ -3078,6 +3092,9 @@ class TestQuopri(unittest.TestCase):
def test_encode_shortest_maxlinelen(self):
self._test_encode('=' * 5, '=3D=\n' * 4 + '=3D', maxlinelen=4)
+ def test_encode_maxlinelen_too_small(self):
+ self.assertRaises(ValueError, self._test_encode, '', '', maxlinelen=3)
+
def test_encode(self):
eq = self.assertEqual
eq(quoprimime.body_encode(''), '')