|
| 1 | +import re |
| 2 | +from buildbot.steps.shell import ShellCommand |
| 3 | +from buildbot.status.builder import SUCCESS, FAILURE, WARNINGS |
| 4 | + |
| 5 | +try: |
| 6 | + import cStringIO |
| 7 | + StringIO = cStringIO.StringIO |
| 8 | +except ImportError: |
| 9 | + from StringIO import StringIO |
| 10 | + |
| 11 | +class DjangoTest(ShellCommand): |
| 12 | + name = "django test" |
| 13 | + command = ["python", "manage.py", "test"] |
| 14 | + description = ["running django test"] |
| 15 | + descriptionDone = ["django test"] |
| 16 | + flunkOnFailure = False |
| 17 | + flunkingIssues = ["exception", "failure"] # any pyflakes lines like this cause FAILURE |
| 18 | + |
| 19 | + msgtypes = ("exception", "failure", "skipped", "diffs", "ok") |
| 20 | + |
| 21 | + def createSummary(self, log): |
| 22 | + summaries = {} |
| 23 | + typelist = {} |
| 24 | + counts = {} |
| 25 | + def count(m): |
| 26 | + if not m in counts: |
| 27 | + counts[m] = 0 |
| 28 | + counts[m] += 1 |
| 29 | + |
| 30 | + for type in self.msgtypes: |
| 31 | + typelist[type] = set([]) |
| 32 | + |
| 33 | + first = True |
| 34 | + for line in StringIO(log.getText()).readlines(): |
| 35 | + if re.search("^Traceback: ", line): |
| 36 | + m = "exception" |
| 37 | + typelist["exceptions"].add(m) |
| 38 | + count(m) |
| 39 | + if re.search("^Fail \d+ ", line): |
| 40 | + m = "fail_%s" % line.split()[1] |
| 41 | + typelist["failure"].add(m) |
| 42 | + count(m) |
| 43 | + if re.search("^Skipping ", line): |
| 44 | + m = "skipped" |
| 45 | + typelist["skipped"].add(m) |
| 46 | + count(m) |
| 47 | + if re.search("^Diff: .* ", line): |
| 48 | + m = "diff_%s" % line.skip()[1] |
| 49 | + typelist["diffs"].add(m) |
| 50 | + count(m) |
| 51 | + if re.search("^OK (\d+) ", line): |
| 52 | + m = "pass_%s" % line.split()[1] |
| 53 | + typelist["pass"].add(m) |
| 54 | + count(m) |
| 55 | + if re.search("^Pass (\d+) ", line): |
| 56 | + m = "pass_%s" % line.split()[1] |
| 57 | + typelist["pass"].add(m) |
| 58 | + count(m) |
| 59 | + if not m in summaries: |
| 60 | + summaries[m] = [] |
| 61 | + summaries[m].append(line) |
| 62 | + |
| 63 | + self.descriptionDone = self.descriptionDone[:] |
| 64 | + for type in self.msgtypes: |
| 65 | + for msg in typelist[type]: |
| 66 | + if counts[msg]: |
| 67 | + self.descriptionDone.append("%s=%d" % (msg, counts[msg])) |
| 68 | + self.addCompleteLog(msg, "".join(summaries[msg])) |
| 69 | + self.setProperty("urltest-%s" % type, sum([counts[msg] for msg in typelist[type]])) |
| 70 | + self.setProperty("urltest-total", sum(counts.values())) |
| 71 | + |
| 72 | + def evaluateCommand(self, cmd): |
| 73 | + if cmd.rc != 0: |
| 74 | + return FAILURE |
| 75 | + for type in self.flunkingIssues: |
| 76 | + if self.getProperty("urltest-%s" % type): |
| 77 | + return FAILURE |
| 78 | + if self.getProperty("urltest-total"): |
| 79 | + return WARNINGS |
| 80 | + return SUCCESS |
0 commit comments