def _end(self, reason):
     unittest.failIf(reason.check(error.ProcessDone), "Child should fail due to EPIPE.")
     reason.trap(error.ProcessTerminated)
     # child must not get past that write without raising
     unittest.failIfEqual(reason.value.exitCode, 42)
     unittest.failUnlessEqual(self.output, "")
     return self.errput
    def checkResults(self, method):
        def _dbg(msg):
            log.msg(iface=itrial.ITrialDebug, testTests=msg)

        tm = itrial.ITestMethod(method)

        failUnlessEqual(tm.runs, 1)
        failUnless(tm.startTime > 0)
        #failUnless(tm.endTime > 0)   # failed tests don't have endTime set
        failUnless(tm.name, "tm.name not set")
        failUnless(tm.klass, "tm.klass not set")
        failUnless(tm.module, "tm.module not set")
        failUnless(tm.setUp, "tm.setUp not set")
        failUnless(tm.tearDown, "tm.tearDown not set")
        

        def _checkStatus(meth, status):
            statusmsg = "test did not return status %s, instead returned %s" % (status, meth.status)
            if meth.errors and status is not ERROR:
                statusmsg += "\n\n%s" % (''.join(["\t%s\n" % line for line in
                                                  ''.join([f.getTraceback() for f in meth.errors]
                                        ).split('\n')]))
            failUnlessEqual(meth.status, status, statusmsg)

        def _checkTimeoutError(meth):
            if meth.timeout is not None:
                failUnless(meth.hasTbs, 'method did not have tracebacks!')
                f = meth.errors[0]
                failUnlessEqual(f.type, defer.TimeoutError)

        try:
            failUnless(tm.startTime > 0.0, "%f not > 0.0" % (tm.startTime,))
##             failUnless(tm.endTime > 0.0, "%f not > 0.0" % (tm.endTime,))
##             failUnless(tm.endTime > tm.startTime, "%f not > %f" % (tm.endTime,tm.startTime))

            if tm.name.endswith("_pass"):
                _checkStatus(tm, SUCCESS)
                failIf(tm.todo)
                failIf(tm.hasTbs)
                failIf(tm.skip)

            elif tm.name.endswith("_fail"):
                _checkStatus(tm, FAILURE)
                _checkTimeoutError(tm)
                failIf(tm.skip)
                failIf(tm.errors)
                failUnless(tm.hasTbs)
                failUnless(len(tm.failures) == 1,
                           "%s had %d failures" % (tm.name,
                                                   len(tm.failures)))
            elif tm.name.endswith("_error"):
                _checkStatus(tm, ERROR)
                _checkTimeoutError(tm)
                failUnless(tm.hasTbs)
                failUnless(len(tm.errors) == 1,
                           "%s had %d errors" % (tm.name,
                                                 len(tm.errors)))

                # with new-style todos it's possible for a todoed method to
                # wind up counting as a ERROR
                # failIf(tm.todo)
                failIf(tm.skip)
                failIf(tm.failures)

            elif tm.name.endswith("_skip"):
                _checkStatus(tm, SKIP)
                failUnless(tm.skip, "skip reason not set")
                failIf(tm.todo)
                failIf(tm.errors)
                failIf(tm.failures)
                failIf(tm.hasTbs)

            elif tm.name.endswith("_exfail"):
                _checkStatus(tm, EXPECTED_FAILURE)
                _checkTimeoutError(tm)
                failUnless(tm.hasTbs)
                failUnless(tm.errors or tm.failures)
                failUnless(tm.todo)
                failIf(tm.skip)

            elif tm.name.endswith("_unexpass"):
                _checkStatus(tm, UNEXPECTED_SUCCESS)
                _checkTimeoutError(tm)
                failUnless(tm.todo)
                failIf(tm.skip)

            elif tm.name.endswith("_timeout"):
                failUnless(tm.errors, "tm.errors was %s" % (tm.errors,))
                expectedExc, f = tm.original.t_excClass, tm.errors[0]
                failUnless(f.check(expectedExc),
                           "exception '%s', with tb:\n%s\n\n was not of expected type '%s'" % (
                           f, f.getTraceback(), expectedExc))
                failUnlessEqual(f.value.args[0], tm.original.t_excArg)
                failUnlessEqual(itrial.ITimeout(tm.timeout).duration, tm.original.t_duration)

            elif tm.name.endswith("_timeoutClassAttr"):
                failUnless(tm.errors, "tm.errors was %s" % (tm.errors,))
                expectedExc, f = tm.klass.t_excClass, tm.errors[0]
                failUnless(f.check(expectedExc),
                           "exception '%s', with tb:\n%s\n\n was not of expected type '%s'" % (
                           f, f.getTraceback(), expectedExc))
                failUnlessEqual(f.value.args[0], tm.klass.t_excArg)
                failUnlessEqual(itrial.ITimeout(tm.timeout).duration, tm.klass.t_duration)

            elif tm.name.endswith("_skipClassAttr"):
                failUnlessEqual(tm.skip, CLASS_SKIP_MSG)

            elif tm.name.endswith("_skipAttr"):
                failUnlessEqual(tm.skip, METHOD_SKIP_MSG)

            elif tm.name.endswith("_todoClassAttr"):
                failUnlessEqual(tm.todo, CLASS_TODO_MSG)

            elif tm.name.endswith("_todoAttr"):
                failUnlessEqual(tm.todo, METHOD_TODO_MSG)

            else:
                raise unittest.FailTest, "didn't have tests for a method ending in %s" % (
                                         tm.name.split('_')[1],)
        except unittest.FailTest:
            tb = failure.Failure().getTraceback()
            raise unittest.FailTest, "error occured in test %s: %s" % (tm.name, tb)