def run(): try: opts, args = getopt.getopt(sys.argv[1:], "ht") except getopt.error as msg: print(str(msg) + "\n\n" + __doc__, file=sys.stderr) sys.exit() for opt, arg in opts: if opt == "-h": print(__doc__, file=sys.stderr) sys.exit() elif opt == "-t": state.isTest = True state.runTestServer = True state.createWorkers() if state.runTestServer: print("Running a test SMTP server on port 8025...") TestListener() asyncore.loop() else: state.isTest = True state.buildServerStrings() testSocketMap = {} def runTestServer(): TestListener(socketMap=testSocketMap) asyncore.loop(map=testSocketMap) def runProxy(): trainer = SMTPTrainer(Classifier(), state) BayesSMTPProxyListener("localhost", 8025, ("", 8026), trainer) Dibbler.run() _thread.start_new_thread(runTestServer, ()) _thread.start_new_thread(runProxy, ()) sb_test_support.unittest_main(argv=sys.argv + ["suite"])
for opt, arg in opts: if opt == '-h': print >>sys.stderr, __doc__ sys.exit() elif opt == '-t': state.isTest = True state.runTestServer = True state.createWorkers() if state.runTestServer: print "Running a test SMTP server on port 8025..." TestListener() asyncore.loop() else: state.isTest = True state.buildServerStrings() testSocketMap = {} def runTestServer(): TestListener(socketMap=testSocketMap) asyncore.loop(map=testSocketMap) def runProxy(): global bayes bayes = Classifier() trainer = SMTPTrainer(bayes, state) BayesSMTPProxyListener('localhost', 8025, ('', 8026), trainer) Dibbler.run() thread.start_new_thread(runTestServer, ()) thread.start_new_thread(runProxy, ()) sb_test_support.unittest_main(argv=sys.argv + ['suite']) if __name__ == '__main__': run()
class IMAPFileMessageFactoryTest(unittest.TestCase): def testCreateNoContent(self): factory = IMAPFileMessageFactory() msg = factory.create("key", "directory") self.assertEqual(msg.id, key) self.assert_(isinstance(msg, type(IMAPFileMessage()))) def suite(): suite = unittest.TestSuite() for cls in ( IMAPMessageTest, DynamicIMAPMessageTest, IMAPFileMessageTest, ): suite.addTest(unittest.makeSuite(cls)) return suite if __name__ == '__main__': def runTestServer(): from spambayes import asyncore asyncore.loop() TestListener() thread.start_new_thread(runTestServer, ()) sb_test_support.unittest_main(argv=sys.argv + ['suite'])
self.s.CalculatePersistentStats() self.assertEqual(self.s.GetStats(), ["Messages classified: 0"]) def test_from_specified_date(self): self._stuff_with_persistent_data() time.sleep(0.1) self.s.from_date = time.time() time.sleep(0.1) msg = Message("0") msg.RememberTrained(True) msg.RememberClassification(options["Headers", "header_spam_string"]) msg = Message("7") msg.RememberTrained(False) msg.RememberClassification(options["Headers", "header_spam_string"]) msg = Message("2") msg.RememberTrained(True) msg.RememberClassification(options["Headers", "header_ham_string"]) self.s.CalculatePersistentStats() self.assertEqual(self.s.GetStats()[0], "Messages classified: 3") def suite(): suite = unittest.TestSuite() for cls in (StatsTest,): suite.addTest(unittest.makeSuite(cls)) return suite if __name__ == "__main__": sb_test_support.unittest_main(argv=sys.argv + ["suite"])
port = options["html_ui", "port"] call_web_function ('http://localhost:%d/save' % port, how='Save & shutdown') for i in range(10): time.sleep(0.5) status = win32serviceutil.QueryServiceStatus(service_name) if status[1] == win32service.SERVICE_STOPPED: break else: self.fail("Gave up waiting for service to stop") self.failUnless(not is_any_sb_server_running(), "Should be no platform mutex held after stopping") if __name__=='__main__': sb_test_support.unittest_main()
def _stop_service(self): # StopServiceWithDeps checks the status of each service as it # stops it, which is exactly what we want here. win32serviceutil.StopServiceWithDeps(service_name) def test_simple_startstop(self): self._start_service() self._stop_service() def test_remote_shutdown(self): self._start_service() # Should be using the default port from the options file. from spambayes.Options import options port = options["html_ui", "port"] call_web_function('http://localhost:%d/save' % port, how='Save & shutdown') # wait for it to stop - 5 secs, 0.25 per check for i in range(10): time.sleep(0.5) status = win32serviceutil.QueryServiceStatus(service_name) if status[1] == win32service.SERVICE_STOPPED: break else: self.fail("Gave up waiting for service to stop") self.failUnless(not is_any_sb_server_running(), "Should be no platform mutex held after stopping") if __name__ == '__main__': sb_test_support.unittest_main()