diff --git a/run_tests.sh b/run_tests.sh index 19f1d59d..42d2aca4 100755 --- a/run_tests.sh +++ b/run_tests.sh @@ -1,4 +1,4 @@ #!/usr/bin/env bash set -ex -REPORT_PATH="${REPORT_PATH:-./}" -nosetests --with-xunit --with-coverage --cover-xml --cover-xml-file $REPORT_PATH/coverage.xml --xunit-file=$REPORT_PATH/nosetests.xml --cover-package=talon . +REPORT_PATH="${REPORT_PATH:-.}" +pytest --cov=talon --cov-report=term --cov-report="xml:$REPORT_PATH/coverage.xml" --junitxml="$REPORT_PATH/nosetests.xml" . diff --git a/setup.py b/setup.py index cf8e7e6e..fa1a692d 100755 --- a/setup.py +++ b/setup.py @@ -57,8 +57,7 @@ def finalize_options(self): "joblib", ], tests_require=[ - "mock", - "nose", - "coverage" + "pytest", + "pytest-cov" ] ) diff --git a/test-requirements.txt b/test-requirements.txt index 5f50e2a9..9955decc 100644 --- a/test-requirements.txt +++ b/test-requirements.txt @@ -1,3 +1,2 @@ -coverage -mock -nose>=1.2.1 +pytest +pytest-cov diff --git a/tests/__init__.py b/tests/__init__.py index 8fdebd6b..a39ca71a 100644 --- a/tests/__init__.py +++ b/tests/__init__.py @@ -1,6 +1,5 @@ from __future__ import absolute_import -from nose.tools import * -from mock import * +from unittest.mock import * import talon diff --git a/tests/html_quotations_test.py b/tests/html_quotations_test.py index 85871e73..fa375d32 100644 --- a/tests/html_quotations_test.py +++ b/tests/html_quotations_test.py @@ -6,8 +6,6 @@ import re from unittest.mock import Mock, patch -from nose.tools import assert_false, assert_true, eq_, ok_ - from tests.fixtures import (OLK_SRC_BODY_SECTION, REPLY_QUOTATIONS_SHARE_BLOCK, REPLY_SEPARATED_BY_HR) @@ -31,8 +29,8 @@ def test_quotation_splitter_inside_blockquote(): """ - eq_("Reply", - RE_WHITESPACE.sub('', quotations.extract_from_html(msg_body))) + assert "Reply" == \ + RE_WHITESPACE.sub('', quotations.extract_from_html(msg_body)) def test_quotation_splitter_outside_blockquote(): @@ -48,8 +46,8 @@ def test_quotation_splitter_outside_blockquote(): """ - eq_("Reply", - RE_WHITESPACE.sub('', quotations.extract_from_html(msg_body))) + assert "Reply" == \ + RE_WHITESPACE.sub('', quotations.extract_from_html(msg_body)) def test_regular_blockquote(): @@ -66,8 +64,8 @@ def test_regular_blockquote(): """ - eq_("Reply
Regular
", - RE_WHITESPACE.sub('', quotations.extract_from_html(msg_body))) + assert "Reply
Regular
" == \ + RE_WHITESPACE.sub('', quotations.extract_from_html(msg_body)) def test_no_blockquote(): @@ -94,12 +92,12 @@ def test_no_blockquote(): Reply """ - eq_(RE_WHITESPACE.sub('', reply), - RE_WHITESPACE.sub('', quotations.extract_from_html(msg_body))) + assert RE_WHITESPACE.sub('', reply) == \ + RE_WHITESPACE.sub('', quotations.extract_from_html(msg_body)) def test_empty_body(): - eq_('', quotations.extract_from_html('')) + assert '' == quotations.extract_from_html('') def test_validate_output_html(): @@ -117,10 +115,10 @@ def test_validate_output_html():
""" out = quotations.extract_from_html(msg_body) - ok_('' in out and '' in out, - 'Invalid HTML - / tag not present') - ok_('
' not in out, - 'Invalid HTML output -
element is not valid') + assert '' in out and '' in out, \ + 'Invalid HTML - / tag not present' + assert '
' not in out, \ + 'Invalid HTML output -
element is not valid' def test_gmail_quote(): @@ -133,8 +131,8 @@ def test_gmail_quote():
""" - eq_("Reply", - RE_WHITESPACE.sub('', quotations.extract_from_html(msg_body))) + assert "Reply" == \ + RE_WHITESPACE.sub('', quotations.extract_from_html(msg_body)) def test_gmail_quote_compact(): @@ -144,8 +142,8 @@ def test_gmail_quote_compact(): '
Test
' \ '
' \ '
' - eq_("Reply", - RE_WHITESPACE.sub('', quotations.extract_from_html(msg_body))) + assert "Reply" == \ + RE_WHITESPACE.sub('', quotations.extract_from_html(msg_body)) def test_gmail_quote_blockquote(): @@ -156,8 +154,8 @@ def test_gmail_quote_blockquote():
""" - eq_(RE_WHITESPACE.sub('', msg_body), - RE_WHITESPACE.sub('', quotations.extract_from_html(msg_body))) + assert RE_WHITESPACE.sub('', msg_body) == \ + RE_WHITESPACE.sub('', quotations.extract_from_html(msg_body)) def test_unicode_in_reply(): @@ -171,9 +169,9 @@ def test_unicode_in_reply(): Quote """ - eq_("Reply  Text

" - "", - RE_WHITESPACE.sub('', quotations.extract_from_html(msg_body))) + assert "Reply  Text

" \ + "" == \ + RE_WHITESPACE.sub('', quotations.extract_from_html(msg_body)) def test_blockquote_disclaimer(): @@ -210,8 +208,8 @@ def test_blockquote_disclaimer(): """ - eq_(RE_WHITESPACE.sub('', stripped_html), - RE_WHITESPACE.sub('', quotations.extract_from_html(msg_body))) + assert RE_WHITESPACE.sub('', stripped_html) == \ + RE_WHITESPACE.sub('', quotations.extract_from_html(msg_body)) def test_date_block(): @@ -229,8 +227,8 @@ def test_date_block(): """ - eq_('
message
', - RE_WHITESPACE.sub('', quotations.extract_from_html(msg_body))) + assert '
message
' == \ + RE_WHITESPACE.sub('', quotations.extract_from_html(msg_body)) def test_from_block(): @@ -246,8 +244,8 @@ def test_from_block(): text """ - eq_('
message
', - RE_WHITESPACE.sub('', quotations.extract_from_html(msg_body))) + assert '
message
' == \ + RE_WHITESPACE.sub('', quotations.extract_from_html(msg_body)) def test_reply_shares_div_with_from_block(): @@ -264,26 +262,26 @@ def test_reply_shares_div_with_from_block(): ''' - eq_('
Blah

', - RE_WHITESPACE.sub('', quotations.extract_from_html(msg_body))) + assert '
Blah

' == \ + RE_WHITESPACE.sub('', quotations.extract_from_html(msg_body)) def test_reply_quotations_share_block(): stripped_html = quotations.extract_from_plain(REPLY_QUOTATIONS_SHARE_BLOCK) - ok_(stripped_html) - ok_('From' not in stripped_html) + assert stripped_html + assert 'From' not in stripped_html def test_OLK_SRC_BODY_SECTION_stripped(): - eq_('
Reply
', + assert '
Reply
' == \ RE_WHITESPACE.sub( - '', quotations.extract_from_html(OLK_SRC_BODY_SECTION))) + '', quotations.extract_from_html(OLK_SRC_BODY_SECTION)) def test_reply_separated_by_hr(): - eq_('
Hi
there
', + assert '
Hi
there
' == \ RE_WHITESPACE.sub( - '', quotations.extract_from_html(REPLY_SEPARATED_BY_HR))) + '', quotations.extract_from_html(REPLY_SEPARATED_BY_HR)) def test_from_block_and_quotations_in_separate_divs(): @@ -302,8 +300,8 @@ def test_from_block_and_quotations_in_separate_divs(): ''' - eq_('Reply

', - RE_WHITESPACE.sub('', quotations.extract_from_html(msg_body))) + assert 'Reply

' == \ + RE_WHITESPACE.sub('', quotations.extract_from_html(msg_body)) def extract_reply_and_check(filename): @@ -318,8 +316,8 @@ def extract_reply_and_check(filename): reply = quotations.extract_from_html(msg_body) plain_reply = u.html_to_text(reply) - eq_(RE_WHITESPACE.sub('', "Hi. I am fine.\n\nThanks,\nAlex"), - RE_WHITESPACE.sub('', plain_reply)) + assert RE_WHITESPACE.sub('', "Hi. I am fine.\n\nThanks,\nAlex") == \ + RE_WHITESPACE.sub('', plain_reply) def test_gmail_reply(): @@ -363,8 +361,8 @@ def test_CRLF(): """ symbol = ' ' extracted = quotations.extract_from_html('\r\n') - assert_false(symbol in extracted) - eq_('', RE_WHITESPACE.sub('', extracted)) + assert symbol not in extracted + assert '' == RE_WHITESPACE.sub('', extracted) msg_body = """My reply @@ -381,16 +379,16 @@ def test_CRLF(): """ msg_body = msg_body.replace('\n', '\r\n') extracted = quotations.extract_from_html(msg_body) - assert_false(symbol in extracted) + assert symbol not in extracted # Keep new lines otherwise "My reply" becomes one word - "Myreply" - eq_("My\nreply\n", extracted) + assert "My\nreply\n" == extracted def test_gmail_forwarded_msg(): msg_body = """

---------- Forwarded message ----------
From: Bob <bob@example.com>
Date: Fri, Feb 11, 2010 at 5:59 PM
Subject: Bob WFH today
To: Mary <mary@example.com>


eom

""" extracted = quotations.extract_from_html(msg_body) - eq_(RE_WHITESPACE.sub('', msg_body), RE_WHITESPACE.sub('', extracted)) + assert RE_WHITESPACE.sub('', msg_body) == RE_WHITESPACE.sub('', extracted) def test_readable_html_empty(): @@ -407,14 +405,14 @@ def test_readable_html_empty(): """ - eq_(RE_WHITESPACE.sub('', msg_body), - RE_WHITESPACE.sub('', quotations.extract_from_html(msg_body))) + assert RE_WHITESPACE.sub('', msg_body) == \ + RE_WHITESPACE.sub('', quotations.extract_from_html(msg_body)) @patch.object(quotations, 'html_document_fromstring', Mock(return_value=None)) def test_bad_html(): bad_html = "" - eq_(bad_html, quotations.extract_from_html(bad_html)) + assert bad_html == quotations.extract_from_html(bad_html) def test_remove_namespaces(): @@ -430,8 +428,8 @@ def test_remove_namespaces(): rendered = quotations.extract_from_html(msg_body) - assert_true("

" in rendered) - assert_true("xmlns" in rendered) + assert "

" in rendered + assert "xmlns" in rendered - assert_true("" not in rendered) - assert_true("" not in rendered) + assert "" not in rendered + assert "" not in rendered diff --git a/tests/quotations_test.py b/tests/quotations_test.py index e5ed0416..21e8b271 100644 --- a/tests/quotations_test.py +++ b/tests/quotations_test.py @@ -19,14 +19,14 @@ def test_extract_from_respects_content_type(extract_from_plain, quotations.extract_from(msg_body, 'text/html') extract_from_html.assert_called_with(msg_body) - eq_(msg_body, quotations.extract_from(msg_body, 'text/blah')) + assert msg_body == quotations.extract_from(msg_body, 'text/blah') @patch.object(quotations, 'extract_from_plain', Mock(side_effect=Exception())) def test_crash_inside_extract_from(): msg_body = "Hi there" - eq_(msg_body, quotations.extract_from(msg_body, 'text/plain')) + assert msg_body == quotations.extract_from(msg_body, 'text/plain') def test_empty_body(): - eq_('', quotations.extract_from_plain('')) + assert '' == quotations.extract_from_plain('') diff --git a/tests/signature/bruteforce_test.py b/tests/signature/bruteforce_test.py index 382615bb..cd897e85 100644 --- a/tests/signature/bruteforce_test.py +++ b/tests/signature/bruteforce_test.py @@ -7,40 +7,40 @@ def test_empty_body(): - eq_(('', None), bruteforce.extract_signature('')) + assert ('', None) == bruteforce.extract_signature('') def test_no_signature(): msg_body = 'Hey man!' - eq_((msg_body, None), bruteforce.extract_signature(msg_body)) + assert (msg_body, None) == bruteforce.extract_signature(msg_body) def test_signature_only(): msg_body = '--\nRoman' - eq_((msg_body, None), bruteforce.extract_signature(msg_body)) + assert (msg_body, None) == bruteforce.extract_signature(msg_body) def test_signature_separated_by_dashes(): msg_body = '''Hey man! How r u? --- Roman''' - eq_(('Hey man! How r u?', '---\nRoman'), - bruteforce.extract_signature(msg_body)) + assert ('Hey man! How r u?', '---\nRoman') == \ + bruteforce.extract_signature(msg_body) msg_body = '''Hey! -roman''' - eq_(('Hey!', '-roman'), bruteforce.extract_signature(msg_body)) + assert ('Hey!', '-roman') == bruteforce.extract_signature(msg_body) msg_body = '''Hey! - roman''' - eq_(('Hey!', '- roman'), bruteforce.extract_signature(msg_body)) + assert ('Hey!', '- roman') == bruteforce.extract_signature(msg_body) msg_body = '''Wow. Awesome! -- Bob Smith''' - eq_(('Wow. Awesome!', '--\nBob Smith'), - bruteforce.extract_signature(msg_body)) + assert ('Wow. Awesome!', '--\nBob Smith') == \ + bruteforce.extract_signature(msg_body) def test_signature_words(): @@ -48,39 +48,39 @@ def test_signature_words(): Thanks! Roman''' - eq_(('Hey!', 'Thanks!\nRoman'), - bruteforce.extract_signature(msg_body)) + assert ('Hey!', 'Thanks!\nRoman') == \ + bruteforce.extract_signature(msg_body) msg_body = '''Hey! -- Best regards, Roman''' - eq_(('Hey!', '--\nBest regards,\n\nRoman'), - bruteforce.extract_signature(msg_body)) + assert ('Hey!', '--\nBest regards,\n\nRoman') == \ + bruteforce.extract_signature(msg_body) msg_body = '''Hey! -- -- Regards, Roman''' - eq_(('Hey!', '--\n--\nRegards,\nRoman'), - bruteforce.extract_signature(msg_body)) + assert ('Hey!', '--\n--\nRegards,\nRoman') == \ + bruteforce.extract_signature(msg_body) def test_iphone_signature(): msg_body = '''Hey! Sent from my iPhone!''' - eq_(('Hey!', 'Sent from my iPhone!'), - bruteforce.extract_signature(msg_body)) + assert ('Hey!', 'Sent from my iPhone!') == \ + bruteforce.extract_signature(msg_body) def test_mailbox_for_iphone_signature(): msg_body = """Blah Sent from Mailbox for iPhone""" - eq_(("Blah", "Sent from Mailbox for iPhone"), - bruteforce.extract_signature(msg_body)) + assert ("Blah", "Sent from Mailbox for iPhone") == \ + bruteforce.extract_signature(msg_body) def test_line_starts_with_signature_word(): @@ -89,8 +89,8 @@ def test_line_starts_with_signature_word(): -- Thanks! Roman''' - eq_(('Hey man!\nThanks for your attention.', '--\nThanks!\nRoman'), - bruteforce.extract_signature(msg_body)) + assert ('Hey man!\nThanks for your attention.', '--\nThanks!\nRoman') == \ + bruteforce.extract_signature(msg_body) def test_line_starts_with_dashes(): @@ -101,8 +101,8 @@ def test_line_starts_with_dashes(): --> two -- Roman''' - eq_(('Hey man!\nLook at this:\n\n--> one\n--> two', '--\nRoman'), - bruteforce.extract_signature(msg_body)) + assert ('Hey man!\nLook at this:\n\n--> one\n--> two', '--\nRoman') == \ + bruteforce.extract_signature(msg_body) def test_blank_lines_inside_signature(): @@ -111,35 +111,35 @@ def test_blank_lines_inside_signature(): -Lev. Sent from my HTC smartphone!''' - eq_(('Blah.', '-Lev.\n\nSent from my HTC smartphone!'), - bruteforce.extract_signature(msg_body)) + assert ('Blah.', '-Lev.\n\nSent from my HTC smartphone!') == \ + bruteforce.extract_signature(msg_body) msg_body = '''Blah -- John Doe''' - eq_(('Blah', '--\n\nJohn Doe'), bruteforce.extract_signature(msg_body)) + assert ('Blah', '--\n\nJohn Doe') == bruteforce.extract_signature(msg_body) def test_blackberry_signature(): msg_body = """Heeyyoooo. Sent wirelessly from my BlackBerry device on the Bell network. Envoyé sans fil par mon terminal mobile BlackBerry sur le réseau de Bell.""" - eq_(('Heeyyoooo.', msg_body[len('Heeyyoooo.\n'):]), - bruteforce.extract_signature(msg_body)) + assert ('Heeyyoooo.', msg_body[len('Heeyyoooo.\n'):]) == \ + bruteforce.extract_signature(msg_body) msg_body = u"""Blah Enviado desde mi oficina móvil BlackBerry® de Telcel""" - eq_(('Blah', u'Enviado desde mi oficina móvil BlackBerry® de Telcel'), - bruteforce.extract_signature(msg_body)) + assert ('Blah', u'Enviado desde mi oficina móvil BlackBerry® de Telcel') == \ + bruteforce.extract_signature(msg_body) @patch.object(bruteforce, 'get_delimiter', Mock(side_effect=Exception())) def test_crash_in_extract_signature(): msg_body = '''Hey! -roman''' - eq_((msg_body, None), bruteforce.extract_signature(msg_body)) + assert (msg_body, None) == bruteforce.extract_signature(msg_body) def test_signature_cant_start_from_first_line(): @@ -150,8 +150,8 @@ def test_signature_cant_start_from_first_line(): regards John Doe""" - eq_(('Thanks,\n\nBlah', 'regards\n\nJohn Doe'), - bruteforce.extract_signature(msg_body)) + assert ('Thanks,\n\nBlah', 'regards\n\nJohn Doe') == \ + bruteforce.extract_signature(msg_body) @patch.object(bruteforce, 'SIGNATURE_MAX_LINES', 2) @@ -163,73 +163,73 @@ def test_signature_max_lines_ignores_empty_lines(): John Doe""" - eq_(('Thanks,\nBlah', 'regards\n\n\nJohn Doe'), - bruteforce.extract_signature(msg_body)) + assert ('Thanks,\nBlah', 'regards\n\n\nJohn Doe') == \ + bruteforce.extract_signature(msg_body) def test_get_signature_candidate(): # if there aren't at least 2 non-empty lines there should be no signature for lines in [], [''], ['', ''], ['abc']: - eq_([], bruteforce.get_signature_candidate(lines)) + assert [] == bruteforce.get_signature_candidate(lines) # first line never included lines = ['text', 'signature'] - eq_(['signature'], bruteforce.get_signature_candidate(lines)) + assert ['signature'] == bruteforce.get_signature_candidate(lines) # test when message is shorter then SIGNATURE_MAX_LINES with patch.object(bruteforce, 'SIGNATURE_MAX_LINES', 3): lines = ['text', '', '', 'signature'] - eq_(['signature'], bruteforce.get_signature_candidate(lines)) + assert ['signature'] == bruteforce.get_signature_candidate(lines) # test when message is longer then the SIGNATURE_MAX_LINES with patch.object(bruteforce, 'SIGNATURE_MAX_LINES', 2): lines = ['text1', 'text2', 'signature1', '', 'signature2'] - eq_(['signature1', '', 'signature2'], - bruteforce.get_signature_candidate(lines)) + assert ['signature1', '', 'signature2'] == \ + bruteforce.get_signature_candidate(lines) # test long lines not encluded with patch.object(bruteforce, 'TOO_LONG_SIGNATURE_LINE', 3): lines = ['BR,', 'long', 'Bob'] - eq_(['Bob'], bruteforce.get_signature_candidate(lines)) + assert ['Bob'] == bruteforce.get_signature_candidate(lines) # test list (with dashes as bullet points) not included lines = ['List:,', '- item 1', '- item 2', '--', 'Bob'] - eq_(['--', 'Bob'], bruteforce.get_signature_candidate(lines)) + assert ['--', 'Bob'] == bruteforce.get_signature_candidate(lines) def test_mark_candidate_indexes(): with patch.object(bruteforce, 'TOO_LONG_SIGNATURE_LINE', 3): # spaces are not considered when checking line length - eq_('clc', + assert 'clc' == \ bruteforce._mark_candidate_indexes( ['BR, ', 'long', 'Bob'], - [0, 1, 2])) + [0, 1, 2]) # only candidate lines are marked # if line has only dashes it's a candidate line - eq_('ccdc', + assert 'ccdc' == \ bruteforce._mark_candidate_indexes( ['-', 'long', '-', '- i', 'Bob'], - [0, 2, 3, 4])) + [0, 2, 3, 4]) def test_process_marked_candidate_indexes(): - eq_([2, 13, 15], + assert [2, 13, 15] == \ bruteforce._process_marked_candidate_indexes( - [2, 13, 15], 'dcc')) + [2, 13, 15], 'dcc') - eq_([15], + assert [15] == \ bruteforce._process_marked_candidate_indexes( - [2, 13, 15], 'ddc')) + [2, 13, 15], 'ddc') - eq_([13, 15], + assert [13, 15] == \ bruteforce._process_marked_candidate_indexes( - [13, 15], 'cc')) + [13, 15], 'cc') - eq_([15], + assert [15] == \ bruteforce._process_marked_candidate_indexes( - [15], 'lc')) + [15], 'lc') - eq_([15], + assert [15] == \ bruteforce._process_marked_candidate_indexes( - [13, 15], 'ld')) + [13, 15], 'ld') diff --git a/tests/signature/extraction_test.py b/tests/signature/extraction_test.py index b9426748..d1b429a8 100644 --- a/tests/signature/extraction_test.py +++ b/tests/signature/extraction_test.py @@ -19,8 +19,8 @@ def test_message_shorter_SIGNATURE_MAX_LINES(): Thanks in advance, Bob""" text, extracted_signature = extract(body, sender) - eq_('\n'.join(body.splitlines()[:2]), text) - eq_('\n'.join(body.splitlines()[-2:]), extracted_signature) + assert '\n'.join(body.splitlines()[:2]) == text + assert '\n'.join(body.splitlines()[-2:]) == extracted_signature def test_messages_longer_SIGNATURE_MAX_LINES(): @@ -38,9 +38,9 @@ def test_messages_longer_SIGNATURE_MAX_LINES(): extracted_signature = extracted_signature or '' with open(filename[:-len('body')] + 'signature', **kwargs) as ms: msg_signature = ms.read() - eq_(msg_signature.strip(), extracted_signature.strip()) + assert msg_signature.strip() == extracted_signature.strip() stripped_msg = body.strip()[:len(body.strip()) - len(msg_signature)] - eq_(stripped_msg.strip(), text.strip()) + assert stripped_msg.strip() == text.strip() def test_text_line_in_signature(): @@ -53,8 +53,8 @@ def test_text_line_in_signature(): Bob""" text, extracted_signature = extract(body, sender) - eq_('\n'.join(body.splitlines()[:2]), text) - eq_('\n'.join(body.splitlines()[-3:]), extracted_signature) + assert '\n'.join(body.splitlines()[:2]) == text + assert '\n'.join(body.splitlines()[-3:]) == extracted_signature def test_long_line_in_signature(): @@ -66,8 +66,8 @@ def test_long_line_in_signature(): Bob""" text, extracted_signature = extract(body, sender) - eq_('\n'.join(body.splitlines()[:-1]), text) - eq_('Bob', extracted_signature) + assert '\n'.join(body.splitlines()[:-1]) == text + assert 'Bob' == extracted_signature body = """Thanks David, @@ -78,8 +78,8 @@ def test_long_line_in_signature(): def test_basic(): msg_body = 'Blah\r\n--\r\n\r\nSergey Obukhov' - eq_(('Blah', '--\r\n\r\nSergey Obukhov'), - extract(msg_body, 'Sergey')) + assert ('Blah', '--\r\n\r\nSergey Obukhov') == \ + extract(msg_body, 'Sergey') def test_capitalized(): @@ -104,7 +104,7 @@ def test_capitalized(): Doe Inc 555-531-7967""" - eq_(sig, extract(msg_body, 'Doe')[1]) + assert sig == extract(msg_body, 'Doe')[1] def test_over_2_text_lines_after_signature(): @@ -116,12 +116,12 @@ def test_over_2_text_lines_after_signature(): It's not signature """ text, extracted_signature = extract(body, "Bob") - eq_(extracted_signature, None) + assert extracted_signature is None def test_no_signature(): sender, body = "bob@foo.bar", "Hello" - eq_((body, None), extract(body, sender)) + assert (body, None) == extract(body, sender) def test_handles_unicode(): @@ -133,46 +133,46 @@ def test_handles_unicode(): def test_signature_extract_crash(has_signature): has_signature.side_effect = Exception('Bam!') msg_body = u'Blah\r\n--\r\n\r\nСергей' - eq_((msg_body, None), extract(msg_body, 'Сергей')) + assert (msg_body, None) == extract(msg_body, 'Сергей') def test_mark_lines(): with patch.object(bruteforce, 'SIGNATURE_MAX_LINES', 2): # we analyse the 2nd line as well though it's the 6th line # (starting from the bottom) because we don't count empty line - eq_('ttset', + assert 'ttset' == \ e._mark_lines(['Bob Smith', 'Bob Smith', 'Bob Smith', '', - 'some text'], 'Bob Smith')) + 'some text'], 'Bob Smith') with patch.object(bruteforce, 'SIGNATURE_MAX_LINES', 3): # we don't analyse the 1st line because # signature cant start from the 1st line - eq_('tset', + assert 'tset' == \ e._mark_lines(['Bob Smith', 'Bob Smith', '', - 'some text'], 'Bob Smith')) + 'some text'], 'Bob Smith') def test_process_marked_lines(): # no signature found - eq_((list(range(5)), None), e._process_marked_lines(list(range(5)), 'telt')) + assert (list(range(5)), None) == e._process_marked_lines(list(range(5)), 'telt') # signature in the middle of the text - eq_((list(range(9)), None), e._process_marked_lines(list(range(9)), 'tesestelt')) + assert (list(range(9)), None) == e._process_marked_lines(list(range(9)), 'tesestelt') # long line splits signature - eq_((list(range(7)), [7, 8]), - e._process_marked_lines(list(range(9)), 'tsslsless')) + assert (list(range(7)), [7, 8]) == \ + e._process_marked_lines(list(range(9)), 'tsslsless') - eq_((list(range(20)), [20]), - e._process_marked_lines(list(range(21)), 'ttttttstttesllelelets')) + assert (list(range(20)), [20]) == \ + e._process_marked_lines(list(range(21)), 'ttttttstttesllelelets') # some signature lines could be identified as text - eq_(([0], list(range(1, 9))), e._process_marked_lines(list(range(9)), 'tsetetest')) + assert ([0], list(range(1, 9))) == e._process_marked_lines(list(range(9)), 'tsetetest') - eq_(([], list(range(5))), - e._process_marked_lines(list(range(5)), "ststt")) + assert ([], list(range(5))) == \ + e._process_marked_lines(list(range(5)), "ststt") diff --git a/tests/signature/learning/dataset_test.py b/tests/signature/learning/dataset_test.py index 8e152753..17890ad1 100644 --- a/tests/signature/learning/dataset_test.py +++ b/tests/signature/learning/dataset_test.py @@ -12,28 +12,28 @@ def test_is_sender_filename(): - assert_false(d.is_sender_filename("foo/bar")) - assert_false(d.is_sender_filename("foo/bar_body")) - ok_(d.is_sender_filename("foo/bar_sender")) + assert not d.is_sender_filename("foo/bar") + assert not d.is_sender_filename("foo/bar_body") + assert d.is_sender_filename("foo/bar_sender") def test_build_sender_filename(): - eq_("foo/bar_sender", d.build_sender_filename("foo/bar_body")) + assert "foo/bar_sender" == d.build_sender_filename("foo/bar_body") def test_parse_msg_sender(): sender, msg = d.parse_msg_sender(EML_MSG_FILENAME) # if the message in eml format with open(EML_MSG_FILENAME) as f: - eq_(sender, - " Alex Q ") - eq_(msg, f.read()) + assert sender == \ + " Alex Q " + assert msg == f.read() # if the message sender is stored in a separate file sender, msg = d.parse_msg_sender(MSG_FILENAME_WITH_BODY_SUFFIX) with open(MSG_FILENAME_WITH_BODY_SUFFIX) as f: - eq_(sender, u"john@example.com") - eq_(msg, f.read()) + assert sender == u"john@example.com" + assert msg == f.read() def test_build_extraction_dataset(): @@ -50,5 +50,5 @@ def test_build_extraction_dataset(): # the result is a loadable signature extraction dataset # 32 comes from 3 emails in emails/P folder, 11 lines checked to be # a signature, one email has only 10 lines - eq_(test_data.shape[0], 32) - eq_(len(features('')), test_data.shape[1]) + assert test_data.shape[0] == 32 + assert len(features('')) == test_data.shape[1] diff --git a/tests/signature/learning/featurespace_test.py b/tests/signature/learning/featurespace_test.py index dd9f110f..76765213 100644 --- a/tests/signature/learning/featurespace_test.py +++ b/tests/signature/learning/featurespace_test.py @@ -21,17 +21,17 @@ def test_apply_features(): result = fs.apply_features(s, features) # note that we don't consider the first line because signatures don't # usually take all the text, empty lines are not considered - eq_(result, [[1, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 1], - [0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0], - [1, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0], - [0, 0, 0, 0, 1, 0, 0, 0, 0, 0, 0, 0], - [0, 0, 1, 0, 0, 0, 0, 0, 0, 0, 0, 0]]) + assert result == [[1, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 1], + [0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0], + [1, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0], + [0, 0, 0, 0, 1, 0, 0, 0, 0, 0, 0, 0], + [0, 0, 1, 0, 0, 0, 0, 0, 0, 0, 0, 0]] with patch.object(fs, 'SIGNATURE_MAX_LINES', 5): features = fs.features(sender) new_result = fs.apply_features(s, features) # result remains the same because we don't consider empty lines - eq_(result, new_result) + assert result == new_result def test_build_pattern(): @@ -45,4 +45,4 @@ def test_build_pattern(): sender = 'John ' features = fs.features(sender) result = fs.build_pattern(s, features) - eq_(result, [2, 0, 1, 0, 1, 0, 0, 0, 0, 0, 0, 1]) + assert result == [2, 0, 1, 0, 1, 0, 0, 0, 0, 0, 0, 1] diff --git a/tests/signature/learning/helpers_test.py b/tests/signature/learning/helpers_test.py index d9e7b866..6cb72c5e 100644 --- a/tests/signature/learning/helpers_test.py +++ b/tests/signature/learning/helpers_test.py @@ -45,28 +45,28 @@ def test_match_phone_numbers(): for phone in VALID_PHONE_NUMBERS: - ok_(RE_RELAX_PHONE.search(phone), "{} should be matched".format(phone)) + assert RE_RELAX_PHONE.search(phone), "{} should be matched".format(phone) def test_match_names(): names = ['John R. Doe'] for name in names: - ok_(RE_NAME.match(name), "{} should be matched".format(name)) + assert RE_NAME.match(name), "{} should be matched".format(name) # Now test helpers functions def test_binary_regex_search(): - eq_(1, h.binary_regex_search(re.compile("12"))("12")) - eq_(0, h.binary_regex_search(re.compile("12"))("34")) + assert 1 == h.binary_regex_search(re.compile("12"))("12") + assert 0 == h.binary_regex_search(re.compile("12"))("34") def binary_regex_match(prog): - eq_(1, h.binary_regex_match(re.compile("12"))("12 3")) - eq_(0, h.binary_regex_match(re.compile("12"))("3 12")) + assert 1 == h.binary_regex_match(re.compile("12"))("12 3") + assert 0 == h.binary_regex_match(re.compile("12"))("3 12") def test_flatten_list(): - eq_([1, 2, 3, 4, 5], h.flatten_list([[1, 2], [3, 4, 5]])) + assert [1, 2, 3, 4, 5] == h.flatten_list([[1, 2], [3, 4, 5]]) @patch.object(h.re, 'compile') @@ -76,17 +76,17 @@ def test_contains_sender_names(re_compile): has_sender_names = h.contains_sender_names("bob.smith@example.com") extract_names.assert_called_with("bob.smith@example.com") for name in ["bob", "Bob", "smith", "Smith"]: - ok_(has_sender_names(name)) + assert has_sender_names(name) extract_names.return_value = '' has_sender_names = h.contains_sender_names("bob.smith@example.com") # if no names could be extracted fallback to the email address - ok_(has_sender_names('bob.smith@example.com')) + assert has_sender_names('bob.smith@example.com') # don't crash if there are no sender extract_names.return_value = '' has_sender_names = h.contains_sender_names("") - assert_false(has_sender_names('')) + assert not has_sender_names('') def test_extract_names(): @@ -157,30 +157,30 @@ def test_extract_names(): try: re.compile("|".join(extracted_names)) except Exception as e: - ok_(False, ("Failed to compile extracted names {}" - "\n\nReason: {}").format(extracted_names, e)) + assert False, ("Failed to compile extracted names {}" + "\n\nReason: {}").format(extracted_names, e) if expected_names: for name in expected_names: - assert_in(name, extracted_names) + assert name in extracted_names else: - eq_(expected_names, extracted_names) + assert expected_names == extracted_names # words like `ru`, `gmail`, `com`, `org`, etc. are not considered # sender's names for word in h.BAD_SENDER_NAMES: - eq_(h.extract_names(word), []) + assert h.extract_names(word) == [] # duplicates are not allowed - eq_(h.extract_names("sergey > Roman""" - eq_("Test reply", quotations.extract_from_plain(msg_body)) + assert "Test reply" == quotations.extract_from_plain(msg_body) def test_pattern_on_date_polymail(): msg_body = """Test reply @@ -46,7 +46,7 @@ def test_pattern_on_date_polymail(): Test quoted data """ - eq_("Test reply", quotations.extract_from_plain(msg_body)) + assert "Test reply" == quotations.extract_from_plain(msg_body) def test_pattern_sent_from_samsung_smb_wrote(): @@ -59,17 +59,17 @@ def test_pattern_sent_from_samsung_smb_wrote(): > > Roman""" - eq_("Test reply", quotations.extract_from_plain(msg_body)) + assert "Test reply" == quotations.extract_from_plain(msg_body) def test_pattern_on_date_wrote_somebody(): - eq_('Lorem', quotations.extract_from_plain( - """Lorem + assert 'Lorem' == quotations.extract_from_plain( + """Lorem Op 13-02-2014 3:18 schreef Julius Caesar : Veniam laborum mlkshk kale chips authentic. Normcore mumblecore laboris, fanny pack readymade eu blog chia pop-up freegan enim master cleanse. -""")) +""") def test_pattern_on_date_somebody_wrote_date_with_slashes(): @@ -81,7 +81,7 @@ def test_pattern_on_date_somebody_wrote_date_with_slashes(): > Test. > > Roman""" - eq_("Test reply", quotations.extract_from_plain(msg_body)) + assert "Test reply" == quotations.extract_from_plain(msg_body) def test_date_time_email_splitter(): @@ -93,7 +93,7 @@ def test_date_time_email_splitter(): > First from site > """ - eq_("Test reply", quotations.extract_from_plain(msg_body)) + assert "Test reply" == quotations.extract_from_plain(msg_body) def test_pattern_on_date_somebody_wrote_allows_space_in_front(): @@ -104,7 +104,7 @@ def test_pattern_on_date_somebody_wrote_allows_space_in_front(): >** > Blah-blah-blah""" - eq_("Thanks Thanmai", quotations.extract_from_plain(msg_body)) + assert "Thanks Thanmai" == quotations.extract_from_plain(msg_body) def test_pattern_on_date_somebody_sent(): @@ -116,7 +116,7 @@ def test_pattern_on_date_somebody_sent(): > Test > > Roman""" - eq_("Test reply", quotations.extract_from_plain(msg_body)) + assert "Test reply" == quotations.extract_from_plain(msg_body) def test_appointment(): @@ -148,13 +148,13 @@ def test_appointment(): John Doe, FCLS Mailgun Inc 555-941-0697""" - eq_(expected, quotations.extract_from_plain(msg_body)) + assert expected == quotations.extract_from_plain(msg_body) def test_line_starts_with_on(): msg_body = """Blah-blah-blah On blah-blah-blah""" - eq_(msg_body, quotations.extract_from_plain(msg_body)) + assert msg_body == quotations.extract_from_plain(msg_body) def test_reply_and_quotation_splitter_share_line(): @@ -162,13 +162,13 @@ def test_reply_and_quotation_splitter_share_line(): # are on the same line msg_body = """reply On Wed, Apr 4, 2012 at 3:59 PM, bob@example.com wrote: > Hi""" - eq_('reply', quotations.extract_from_plain(msg_body)) + assert 'reply' == quotations.extract_from_plain(msg_body) # test pattern '--- On wrote:' with reply text on # the same line msg_body = """reply--- On Wed, Apr 4, 2012 at 3:59 PM, me@domain.com wrote: > Hi""" - eq_('reply', quotations.extract_from_plain(msg_body)) + assert 'reply' == quotations.extract_from_plain(msg_body) # test pattern '--- On wrote:' with reply text containing # '-' symbol @@ -178,7 +178,7 @@ def test_reply_and_quotation_splitter_share_line(): reply = """reply bla-bla - bla""" - eq_(reply, quotations.extract_from_plain(msg_body)) + assert reply == quotations.extract_from_plain(msg_body) def _check_pattern_original_message(original_message_indicator): @@ -187,8 +187,8 @@ def _check_pattern_original_message(original_message_indicator): -----{}----- Test""" - eq_('Test reply', quotations.extract_from_plain( - msg_body.format(six.text_type(original_message_indicator)))) + assert 'Test reply' == quotations.extract_from_plain( + msg_body.format(six.text_type(original_message_indicator))) def test_english_original_message(): _check_pattern_original_message('Original Message') @@ -208,7 +208,7 @@ def test_reply_after_quotations(): > > Test Test reply""" - eq_("Test reply", quotations.extract_from_plain(msg_body)) + assert "Test reply" == quotations.extract_from_plain(msg_body) def test_android_wrote(): @@ -219,7 +219,7 @@ def test_android_wrote(): > quoted > text """ - eq_("Test reply", quotations.extract_from_plain(msg_body)) + assert "Test reply" == quotations.extract_from_plain(msg_body) def test_reply_wraps_quotations(): @@ -236,7 +236,7 @@ def test_reply_wraps_quotations(): Regards, Roman""" - eq_(reply, quotations.extract_from_plain(msg_body)) + assert reply == quotations.extract_from_plain(msg_body) def test_reply_wraps_nested_quotations(): @@ -255,7 +255,7 @@ def test_reply_wraps_nested_quotations(): reply = """Test reply Regards, Roman""" - eq_(reply, quotations.extract_from_plain(msg_body)) + assert reply == quotations.extract_from_plain(msg_body) def test_quotation_separator_takes_2_lines(): @@ -273,7 +273,7 @@ def test_quotation_separator_takes_2_lines(): reply = """Test reply Regards, Roman""" - eq_(reply, quotations.extract_from_plain(msg_body)) + assert reply == quotations.extract_from_plain(msg_body) def test_quotation_separator_takes_3_lines(): @@ -285,7 +285,7 @@ def test_quotation_separator_takes_3_lines(): Test message """ - eq_("Test reply", quotations.extract_from_plain(msg_body)) + assert "Test reply" == quotations.extract_from_plain(msg_body) def test_short_quotation(): @@ -294,7 +294,7 @@ def test_short_quotation(): On 04/19/2011 07:10 AM, Roman Tkachenko wrote: > Hello""" - eq_("Hi", quotations.extract_from_plain(msg_body)) + assert "Hi" == quotations.extract_from_plain(msg_body) def test_with_indent(): msg_body = """YOLO salvia cillum kogi typewriter mumblecore cardigan skateboard Austin. @@ -303,7 +303,7 @@ def test_with_indent(): Brunch mumblecore pug Marfa tofu, irure taxidermy hoodie readymade pariatur. """ - eq_("YOLO salvia cillum kogi typewriter mumblecore cardigan skateboard Austin.", quotations.extract_from_plain(msg_body)) + assert "YOLO salvia cillum kogi typewriter mumblecore cardigan skateboard Austin." == quotations.extract_from_plain(msg_body) def test_short_quotation_with_newline(): @@ -321,7 +321,7 @@ def test_short_quotation_with_newline(): Mark Sent from Acompli""" - eq_("Btw blah blah...", quotations.extract_from_plain(msg_body)) + assert "Btw blah blah..." == quotations.extract_from_plain(msg_body) def test_pattern_date_email_with_unicode(): @@ -329,11 +329,11 @@ def test_pattern_date_email_with_unicode(): 2011/4/7 Nathan \xd0\xb8ova > Cool beans, scro""" - eq_("Replying ok", quotations.extract_from_plain(msg_body)) + assert "Replying ok" == quotations.extract_from_plain(msg_body) def test_english_from_block(): - eq_('Allo! Follow up MIME!', quotations.extract_from_plain("""Allo! Follow up MIME! + assert 'Allo! Follow up MIME!' == quotations.extract_from_plain("""Allo! Follow up MIME! From: somebody@example.com Sent: March-19-11 5:42 PM @@ -341,11 +341,11 @@ def test_english_from_block(): Subject: The manager has commented on your Loop Blah-blah-blah -""")) +""") def test_german_from_block(): - eq_('Allo! Follow up MIME!', quotations.extract_from_plain( - """Allo! Follow up MIME! + assert 'Allo! Follow up MIME!' == quotations.extract_from_plain( + """Allo! Follow up MIME! Von: somebody@example.com Gesendet: Dienstag, 25. November 2014 14:59 @@ -353,11 +353,11 @@ def test_german_from_block(): Betreff: The manager has commented on your Loop Blah-blah-blah -""")) +""") def test_french_multiline_from_block(): - eq_('Lorem ipsum', quotations.extract_from_plain( - u"""Lorem ipsum + assert 'Lorem ipsum' == quotations.extract_from_plain( + u"""Lorem ipsum De : Brendan xxx [mailto:brendan.xxx@xxx.com] Envoyé : vendredi 23 janvier 2015 16:39 @@ -365,29 +365,29 @@ def test_french_multiline_from_block(): Objet : Follow Up Blah-blah-blah -""")) +""") def test_french_from_block(): - eq_('Lorem ipsum', quotations.extract_from_plain( - u"""Lorem ipsum + assert 'Lorem ipsum' == quotations.extract_from_plain( + u"""Lorem ipsum Le 23 janv. 2015 à 22:03, Brendan xxx > a écrit: -Bonjour!""")) +Bonjour!""") def test_polish_from_block(): - eq_('Lorem ipsum', quotations.extract_from_plain( - u"""Lorem ipsum + assert 'Lorem ipsum' == quotations.extract_from_plain( + u"""Lorem ipsum W dniu 28 stycznia 2015 01:53 użytkownik Zoe xxx napisał: Blah! -""")) +""") def test_danish_from_block(): - eq_('Allo! Follow up MIME!', quotations.extract_from_plain( - """Allo! Follow up MIME! + assert 'Allo! Follow up MIME!' == quotations.extract_from_plain( + """Allo! Follow up MIME! Fra: somebody@example.com Sendt: 19. march 2011 12:10 @@ -395,58 +395,58 @@ def test_danish_from_block(): Emne: The manager has commented on your Loop Blah-blah-blah -""")) +""") def test_swedish_from_block(): - eq_('Allo! Follow up MIME!', quotations.extract_from_plain( - u"""Allo! Follow up MIME! + assert 'Allo! Follow up MIME!' == quotations.extract_from_plain( + u"""Allo! Follow up MIME! Från: Anno Sportel [mailto:anno.spoel@hsbcssad.com] Skickat: den 26 augusti 2015 14:45 Till: Isacson Leiff Ämne: RE: Week 36 Blah-blah-blah -""")) +""") def test_swedish_from_line(): - eq_('Lorem', quotations.extract_from_plain( - """Lorem + assert 'Lorem' == quotations.extract_from_plain( + """Lorem Den 14 september, 2015 02:23:18, Valentino Rudy (valentino@rudy.be) skrev: Veniam laborum mlkshk kale chips authentic. Normcore mumblecore laboris, fanny pack readymade eu blog chia pop-up freegan enim master cleanse. -""")) +""") def test_norwegian_from_line(): - eq_('Lorem', quotations.extract_from_plain( - u"""Lorem + assert 'Lorem' == quotations.extract_from_plain( + u"""Lorem På 14 september 2015 på 02:23:18, Valentino Rudy (valentino@rudy.be) skrev: Veniam laborum mlkshk kale chips authentic. Normcore mumblecore laboris, fanny pack readymade eu blog chia pop-up freegan enim master cleanse. -""")) +""") def test_dutch_from_block(): - eq_('Gluten-free culpa lo-fi et nesciunt nostrud.', quotations.extract_from_plain( - """Gluten-free culpa lo-fi et nesciunt nostrud. + assert 'Gluten-free culpa lo-fi et nesciunt nostrud.' == quotations.extract_from_plain( + """Gluten-free culpa lo-fi et nesciunt nostrud. Op 17-feb.-2015, om 13:18 heeft Julius Caesar het volgende geschreven: Small batch beard laboris tempor, non listicle hella Tumblr heirloom. -""")) +""") def test_vietnamese_from_block(): - eq_('Hello', quotations.extract_from_plain( - u"""Hello + assert 'Hello' == quotations.extract_from_plain( + u"""Hello Vào 14:24 8 tháng 6, 2017, Hùng Nguyễn đã viết: > Xin chào -""")) +""") def test_quotation_marker_false_positive(): msg_body = """Visit us now for assistance... >>> >>> http://www.domain.com <<< Visit our site by clicking the link above""" - eq_(msg_body, quotations.extract_from_plain(msg_body)) + assert msg_body == quotations.extract_from_plain(msg_body) def test_link_closed_with_quotation_marker_on_new_line(): @@ -459,7 +459,7 @@ def test_link_closed_with_quotation_marker_on_new_line(): > > Requester: ''' - eq_('8.45am-1pm', quotations.extract_from_plain(msg_body)) + assert '8.45am-1pm' == quotations.extract_from_plain(msg_body) def test_link_breaks_quotation_markers_sequence(): @@ -475,7 +475,7 @@ def test_link_breaks_quotation_markers_sequence(): > life is short. (http://example.com/c/YzMmE) > """ - eq_("Blah", quotations.extract_from_plain(msg_body)) + assert "Blah" == quotations.extract_from_plain(msg_body) # link starts after some text on one line and ends on another msg_body = """Blah @@ -488,7 +488,7 @@ def test_link_breaks_quotation_markers_sequence(): _nonce=3dd518) > """ - eq_("Blah", quotations.extract_from_plain(msg_body)) + assert "Blah" == quotations.extract_from_plain(msg_body) def test_from_block_starts_with_date(): @@ -498,7 +498,7 @@ def test_from_block_starts_with_date(): To: klizhentas@example.com """ - eq_('Blah', quotations.extract_from_plain(msg_body)) + assert 'Blah' == quotations.extract_from_plain(msg_body) def test_bold_from_block(): @@ -511,7 +511,7 @@ def test_bold_from_block(): *Subject:* Hello """ - eq_("Hi", quotations.extract_from_plain(msg_body)) + assert "Hi" == quotations.extract_from_plain(msg_body) def test_weird_date_format_in_date_block(): @@ -522,7 +522,7 @@ def test_weird_date_format_in_date_block(): Subject: [Ticket #8] Test """ - eq_('Blah', quotations.extract_from_plain(msg_body)) + assert 'Blah' == quotations.extract_from_plain(msg_body) def test_dont_parse_quotations_for_forwarded_messages(): @@ -536,7 +536,7 @@ def test_dont_parse_quotations_for_forwarded_messages(): To: rob@example.com Text""" - eq_(msg_body, quotations.extract_from_plain(msg_body)) + assert msg_body == quotations.extract_from_plain(msg_body) def test_forwarded_message_in_quotations(): @@ -554,7 +554,7 @@ def test_forwarded_message_in_quotations(): To: rob@example.com """ - eq_("Blah", quotations.extract_from_plain(msg_body)) + assert "Blah" == quotations.extract_from_plain(msg_body) def test_mark_message_lines(): @@ -572,7 +572,7 @@ def test_mark_message_lines(): '> Hi', '', 'Signature'] - eq_('tesssemet', quotations.mark_message_lines(lines)) + assert 'tesssemet' == quotations.mark_message_lines(lines) lines = ['Just testing the email reply', '', @@ -586,7 +586,7 @@ def test_mark_message_lines(): 'wrote:', '', 'Tarmo Lehtpuu has posted the following message on'] - eq_('tettessset', quotations.mark_message_lines(lines)) + assert 'tettessset' == quotations.mark_message_lines(lines) def test_process_marked_lines(): @@ -596,27 +596,27 @@ def test_process_marked_lines(): lines = [str(i) for i in range(len(markers))] lines = [str(i) for i in range(len(markers))] - eq_(lines, quotations.process_marked_lines(lines, markers)) + assert lines == quotations.process_marked_lines(lines, markers) # no splitter => no markers markers = 'tmm' lines = ['1', '2', '3'] - eq_(['1', '2', '3'], quotations.process_marked_lines(lines, markers)) + assert ['1', '2', '3'] == quotations.process_marked_lines(lines, markers) # text after splitter without markers is quotation markers = 'tst' lines = ['1', '2', '3'] - eq_(['1'], quotations.process_marked_lines(lines, markers)) + assert ['1'] == quotations.process_marked_lines(lines, markers) # message + quotation + signature markers = 'tsmt' lines = ['1', '2', '3', '4'] - eq_(['1', '4'], quotations.process_marked_lines(lines, markers)) + assert ['1', '4'] == quotations.process_marked_lines(lines, markers) # message + + nested quotation markers = 'tstsmt' lines = ['1', '2', '3', '4', '5', '6'] - eq_(['1'], quotations.process_marked_lines(lines, markers)) + assert ['1'] == quotations.process_marked_lines(lines, markers) # test links wrapped with paranthesis # link starts on the marker line @@ -628,7 +628,7 @@ def test_process_marked_lines(): ')', '', '> quote'] - eq_(lines[:1], quotations.process_marked_lines(lines, markers)) + assert lines[:1] == quotations.process_marked_lines(lines, markers) # link starts on the new line markers = 'tmmmtm' @@ -639,7 +639,7 @@ def test_process_marked_lines(): '(http://example.com) > ', '> life is short. (http://example.com) ' ] - eq_(lines[:1], quotations.process_marked_lines(lines, markers)) + assert lines[:1] == quotations.process_marked_lines(lines, markers) # check all "inline" replies markers = 'tsmtmtm' @@ -650,7 +650,7 @@ def test_process_marked_lines(): '>', 'inline reply', '>'] - eq_(lines, quotations.process_marked_lines(lines, markers)) + assert lines == quotations.process_marked_lines(lines, markers) # inline reply with link not wrapped in paranthesis markers = 'tsmtm' @@ -659,7 +659,7 @@ def test_process_marked_lines(): '>', 'inline reply with link http://example.com', '>'] - eq_(lines, quotations.process_marked_lines(lines, markers)) + assert lines == quotations.process_marked_lines(lines, markers) # inline reply with link wrapped in paranthesis markers = 'tsmtm' @@ -668,7 +668,7 @@ def test_process_marked_lines(): '>', 'inline reply (http://example.com)', '>'] - eq_(lines, quotations.process_marked_lines(lines, markers)) + assert lines == quotations.process_marked_lines(lines, markers) def test_preprocess(): @@ -694,7 +694,7 @@ def test_preprocess(): 'wrote:\n' '\n' '> Hi') - eq_(prepared_msg, quotations.preprocess(msg, '\n')) + assert prepared_msg == quotations.preprocess(msg, '\n') msg = """ > Z0PSUyQSZkPWUwY2U """ - eq_(msg, quotations.preprocess(msg, '\n')) + assert msg == quotations.preprocess(msg, '\n') # 'On wrote' shouldn't be spread across too many lines msg = ('Hello\n' @@ -714,7 +714,7 @@ def test_preprocess(): 'wrote:\n' '\n' '> Hi') - eq_(msg, quotations.preprocess(msg, '\n')) + assert msg == quotations.preprocess(msg, '\n') msg = ('Hello On Nov 30, smb wrote:\n' 'Hi\n' @@ -727,12 +727,12 @@ def test_preprocess(): 'On Nov 29, smb wrote:\n' 'hi') - eq_(prepared_msg, quotations.preprocess(msg, '\n')) + assert prepared_msg == quotations.preprocess(msg, '\n') def test_preprocess_postprocess_2_links(): msg_body = " " - eq_(msg_body, quotations.extract_from_plain(msg_body)) + assert msg_body == quotations.extract_from_plain(msg_body) def body_iterator(msg, decode=False): @@ -761,7 +761,7 @@ def test_standard_replies(): reply_text = f.read().strip() else: reply_text = 'Hello' - yield eq_, reply_text, stripped_text, \ + assert reply_text == stripped_text, \ "'%(reply)s' != %(stripped)s for %(fn)s" % \ {'reply': reply_text, 'stripped': stripped_text, 'fn': filename} @@ -813,7 +813,7 @@ def test_split_email(): """ expected_markers = "stttttsttttetesetesmmmmmmsmmmmmmmmmmmmmmmm" markers = quotations.split_emails(msg) - eq_(markers, expected_markers) + assert markers == expected_markers @@ -826,7 +826,7 @@ def test_feedback_below_left_unparsed(): that this line is intact.""" parsed = quotations.extract_from_plain(msg_body) - eq_(msg_body, parsed) + assert msg_body == parsed def test_appointment_2(): @@ -838,4 +838,4 @@ def test_appointment_2(): Please bring in your ID.""" parsed = quotations.extract_from_plain(msg_body) - eq_(msg_body, parsed) + assert msg_body == parsed diff --git a/tests/utils_test.py b/tests/utils_test.py index 0027752e..b439f084 100644 --- a/tests/utils_test.py +++ b/tests/utils_test.py @@ -7,9 +7,9 @@ def test_get_delimiter(): - eq_('\r\n', u.get_delimiter('abc\r\n123')) - eq_('\n', u.get_delimiter('abc\n123')) - eq_('\n', u.get_delimiter('abc')) + assert '\r\n' == u.get_delimiter('abc\r\n123') + assert '\n' == u.get_delimiter('abc\n123') + assert '\n' == u.get_delimiter('abc') def test_html_to_text(): @@ -25,11 +25,11 @@ def test_html_to_text():

""" text = u.html_to_text(html) - eq_("Hello world! \n\n * One! \n * Two \nHaha", text) - eq_(u"привет!", u.html_to_text("привет!")) + assert "Hello world! \n\n * One! \n * Two \nHaha" == text + assert u"привет!" == u.html_to_text("привет!") html = '

Hi' - eq_('Hi', u.html_to_text(html)) + assert 'Hi' == u.html_to_text(html) html = """Hi """ - eq_('Hi', u.html_to_text(html)) + assert 'Hi' == u.html_to_text(html) html = """
TEXT 1

TEXT 2

""" - eq_('TEXT 1 \nTEXT 2', u.html_to_text(html)) + assert 'TEXT 1 \nTEXT 2' == u.html_to_text(html) def test_comment_no_parent(): s = ' no comment' d = u.html_document_fromstring(s) - eq_("no comment", u.html_tree_to_text(d)) + assert "no comment" == u.html_tree_to_text(d) @patch.object(u, 'html_fromstring', Mock(return_value=None)) def test_bad_html_to_text(): bad_html = "one
two
three" - eq_(None, u.html_to_text(bad_html)) + assert u.html_to_text(bad_html) is None