bpo-31522: mailbox.get_string: pass `from_` parameter to `get_bytes` … · python/cpython@d16f012

@@ -988,6 +988,34 @@ def assertMailboxEmpty(self):

988988

with open(self._path) as f:

989989

self.assertEqual(f.readlines(), [])

990990991+

def test_get_bytes_from(self):

992+

# Get bytes representations of messages with _unixfrom.

993+

unixfrom = 'From foo@bar blah\n'

994+

key0 = self._box.add(unixfrom + self._template % 0)

995+

key1 = self._box.add(unixfrom + _sample_message)

996+

self.assertEqual(self._box.get_bytes(key0, from_=False),

997+

(self._template % 0).encode('ascii'))

998+

self.assertEqual(self._box.get_bytes(key1, from_=False),

999+

_bytes_sample_message)

1000+

self.assertEqual(self._box.get_bytes(key0, from_=True),

1001+

(unixfrom + self._template % 0).encode('ascii'))

1002+

self.assertEqual(self._box.get_bytes(key1, from_=True),

1003+

unixfrom.encode('ascii') + _bytes_sample_message)

1004+1005+

def test_get_string_from(self):

1006+

# Get string representations of messages with _unixfrom.

1007+

unixfrom = 'From foo@bar blah\n'

1008+

key0 = self._box.add(unixfrom + self._template % 0)

1009+

key1 = self._box.add(unixfrom + _sample_message)

1010+

self.assertEqual(self._box.get_string(key0, from_=False),

1011+

self._template % 0)

1012+

self.assertEqual(self._box.get_string(key1, from_=False).split('\n'),

1013+

_sample_message.split('\n'))

1014+

self.assertEqual(self._box.get_string(key0, from_=True),

1015+

unixfrom + self._template % 0)

1016+

self.assertEqual(self._box.get_string(key1, from_=True).split('\n'),

1017+

(unixfrom + _sample_message).split('\n'))

1018+9911019

def test_add_from_string(self):

9921020

# Add a string starting with 'From ' to the mailbox

9931021

key = self._box.add('From foo@bar blah\nFrom: foo\n\n0\n')