109
110
HelperTestCase.tearDown(self)
110
111
MockerTestCase.tearDown(self)
113
def successResultOf(self, deferred):
114
"""See C{twisted.trial._synctest._Assertions.successResultOf}.
116
This is a copy of the original method, which is available only
117
since Twisted 12.3.0 (from 2012-12-20).
120
deferred.addBoth(result.append)
123
"Success result expected on %r, found no result instead" % (
125
elif isinstance(result[0], Failure):
127
"Success result expected on %r, "
128
"found failure result (%r) instead" % (deferred, result[0]))
132
def failureResultOf(self, deferred):
133
"""See C{twisted.trial._synctest._Assertions.failureResultOf}.
135
This is a copy of the original method, which is available only
136
since Twisted 12.3.0 (from 2012-12-20).
139
deferred.addBoth(result.append)
142
"Failure result expected on %r, found no result instead" % (
144
elif not isinstance(result[0], Failure):
146
"Failure result expected on %r, "
147
"found success result (%r) instead" % (deferred, result[0]))
151
def assertNoResult(self, deferred):
152
"""See C{twisted.trial._synctest._Assertions.assertNoResult}.
154
This is a copy of the original method, which is available only
155
since Twisted 12.3.0 (from 2012-12-20).
158
deferred.addBoth(result.append)
161
"No result expected on %r, found %r instead" % (
162
deferred, result[0]))
112
164
def assertDeferredSucceeded(self, deferred):
113
165
self.assertTrue(isinstance(deferred, Deferred))
306
358
reactor_factory = FakeReactor
307
359
transport_factory = FakeTransport
309
def stopService(service):
310
# We need to explictely stop listening to the socket
311
# because the reactor would still have active selectables
312
# at the end of the test otherwise
313
if os.path.exists(service.port.port):
314
service.port.connectionLost(None)
315
super(FakeBrokerService, service).stopService()
317
361
test_case.broker_service = FakeBrokerService(config)
318
362
test_case.remote = FakeRemoteBroker(
319
363
test_case.broker_service.exchanger,
320
test_case.broker_service.message_store)
364
test_case.broker_service.message_store,
365
test_case.broker_service.broker)
323
368
class BrokerServiceHelper(FakeBrokerServiceHelper):
599
639
"""Remove sample data for the process that matches C{process_id}."""
600
640
process_dir = os.path.join(self._sample_dir, str(process_id))
601
641
shutil.rmtree(process_dir)
604
from twisted.python import log
605
from twisted.python import failure
606
from twisted.trial import reporter
609
def install_trial_hack():
611
Trial's TestCase in Twisted 2.2 had a bug which would prevent
612
certain errors from being reported when being run in a non-trial
613
test runner. This function monkeypatches trial to fix the bug, and
614
only takes effect if using Twisted 2.2.
616
from twisted.trial.itrial import IReporter
617
if "addError" in IReporter:
618
# We have no need for this monkey patch with newer versions of Twisted.
621
def run(self, result):
623
Copied from twisted.trial.unittest.TestCase.run, but some
624
lines from Twisted 2.5.
626
log.msg("--> %s <--" % (self.id()))
629
if not isinstance(result, reporter.TestResult):
630
result = PyUnitResultAdapter(result)
631
# End from Twisted 2.5
633
self._timedOut = False
634
if self._shared and self not in self.__class__._instances:
635
self.__class__._instances.add(self)
636
result.startTest(self)
637
if self.getSkip(): # don't run test methods that are marked as .skip
638
result.addSkip(self, self.getSkip())
639
result.stopTest(self)
642
if hasattr(self, "_installObserver"):
643
self._installObserver()
644
# End from Twisted 2.5
648
first = self._isFirst()
649
self.__class__._instancesRun.add(self)
651
d = self.deferSetUpClass(result)
653
d = self.deferSetUp(None, result)
657
self._cleanUp(result)
658
result.stopTest(self)
659
if self._shared and self._isLast():
660
self._initInstances()
661
self._classCleanUp(result)
663
self._classCleanUp(result)
666
### Copied from Twisted, to fix a bug in trial in Twisted 2.2! ###
669
class UnsupportedTrialFeature(Exception):
670
"""A feature of twisted.trial was used that pyunit cannot support."""
673
class PyUnitResultAdapter(object):
675
Wrap a C{TestResult} from the standard library's C{unittest} so that it
676
supports the extended result types from Trial, and also supports
677
L{twisted.python.failure.Failure}s being passed to L{addError} and
680
@param original: A C{TestResult} instance from C{unittest}.
683
def __init__(self, original):
684
self.original = original
686
def _exc_info(self, err):
687
if isinstance(err, failure.Failure):
688
# Unwrap the Failure into a exc_info tuple.
689
err = (err.type, err.value, err.tb)
692
def startTest(self, method):
693
# We'll need this later in cleanupErrors.
694
self.__currentTest = method
695
self.original.startTest(method)
697
def stopTest(self, method):
698
self.original.stopTest(method)
700
def addFailure(self, test, fail):
701
self.original.addFailure(test, self._exc_info(fail))
703
def addError(self, test, error):
704
self.original.addError(test, self._exc_info(error))
706
def _unsupported(self, test, feature, info):
707
self.original.addFailure(
709
(UnsupportedTrialFeature,
710
UnsupportedTrialFeature(feature, info),
713
def addSkip(self, test, reason):
715
Report the skip as a failure.
717
self._unsupported(test, 'skip', reason)
719
def addUnexpectedSuccess(self, test, todo):
721
Report the unexpected success as a failure.
723
self._unsupported(test, 'unexpected success', todo)
725
def addExpectedFailure(self, test, error):
727
Report the expected failure (i.e. todo) as a failure.
729
self._unsupported(test, 'expected failure', error)
731
def addSuccess(self, test):
732
self.original.addSuccess(test)
734
def upDownError(self, method, error, warn, printStatus):
737
def cleanupErrors(self, errs):
738
# Let's consider cleanupErrors as REAL errors. In recent
739
# Twisted this is the default behavior, and cleanupErrors
741
self.addError(self.__currentTest, errs)
743
def startSuite(self, name):
746
### END COPY FROM TWISTED ###