[Spambayes-checkins] spambayes/spambayes/test test_message.py, 1.5, 1.6

Tony Meyer anadelonbrin at users.sourceforge.net
Tue Jan 4 04:23:26 CET 2005


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

Modified Files:
	test_message.py 
Log Message:
Make compatible with Python 2.2.

Add a test for delNotations when there is no subject/to header.

Fix a bug in the delNotations only once test.

If a dbm module isn't available, then skip the MessageInfoDBTest suite.

Index: test_message.py
===================================================================
RCS file: /cvsroot/spambayes/spambayes/spambayes/test/test_message.py,v
retrieving revision 1.5
retrieving revision 1.6
diff -C2 -d -r1.5 -r1.6
*** test_message.py	2 Jan 2005 05:19:25 -0000	1.5
--- test_message.py	4 Jan 2005 03:23:23 -0000	1.6
***************
*** 468,472 ****
                  # Add a notation to the header
                  header = self.msg[headername]
!                 self.assert_(disp not in header)
                  options["Headers", "notate_%s" % (headername,)] = \
                                     (self.ham, self.unsure, self.spam)
--- 468,472 ----
                  # Add a notation to the header
                  header = self.msg[headername]
!                 self.assertEqual(header.find(disp), -1)
                  options["Headers", "notate_%s" % (headername,)] = \
                                     (self.ham, self.unsure, self.spam)
***************
*** 474,478 ****
                          self.unsure:self.u_prob}[disp]
                  self.msg.addSBHeaders(prob, self.clues)
!                 self.assert_(disp in self.msg[headername])
                  # Remove it
                  self.msg.delNotations()
--- 474,478 ----
                          self.unsure:self.u_prob}[disp]
                  self.msg.addSBHeaders(prob, self.clues)
!                 self.assertNotEqual(self.msg[headername].find(disp), -1)
                  # Remove it
                  self.msg.delNotations()
***************
*** 486,523 ****
                  # Add a notation to the header
                  header = self.msg[headername]
!                 self.assert_(disp not in header)
                  options["Headers", "notate_%s" % (headername,)] = ()
                  prob = {self.ham:self.g_prob, self.spam:self.s_prob,
                          self.unsure:self.u_prob}[disp]
                  self.msg.addSBHeaders(prob, self.clues)
!                 self.assert_(disp not in self.msg[headername])
                  # Remove it
                  self.msg.delNotations()
                  self.assertEqual(self.msg[headername], header)
  
!     def test_delNotations_only_once(self):
!         # Check that only one disposition is removed, even if more than
!         # one is present.
          for headername in ["subject", "to"]:
              for disp in (self.ham, self.spam, self.unsure):
!                 # Add a notation to the header
!                 header = self.msg[headername]
!                 self.assert_(disp not in header)
                  options["Headers", "notate_%s" % (headername,)] = \
                                     (self.ham, self.unsure, self.spam)
-                 prob = {self.ham:self.g_prob, self.spam:self.s_prob,
-                         self.unsure:self.u_prob}[disp]
-                 self.msg.addSBHeaders(prob, self.clues)
-                 self.assert_(disp in self.msg[headername])
-                 header2 = self.msg[headername]
-                 # Add a second notation
-                 self.msg.addSBHeaders(prob, self.clues)
-                 self.assert_(disp in
-                              self.msg[headername].replace(disp, "", 1))
-                 # Remove it
                  self.msg.delNotations()
!                 self.assertEqual(self.msg[headername], header2)
!                 # Restore for next time round the loop
!                 self.msg.replace_header(headername, header)
  
  
--- 486,538 ----
                  # Add a notation to the header
                  header = self.msg[headername]
!                 self.assertEqual(header.find(disp), -1)
                  options["Headers", "notate_%s" % (headername,)] = ()
                  prob = {self.ham:self.g_prob, self.spam:self.s_prob,
                          self.unsure:self.u_prob}[disp]
                  self.msg.addSBHeaders(prob, self.clues)
!                 self.assertEqual(self.msg[headername].find(disp), -1)
                  # Remove it
                  self.msg.delNotations()
                  self.assertEqual(self.msg[headername], header)
  
!     def test_delNotations_no_header(self):
!         # Check that it works if there is no subject/to header.
          for headername in ["subject", "to"]:
              for disp in (self.ham, self.spam, self.unsure):
!                 del self.msg[headername]
                  options["Headers", "notate_%s" % (headername,)] = \
                                     (self.ham, self.unsure, self.spam)
                  self.msg.delNotations()
!                 self.assertEqual(self.msg[headername], None)
! 
!     def test_delNotations_only_once_subject(self):
!         self._test_delNotations_only_once("subject")
! 
!     def test_delNotations_only_once_to(self):
!         self._test_delNotations_only_once("to")
!         
!     def _test_delNotations_only_once(self, headername):
!         # Check that only one disposition is removed, even if more than
!         # one is present.
!         for disp in (self.ham, self.spam, self.unsure):
!             # Add a notation to the header
!             header = self.msg[headername]
!             self.assertEqual(header.find(disp), -1)
!             options["Headers", "notate_%s" % (headername,)] = \
!                                (self.ham, self.unsure, self.spam)
!             prob = {self.ham:self.g_prob, self.spam:self.s_prob,
!                     self.unsure:self.u_prob}[disp]
!             self.msg.addSBHeaders(prob, self.clues)
!             self.assertNotEqual(self.msg[headername].find(disp), -1)
!             header2 = self.msg[headername]
!             # Add a second notation
!             self.msg.addSBHeaders(prob, self.clues)
!             self.assertNotEqual(self.msg[headername].\
!                                 replace(disp, "", 1).find(disp), -1)
!             # Remove it
!             self.msg.delNotations()
!             self.assertEqual(self.msg[headername], header2)
!             # Restore for next time round the loop
!             self.msg.replace_header(headername, header)
  
  
***************
*** 720,729 ****
  def suite():
      suite = unittest.TestSuite()
!     for cls in (MessageTest,
!                 SBHeaderMessageTest,
!                 MessageInfoPickleTest,
!                 MessageInfoDBTest,
!                 UtilitiesTest,
!                ):
          suite.addTest(unittest.makeSuite(cls))
      return suite
--- 735,757 ----
  def suite():
      suite = unittest.TestSuite()
!     classes = (MessageTest,
!                SBHeaderMessageTest,
!                MessageInfoPickleTest,
!                UtilitiesTest,
!                )
!     from spambayes import dbmstorage
!     try:
!         dbmstorage.open_best()
!     except dbmstorage.error:
!         print "Skipping MessageInfoDBTest - no dbm module available"
!         from spambayes import message
!         def always_pickle():
!             return "__test.pik", "pickle"
!         message.database_type = always_pickle
!     except TypeError:
!         # We need an argument, so TypeError will be raised
!         # when it *is* available.
!         classes += (MessageInfoDBTest,)
!     for cls in classes:
          suite.addTest(unittest.makeSuite(cls))
      return suite



More information about the Spambayes-checkins mailing list