| OLD | NEW |
| (Empty) |
| 1 | |
| 2 from twisted.web import resource | |
| 3 from twisted.web.error import NoResource | |
| 4 | |
| 5 # these are our test result types. Steps are responsible for mapping results | |
| 6 # into these values. | |
| 7 SKIP, EXPECTED_FAILURE, FAILURE, ERROR, UNEXPECTED_SUCCESS, SUCCESS = \ | |
| 8 "skip", "expected failure", "failure", "error", "unexpected success", \ | |
| 9 "success" | |
| 10 UNKNOWN = "unknown" # catch-all | |
| 11 | |
| 12 | |
| 13 class OneTest(resource.Resource): | |
| 14 isLeaf = 1 | |
| 15 def __init__(self, parent, testName, results): | |
| 16 self.parent = parent | |
| 17 self.testName = testName | |
| 18 self.resultType, self.results = results | |
| 19 | |
| 20 def render(self, request): | |
| 21 request.setHeader("content-type", "text/html") | |
| 22 if request.method == "HEAD": | |
| 23 request.setHeader("content-length", len(self.html(request))) | |
| 24 return '' | |
| 25 return self.html(request) | |
| 26 | |
| 27 def html(self, request): | |
| 28 # turn ourselves into HTML | |
| 29 raise NotImplementedError | |
| 30 | |
| 31 class TestResults(resource.Resource): | |
| 32 oneTestClass = OneTest | |
| 33 def __init__(self): | |
| 34 resource.Resource.__init__(self) | |
| 35 self.tests = {} | |
| 36 def addTest(self, testName, resultType, results=None): | |
| 37 self.tests[testName] = (resultType, results) | |
| 38 # TODO: .setName and .delete should be used on our Swappable | |
| 39 def countTests(self): | |
| 40 return len(self.tests) | |
| 41 def countFailures(self): | |
| 42 failures = 0 | |
| 43 for t in self.tests.values(): | |
| 44 if t[0] in (FAILURE, ERROR): | |
| 45 failures += 1 | |
| 46 return failures | |
| 47 def summary(self): | |
| 48 """Return a short list of text strings as a summary, suitable for | |
| 49 inclusion in an Event""" | |
| 50 return ["some", "tests"] | |
| 51 def describeOneTest(self, testname): | |
| 52 return "%s: %s\n" % (testname, self.tests[testname][0]) | |
| 53 def html(self): | |
| 54 data = "<html>\n<head><title>Test Results</title></head>\n" | |
| 55 data += "<body>\n" | |
| 56 data += "<pre>\n" | |
| 57 tests = self.tests.keys() | |
| 58 tests.sort() | |
| 59 for testname in tests: | |
| 60 data += self.describeOneTest(testname) | |
| 61 data += "</pre>\n" | |
| 62 data += "</body></html>\n" | |
| 63 return data | |
| 64 def render(self, request): | |
| 65 request.setHeader("content-type", "text/html") | |
| 66 if request.method == "HEAD": | |
| 67 request.setHeader("content-length", len(self.html())) | |
| 68 return '' | |
| 69 return self.html() | |
| 70 def getChild(self, path, request): | |
| 71 if self.tests.has_key(path): | |
| 72 return self.oneTestClass(self, path, self.tests[path]) | |
| 73 return NoResource("No such test '%s'" % path) | |
| OLD | NEW |