Commit a6d61a0e authored by Grégory Wisniewski's avatar Grégory Wisniewski

Update tests application :

- Make test module importation in a generic way
- Add informations on test system
- Improve report rendering


git-svn-id: https://svn.erp5.org/repos/neo/branches/prototype3@613 71dcc9de-d417-0410-9af5-da40c76e7ee4
parent 58d29260
......@@ -18,18 +18,26 @@
import unittest
import logging
import datetime
import time
# list of test modules
# each of them have to import its TestCase classes
TEST_MODULES = [
'neo.tests',
'neo.client.tests',
'neo.master.tests',
'neo.storage.tests'
]
# configuration
LOG_FILE = 'neo.log'
WITH_ZODB_TESTS = True
SEND_REPORT = True
CONSOLE_LOG = False
ATTACH_LOG = False # for ZODB test, only the client side is logged
LOG_FILE = 'neo.log'
SENDER = 'gregory@nexedi.com'
RECIPIENTS = ['neo-report@erp5.org']
RECIPIENTS = ['gregory@nexedi.com'] #['neo-report@erp5.org']
SMTP_SERVER = ( "mail.nexedi.com", "25")
ATTACH_LOG = False # for ZODB test, only the client side
CONSOLE_LOG = False
# override logging configuration to send all messages to a file
logger = logging.getLogger()
......@@ -39,18 +47,11 @@ format='[%(module)12s:%(levelname)s:%(lineno)3d] %(message)s'
formatter = logging.Formatter(format)
handler.setFormatter(formatter)
logger.addHandler(handler)
# enabled console logging is desired
# enabled console logging if desired
if CONSOLE_LOG:
handler = logging.StreamHandler()
handler.setFormatter(formatter)
logger.addHandler(handler)
logging.info("Tests started on %s" % datetime.date.today().isoformat())
# import all test modules
from neo.tests import *
from neo.client.tests import *
from neo.master.tests import *
from neo.storage.tests import *
class NeoTestResult(unittest.TestResult):
""" Custom result class to build report with statistics per module """
......@@ -79,6 +80,7 @@ class NeoTestResult(unittest.TestResult):
unittest.TestResult.startTest(self, test)
module = test.__class__.__name__
method = test._TestCase__testMethodName
print test
logging.info(" * TEST %s" % test)
self.lastStart = time.time()
......@@ -100,17 +102,37 @@ class NeoTestResult(unittest.TestResult):
stats.failures += 1
self._updateTimer(stats)
def _buildSystemInfo(self):
import platform
import datetime
s = """
Date : %s
Node : %s
Processor : %s (%s)
System : %s (%s)
""" % (
datetime.date.today().isoformat(),
platform.node(),
platform.processor(),
platform.architecture()[0],
platform.system(),
platform.release(),
)
return s
def _buildSummary(self):
s = '\n NEO TESTS REPORT'
s = ' ' * 30 + ' NEO TESTS REPORT'
s += '\n'
s += self._buildSystemInfo()
s += '\n'
s += " Test Module | run | error | fail | took \n"
s += " Test Module | run | error | fail | time \n"
s += "-------------------------------+--------+--------+--------+----------\n"
format = "%30s | %3d | %3d | %3d | %6.2fs \n"
for k, v in self.modulesStats.items():
args = (k, v.success, v.errors, v.failures, v.time)
s += format % args
args = ("Summary", self.testsRun, len(self.errors), len(self.failures),
self.time)
errors, failures = len(self.errors) or '.', len(self.failures) or '.'
args = ("Summary", self.testsRun, errors, failures, self.time)
s += "-------------------------------+--------+--------+--------+----------\n"
s += format % args
s += '\n'
......@@ -182,24 +204,28 @@ def sendReport(result):
s.sendmail(SENDER, recipient, mail)
s.close()
def buildTestSuite():
suite = unittest.TestSuite()
loader = unittest.defaultTestLoader
# load neo tests
for test_module in TEST_MODULES:
test_module = __import__(test_module, globals(), locals(), ['*'])
suite.addTests(loader.loadTestsFromModule(test_module))
# load ZODB tests
if WITH_ZODB_TESTS:
from neo.client.tests.testZODB import ZODBTests
suite.addTests(unittest.makeSuite(ZODBTests, 'check'))
return suite
if __name__ == "__main__":
# load functional tests
from neo.client.tests.testZODB import ZODBTests
tests = unittest.makeSuite(ZODBTests, 'check')
loader = unittest.defaultTestLoader
# load test cases from itself
self = __import__(__name__)
tests.addTests(loader.loadTestsFromModule(self))
# run and build the report
result = NeoTestResult()
tests.run(result)
suite = buildTestSuite()
suite.run(result)
result.build()
# send a mail
if SEND_REPORT:
sendReport(result)
else:
print result.subject
print result.summary
print result.errors
print result.summary
print result.errors
Markdown is supported
0%
or
You are about to add 0 people to the discussion. Proceed with caution.
Finish editing this message first!
Please register or to comment