[Spambayes-checkins] spambayes/spambayes/test test_sb_imapfilter.py, 1.9, 1.10

Tony Meyer anadelonbrin at users.sourceforge.net
Thu Jan 13 22:48:21 CET 2005


Update of /cvsroot/spambayes/spambayes/spambayes/test
In directory sc8-pr-cvs1.sourceforge.net:/tmp/cvs-serv9717/spambayes/test

Modified Files:
	test_sb_imapfilter.py 
Log Message:
Add a test for the new safe_read function.

Index: test_sb_imapfilter.py
===================================================================
RCS file: /cvsroot/spambayes/spambayes/spambayes/test/test_sb_imapfilter.py,v
retrieving revision 1.9
retrieving revision 1.10
diff -C2 -d -r1.9 -r1.10
*** test_sb_imapfilter.py	4 Jan 2005 00:18:02 -0000	1.9
--- test_sb_imapfilter.py	13 Jan 2005 21:48:15 -0000	1.10
***************
*** 11,14 ****
--- 11,15 ----
  import unittest
  import asyncore
+ import StringIO
  
  import sb_test_support
***************
*** 530,533 ****
--- 531,567 ----
          self.assertEqual(data['5']["RFC822.HEADER"], headers)
  
+     def _counter(self, size):
+         self._count += 1
+         return self._imap_file_read(size)
+     def test_safe_read(self):
+         # Ensure that safe_read only gets self.imap.MAXIMUM_SAFE_READ bytes
+         # at a time, and that it does collect everything.
+         # Setup a fake file to read from.
+         saved_file = self.imap.file
+         self.imap.file = StringIO.StringIO()
+         self.imap.file.write("".join(IMAP_MESSAGES.values()*10))
+         self.imap.file.seek(0)
+         try:
+             # First check when the size is less than the maximum.
+             self.assertEqual(len(self.imap.read(\
+                 self.imap.MAXIMUM_SAFE_READ-1)),
+                              self.imap.MAXIMUM_SAFE_READ-1)
+             # Check when the size is more than the maximum.
+             self.assertEqual(len(self.imap.read(\
+                 self.imap.MAXIMUM_SAFE_READ+1)),
+                              self.imap.MAXIMUM_SAFE_READ+1)
+             # Check that the read is called once when the size is smaller.
+             self._count = 0
+             self._imap_file_read = self.imap.file.read
+             self.imap.file.read = self._counter
+             self.imap.read(self.imap.MAXIMUM_SAFE_READ-1)
+             self.assertEqual(self._count, 1)
+             # Check that the read is called twice when the size is larger.
+             self._count = 0
+             self.imap.read(self.imap.MAXIMUM_SAFE_READ+1)
+             self.assertEqual(self._count, 2)
+         finally:
+             self.imap.file = saved_file
+ 
  
  class IMAPMessageTest(BaseIMAPFilterTest):



More information about the Spambayes-checkins mailing list