diff options
author | Cheryl Sabella <cheryl.sabella@gmail.com> | 2018-10-19 00:21:47 (GMT) |
---|---|---|
committer | R. David Murray <rdmurray@bitdance.com> | 2018-10-19 00:21:47 (GMT) |
commit | d16f012f842e5719ff9fb90e217efc0f795853f2 (patch) | |
tree | 669ff81719b7c64c559a6347080f79e44677f891 /Lib/test/test_mailbox.py | |
parent | 5be00247ae0de2e24dd14bbe4d9ca159434a1710 (diff) | |
download | cpython-d16f012f842e5719ff9fb90e217efc0f795853f2.zip cpython-d16f012f842e5719ff9fb90e217efc0f795853f2.tar.gz cpython-d16f012f842e5719ff9fb90e217efc0f795853f2.tar.bz2 |
bpo-31522: mailbox.get_string: pass `from_` parameter to `get_bytes` (#9857)
This allows *from_* to be successfully set to a non-default value when calling mbox.get_string.
Diffstat (limited to 'Lib/test/test_mailbox.py')
-rw-r--r-- | Lib/test/test_mailbox.py | 28 |
1 files changed, 28 insertions, 0 deletions
diff --git a/Lib/test/test_mailbox.py b/Lib/test/test_mailbox.py index 3807b95..a75c8cb 100644 --- a/Lib/test/test_mailbox.py +++ b/Lib/test/test_mailbox.py @@ -988,6 +988,34 @@ class _TestMboxMMDF(_TestSingleFile): with open(self._path) as f: self.assertEqual(f.readlines(), []) + def test_get_bytes_from(self): + # Get bytes representations of messages with _unixfrom. + unixfrom = 'From foo@bar blah\n' + key0 = self._box.add(unixfrom + self._template % 0) + key1 = self._box.add(unixfrom + _sample_message) + self.assertEqual(self._box.get_bytes(key0, from_=False), + (self._template % 0).encode('ascii')) + self.assertEqual(self._box.get_bytes(key1, from_=False), + _bytes_sample_message) + self.assertEqual(self._box.get_bytes(key0, from_=True), + (unixfrom + self._template % 0).encode('ascii')) + self.assertEqual(self._box.get_bytes(key1, from_=True), + unixfrom.encode('ascii') + _bytes_sample_message) + + def test_get_string_from(self): + # Get string representations of messages with _unixfrom. + unixfrom = 'From foo@bar blah\n' + key0 = self._box.add(unixfrom + self._template % 0) + key1 = self._box.add(unixfrom + _sample_message) + self.assertEqual(self._box.get_string(key0, from_=False), + self._template % 0) + self.assertEqual(self._box.get_string(key1, from_=False).split('\n'), + _sample_message.split('\n')) + self.assertEqual(self._box.get_string(key0, from_=True), + unixfrom + self._template % 0) + self.assertEqual(self._box.get_string(key1, from_=True).split('\n'), + (unixfrom + _sample_message).split('\n')) + def test_add_from_string(self): # Add a string starting with 'From ' to the mailbox key = self._box.add('From foo@bar blah\nFrom: foo\n\n0\n') |