diff --git a/tools/runner b/tools/runner index 7e220d5fb2def4904dd551ee1ec3af07b3d8ff73..1f96f6dd66dc5cc8d3bfe442280f3c4dfb1d1958 100755 --- a/tools/runner +++ b/tools/runner @@ -21,6 +21,7 @@ import unittest import tempfile import logging import time +import sys import os # list of test modules @@ -71,15 +72,9 @@ FUNC_TEST_MODULES = [ ] # configuration -UNIT_TESTS = True -FUNCTIONAL_TESTS = True -SEND_REPORT = False CONSOLE_LOG = False ATTACH_LOG = False # for ZODB test, only the client side is logged LOG_FILE = 'neo.log' -SENDER = 'gregory@nexedi.com' -RECIPIENTS = ['gregory@nexedi.com'] #['neo-report@erp5.org'] -SMTP_SERVER = ( "mail.nexedi.com", "25") # override logging configuration to send all messages to a file logger = logging.getLogger() @@ -276,7 +271,7 @@ class NeoTestRunner(unittest.TestResult): self.errors = self._buildErrors() self.warnings = self._buildWarnings() - def sendReport(self): + def sendReport(self, smtp_server, sender, recipients): """ Send a mail with the report summary """ import smtplib @@ -286,8 +281,8 @@ class NeoTestRunner(unittest.TestResult): # build the email msg = MIMEMultipart() msg['Subject'] = self.subject - msg['From'] = SENDER - msg['To'] = ', '.join(RECIPIENTS) + msg['From'] = sender + msg['To'] = ', '.join(recipients) #msg.preamble = self.subject msg.epilogue = '' @@ -306,13 +301,13 @@ class NeoTestRunner(unittest.TestResult): log.add_header('Content-Disposition', 'attachment', filename=LOG_FILE) msg.attach(log) - # Send the email via our own SMTP server. + # Send the email via a smtp server s = smtplib.SMTP() - s.connect(*SMTP_SERVER) + s.connect(*mail_server) mail = msg.as_string() - for recipient in RECIPIENTS: + for recipient in recipients: try: - s.sendmail(SENDER, recipient, mail) + s.sendmail(sender, recipient, mail) except smtplib.SMTPRecipientsRefused, e: print "Mail for %s fails : %s" % (recipient, e) s.close() @@ -323,25 +318,32 @@ if __name__ == "__main__": parser = optparse.OptionParser() parser.add_option('-f', '--functional', action='store_true') parser.add_option('-u', '--unit', action='store_true') + parser.add_option('', '--recipient', action='append') + parser.add_option('', '--sender') + parser.add_option('', '--server') (options, args) = parser.parse_args() - if options.functional or options.unit: - # override defaults - FUNCTIONAL_TESTS = options.functional - UNIT_TESTS = options.unit - if not UNIT_TESTS and not FUNCTIONAL_TESTS: - raise RuntimeError('Nothing to run') + # check arguments + if bool(options.sender) ^ bool(options.recipient): + sys.exit('Need a sender and recipients to mail report') + if not (options.unit o options.functional): + sys.exit('Nothing to run, please set -f and/or -u flag') + mail_server = options.server or '127.0.0.1:25' + mail_server = mail_server.split(':') - # run and build the report + # run requested tests runner = NeoTestRunner() - if UNIT_TESTS: + if options.unit: runner.run('Unit tests', UNIT_TEST_MODULES) - if FUNCTIONAL_TESTS: + if options.functional: runner.run('Functional tests', FUNC_TEST_MODULES) + + # build report runner.build() print runner.errors print runner.warnings print runner.summary + # send a mail - if SEND_REPORT: - runner.sendReport() + if options.sender: + runner.sendReport(mail_server, options.sender, options.recipient)