638
639
"""Remove sample data for the process that matches C{process_id}."""
639
640
process_dir = os.path.join(self._sample_dir, str(process_id))
640
641
shutil.rmtree(process_dir)
643
from twisted.python import log
644
from twisted.python import failure
645
from twisted.trial import reporter
648
def install_trial_hack():
650
Trial's TestCase in Twisted 2.2 had a bug which would prevent
651
certain errors from being reported when being run in a non-trial
652
test runner. This function monkeypatches trial to fix the bug, and
653
only takes effect if using Twisted 2.2.
655
from twisted.trial.itrial import IReporter
656
if "addError" in IReporter:
657
# We have no need for this monkey patch with newer versions of Twisted.
660
def run(self, result):
662
Copied from twisted.trial.unittest.TestCase.run, but some
663
lines from Twisted 2.5.
665
log.msg("--> %s <--" % (self.id()))
668
if not isinstance(result, reporter.TestResult):
669
result = PyUnitResultAdapter(result)
670
# End from Twisted 2.5
672
self._timedOut = False
673
if self._shared and self not in self.__class__._instances:
674
self.__class__._instances.add(self)
675
result.startTest(self)
676
if self.getSkip(): # don't run test methods that are marked as .skip
677
result.addSkip(self, self.getSkip())
678
result.stopTest(self)
681
if hasattr(self, "_installObserver"):
682
self._installObserver()
683
# End from Twisted 2.5
687
first = self._isFirst()
688
self.__class__._instancesRun.add(self)
690
d = self.deferSetUpClass(result)
692
d = self.deferSetUp(None, result)
696
self._cleanUp(result)
697
result.stopTest(self)
698
if self._shared and self._isLast():
699
self._initInstances()
700
self._classCleanUp(result)
702
self._classCleanUp(result)
705
### Copied from Twisted, to fix a bug in trial in Twisted 2.2! ###
708
class UnsupportedTrialFeature(Exception):
709
"""A feature of twisted.trial was used that pyunit cannot support."""
712
class PyUnitResultAdapter(object):
714
Wrap a C{TestResult} from the standard library's C{unittest} so that it
715
supports the extended result types from Trial, and also supports
716
L{twisted.python.failure.Failure}s being passed to L{addError} and
719
@param original: A C{TestResult} instance from C{unittest}.
722
def __init__(self, original):
723
self.original = original
725
def _exc_info(self, err):
726
if isinstance(err, failure.Failure):
727
# Unwrap the Failure into a exc_info tuple.
728
err = (err.type, err.value, err.tb)
731
def startTest(self, method):
732
# We'll need this later in cleanupErrors.
733
self.__currentTest = method
734
self.original.startTest(method)
736
def stopTest(self, method):
737
self.original.stopTest(method)
739
def addFailure(self, test, fail):
740
self.original.addFailure(test, self._exc_info(fail))
742
def addError(self, test, error):
743
self.original.addError(test, self._exc_info(error))
745
def _unsupported(self, test, feature, info):
746
self.original.addFailure(
748
(UnsupportedTrialFeature,
749
UnsupportedTrialFeature(feature, info),
752
def addSkip(self, test, reason):
754
Report the skip as a failure.
756
self._unsupported(test, 'skip', reason)
758
def addUnexpectedSuccess(self, test, todo):
760
Report the unexpected success as a failure.
762
self._unsupported(test, 'unexpected success', todo)
764
def addExpectedFailure(self, test, error):
766
Report the expected failure (i.e. todo) as a failure.
768
self._unsupported(test, 'expected failure', error)
770
def addSuccess(self, test):
771
self.original.addSuccess(test)
773
def upDownError(self, method, error, warn, printStatus):
776
def cleanupErrors(self, errs):
777
# Let's consider cleanupErrors as REAL errors. In recent
778
# Twisted this is the default behavior, and cleanupErrors
780
self.addError(self.__currentTest, errs)
782
def startSuite(self, name):
785
### END COPY FROM TWISTED ###