'If the context factory passed to L{ITCPTransport.startTLS} raises an
exception from its C{getContext} method, that exception is raised by
L{ITCPTransport.startTLS}.'

def test_badContext(self):

    reactor = self.buildReactor()
    brokenFactory = BrokenContextFactory()
    results = []
    serverFactory = ServerFactory.forProtocol(Protocol)
    port = reactor.listenTCP(0, serverFactory, interface=self.interface)
    endpoint = self.endpoints.client(reactor, port.getHost())
    clientFactory = ClientFactory()
    clientFactory.protocol = Protocol
    connectDeferred = endpoint.connect(clientFactory)
    def connected(protocol):
        if (not ITLSTransport.providedBy(protocol.transport)):
            results.append('skip')
        else:
            results.append(self.assertRaises(ValueError, protocol.transport.startTLS, brokenFactory))
    def connectFailed(failure):
        results.append(failure)
    def whenRun():
        connectDeferred.addCallback(connected)
        connectDeferred.addErrback(connectFailed)
        connectDeferred.addBoth((lambda ign: reactor.stop()))
    needsRunningReactor(reactor, whenRun)
    self.runReactor(reactor)
    self.assertEqual(len(results), 1, ('more    than    one    callback    result:    %s' % (results,)))
    if isinstance(results[0], Failure):
        results[0].raiseException()
    if (results[0] == 'skip'):
        raise SkipTest('Reactor    does    not    support    ITLSTransport')
    self.assertEqual(BrokenContextFactory.message, str(results[0]))
