diff --git a/.gitignore b/.gitignore index 71f7c64..45d9920 100644 --- a/.gitignore +++ b/.gitignore @@ -8,4 +8,4 @@ tests/.DS_Store .project dist/ dist/* - +.tox/ diff --git a/email_reply_parser/__init__.py b/email_reply_parser/__init__.py index 5befe48..a103282 100644 --- a/email_reply_parser/__init__.py +++ b/email_reply_parser/__init__.py @@ -96,7 +96,7 @@ 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]): @@ -104,7 +104,7 @@ def _scan_line(self, line): 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: @@ -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 @@ -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: diff --git a/test/test_email_reply_parser.py b/test/test_email_reply_parser.py index 2255e64..77ec83c 100644 --- a/test/test_email_reply_parser.py +++ b/test/test_email_reply_parser.py @@ -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') @@ -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) diff --git a/tox.ini b/tox.ini new file mode 100644 index 0000000..9e35d5d --- /dev/null +++ b/tox.ini @@ -0,0 +1,5 @@ +[tox] +envlist = py26,py27,py32,py33,py34,pypy + +[testenv] +commands = python setup.py test