Make tests/text_quotations_test.py compatible with Python 3.
This commit is contained in:
@@ -10,6 +10,7 @@ import email.iterators
|
|||||||
from talon import quotations
|
from talon import quotations
|
||||||
import six
|
import six
|
||||||
from six.moves import range
|
from six.moves import range
|
||||||
|
from six import StringIO
|
||||||
|
|
||||||
|
|
||||||
@patch.object(quotations, 'MAX_LINES_COUNT', 1)
|
@patch.object(quotations, 'MAX_LINES_COUNT', 1)
|
||||||
@@ -665,6 +666,15 @@ def test_preprocess_postprocess_2_links():
|
|||||||
eq_(msg_body, quotations.extract_from_plain(msg_body))
|
eq_(msg_body, quotations.extract_from_plain(msg_body))
|
||||||
|
|
||||||
|
|
||||||
|
def body_iterator(msg, decode=False):
|
||||||
|
for subpart in msg.walk():
|
||||||
|
payload = subpart.get_payload(decode=decode)
|
||||||
|
if isinstance(payload, six.text_type):
|
||||||
|
yield payload
|
||||||
|
else:
|
||||||
|
yield payload.decode('utf8')
|
||||||
|
|
||||||
|
|
||||||
def test_standard_replies():
|
def test_standard_replies():
|
||||||
for filename in os.listdir(STANDARD_REPLIES):
|
for filename in os.listdir(STANDARD_REPLIES):
|
||||||
filename = os.path.join(STANDARD_REPLIES, filename)
|
filename = os.path.join(STANDARD_REPLIES, filename)
|
||||||
@@ -673,7 +683,7 @@ def test_standard_replies():
|
|||||||
with open(filename) as f:
|
with open(filename) as f:
|
||||||
message = email.message_from_file(f)
|
message = email.message_from_file(f)
|
||||||
body = next(email.iterators.typed_subpart_iterator(message, subtype='plain'))
|
body = next(email.iterators.typed_subpart_iterator(message, subtype='plain'))
|
||||||
text = ''.join(email.iterators.body_line_iterator(body, True))
|
text = ''.join(body_iterator(body, True))
|
||||||
|
|
||||||
stripped_text = quotations.extract_from_plain(text)
|
stripped_text = quotations.extract_from_plain(text)
|
||||||
reply_text_fn = filename[:-4] + '_reply_text'
|
reply_text_fn = filename[:-4] + '_reply_text'
|
||||||
|
|||||||
Reference in New Issue
Block a user