Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

make test/emails/ dir relative to test script #11

Open
wants to merge 5 commits into
base: master
Choose a base branch
from
Open
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
2 changes: 1 addition & 1 deletion .gitignore
Original file line number Diff line number Diff line change
Expand Up @@ -8,4 +8,4 @@ tests/.DS_Store
.project
dist/
dist/*

.tox/
10 changes: 5 additions & 5 deletions email_reply_parser/__init__.py
Original file line number Diff line number Diff line change
Expand Up @@ -96,15 +96,15 @@ def _scan_line(self, line):
if re.match(self.SIG_REGEX, line):
line.lstrip()

is_quoted = re.match(self.QUOTED_REGEX, line) != None
is_quoted = re.match(self.QUOTED_REGEX, line) is not None

if self.fragment and len(line.strip()) == 0:
if re.match(self.SIG_REGEX, self.fragment.lines[-1]):
self.fragment.signature = True
self._finish_fragment()

if self.fragment and ((self.fragment.quoted == is_quoted)
or (self.fragment.quoted and (self.quote_header(line) or len(line.strip()) == 0))):
or (self.fragment.quoted and (self.quote_header(line) or len(line.strip()) == 0))):

self.fragment.lines.append(line)
else:
Expand All @@ -118,7 +118,7 @@ def quote_header(self, line):

Returns True or False
"""
return re.match(self.QUOTE_HDR_REGEX, line[::-1]) != None
return re.match(self.QUOTE_HDR_REGEX, line[::-1]) is not None

def _finish_fragment(self):
""" Creates fragment
Expand All @@ -128,8 +128,8 @@ def _finish_fragment(self):
self.fragment.finish()
if not self.found_visible:
if self.fragment.quoted \
or self.fragment.signature \
or (len(self.fragment.content.strip()) == 0):
or self.fragment.signature \
or (len(self.fragment.content.strip()) == 0):

self.fragment.hidden = True
else:
Expand Down
12 changes: 7 additions & 5 deletions test/test_email_reply_parser.py
Original file line number Diff line number Diff line change
Expand Up @@ -5,9 +5,10 @@
sys.path.insert(0, os.path.join(os.path.dirname(__file__), '..'))
from email_reply_parser import EmailReplyParser

TEST_EMAILS_DIR = os.path.join(os.path.dirname(__file__), 'emails')

class EmailMessageTest(unittest.TestCase):

class EmailMessageTest(unittest.TestCase):
def test_simple_body(self):
message = self.get_email('email_1_1')

Expand Down Expand Up @@ -102,17 +103,18 @@ def test_reply_is_parsed(self):
self.assertTrue("You can list the keys for the bucket" in message.reply)

def test_sent_from_iphone(self):
with open('test/emails/email_iPhone.txt') as email:
with open(os.path.join(TEST_EMAILS_DIR, 'email_iPhone.txt')) as email:
self.assertTrue("Sent from my iPhone" not in EmailReplyParser.parse_reply(email.read()))

def test_email_one_is_not_on(self):
with open('test/emails/email_one_is_not_on.txt') as email:
self.assertTrue("On Oct 1, 2012, at 11:55 PM, Dave Tapley wrote:" not in EmailReplyParser.parse_reply(email.read()))
with open(os.path.join(TEST_EMAILS_DIR, 'email_one_is_not_on.txt')) as email:
self.assertTrue(
"On Oct 1, 2012, at 11:55 PM, Dave Tapley wrote:" not in EmailReplyParser.parse_reply(email.read()))

def get_email(self, name):
""" Return EmailMessage instance
"""
with open('test/emails/%s.txt' % name) as f:
with open(os.path.join(TEST_EMAILS_DIR, '%s.txt' % name)) as f:
text = f.read()
return EmailReplyParser.read(text)

Expand Down
5 changes: 5 additions & 0 deletions tox.ini
Original file line number Diff line number Diff line change
@@ -0,0 +1,5 @@
[tox]
envlist = py26,py27,py32,py33,py34,pypy

[testenv]
commands = python setup.py test