Permalink
Browse files

Apply reverend.patch and reverend.unittest.py (slightly modified) fix…

…ing some basic Reverend failures

Author: Sterops
Reviewer: exarkun
Fixes: #2872

Add minimal unit tests for `EmailClassifier.train` and `EmailClassifier.guess` and
fix the unhandled exceptions in the codepaths they exercise.


git-svn-id: http://divmod.org/svn/Divmod/trunk/Reverend@17655 866e43f7-fbfc-0310-8f2a-ec88d1da2979
  • Loading branch information...
1 parent 2743e21 commit e0b22e42b36aea024c9d736fe1a60cc81deafc86 exarkun committed Jul 3, 2009
Showing with 42 additions and 4 deletions.
  1. +4 −4 reverend/guessers/email.py
  2. 0 reverend/test/__init__.py
  3. +38 −0 reverend/test/test_email.py
@@ -28,7 +28,7 @@ def getBodyTokens(self, msg):
text = self.getTextPlain(msg)
if text is None:
text = ''
- tl = self.splitter.split(text)
+ tl = list(self._tokenizer.tokenize(text))
return tl
def getHeaderTokens(self, msg):
@@ -37,20 +37,20 @@ def getHeaderTokens(self, msg):
text += msg.get('from','fromnoone') + ' '
text += msg.get('to','tonoone') + ' '
text += msg.get('cc','ccnoone') + ' '
- tl = self.splitter.split(text)
+ tl = list(self._tokenizer.tokenize(text))
return tl
def getTextPlain(self, msg):
for part in msg.walk():
- typ = part.get_type()
+ typ = part.get_content_type()
if typ and typ.lower() == "text/plain":
text = part.get_payload(decode=True)
return text
return None
def getTextHtml(self, msg):
for part in msg.walk():
- typ = part.get_type()
+ typ = part.get_content_type()
if typ and typ.lower() == "text/html":
text = part.get_payload(decode=False)
return text
No changes.
@@ -0,0 +1,38 @@
+
+"""
+Tests for L{reverend.guessers.email}.
+"""
+
+import email
+from unittest import TestCase
+
+from reverend.guessers.email import EmailClassifier
+
+
+class EmailClassifierTests(TestCase):
+ """
+ Tests for L{EmailClassifier}
+ """
+ def setUp(self):
+ """
+ Create a L{Message} and an L{EmailClassifier}.
+ """
+ self.classifier = EmailClassifier()
+ self.message = email.Message.Message()
+
+
+ def test_training(self):
+ """
+ L{EmailClassifier.train} accepts a pool name and a L{Message}
+ instance and trains the classifier to put similar messages into that
+ pool.
+ """
+ self.classifier.train("test", self.message)
+
+
+ def test_guessing(self):
+ """
+ L{EmailClassifier.guess} accepts a L{Message} and returns a pool
+ name.
+ """
+ self.classifier.guess(self.message)

0 comments on commit e0b22e4

Please sign in to comment.