From 5f38c12de480b362fc8b64aa0f9de091fbb34a35 Mon Sep 17 00:00:00 2001 From: buildbot Date: Thu, 19 Mar 2015 22:12:04 +0000 Subject: [PATCH] Added a custom UnitTest Step class, for the django test steps. - Legacy-Id: 9254 --- buildbot/masters/datatracker/master.cfg | 69 +++++++++++++++++++++++-- 1 file changed, 66 insertions(+), 3 deletions(-) diff --git a/buildbot/masters/datatracker/master.cfg b/buildbot/masters/datatracker/master.cfg index d1eb4998e..ea086bfe3 100644 --- a/buildbot/masters/datatracker/master.cfg +++ b/buildbot/masters/datatracker/master.cfg @@ -50,7 +50,6 @@ c['change_source'] = [ # case, just kick off a 'runtests' build from buildbot.schedulers.basic import SingleBranchScheduler, AnyBranchScheduler -from buildbot.schedulers.forcesched import ForceScheduler from buildbot.changes import filter c['schedulers'] = [ AnyBranchScheduler(name="pyflakes", treeStableTimer=10, builderNames=["Check PyFlakes"]), @@ -85,6 +84,70 @@ class TestCrawlerShellCommand(WarningCountingShellCommand): command=["bin/test-crawl"] warningPattern = '.* FAIL' +class UnitTest(WarningCountingShellCommand): + + name = "test" + warnOnFailure = 1 + description = ["testing"] + descriptionDone = ["test"] + command = ["python", "-m", "unittest", "discover"] + + regexPatterns = { + "total": "Ran (\d+) tests in [0-9.]+s", + "time": "Ran \d+ tests in ([0-9.]+)s", + "skipped": "(?:OK|FAILED).*\skipped=(\d+)", + "failed": "FAILED.*failures\=(\d+)", + "errors": "FAILED.*errors\=(\d+)", + "template_coverage":" *Template coverage: +([0-9.]+%)", + "url_coverage": " *Url coverage: +([0-9.]+%)", + "code_coverage": " *Code coverage: +([0-9.]+%)", + } + + def setTestResults(self, **kwargs): + """ + Called by subclasses to set the relevant statistics; this actually + adds to any statistics already present + """ + for kw in kwargs: + value = kwargs[kw] + if value.isdigit(): + # Counter + value = int(value) + value += self.step_status.getStatistic(kw, 0) + elif re.match("[0-9]+\.[0-9]+$"): + # Runtime + value = float(value) + value += self.step_status.getStatistic(kw, 0) + else: + # This is a percentage, and we can't add them + pass + self.step_status.setStatistic(kw, value) + + def createSummary(self, log): + info = {} + for line in log.getText().split("\n"): + for key in regexPatterns: + regex = regexPatterns[key] + match = re.match(regex, line) + if match: + info[key] = match.group(1) + self.setTestResults(**info) + + def describe(self, done=False): + description = WarningCountingShellCommand.describe(self, done) + if done: + description = description[:] # make a private copy + for name in self.step_status.statistics: + value = self.step_status.getStatistic(name) + if type(value) is float: # this is run-time + description.append('%.2fs %s' % (value, name)) + elif type(value) is int: + description.append('%d %s' % (value, name)) + else: + description.append('%s %s' % (value, name)) + return description + + ## Set up builders c['builders'] = [] @@ -139,7 +202,7 @@ factory.addStep(ShellCommand( haltOnFailure=True, command=["pip", "install", "-r", "requirements.txt"], )) -factory.addStep(Test( +factory.addStep(UnitTest( workdir=Interpolate('build/%(src::branch)s'), haltOnFailure=True, command=["ietf/manage.py", "test", "--settings=settings_sqlitetest"], @@ -173,7 +236,7 @@ factory.addStep(ShellCommand( haltOnFailure=True, command=["pip", "install", "-r", "requirements.txt"], )) -factory.addStep(Test( +factory.addStep(UnitTest( workdir=Interpolate('build/%(src::branch)s'), haltOnFailure=True, command=["ietf/manage.py", "test", "--settings=settings_sqlitetest"],