'Helper method to test TCP server addresses on either IPv4 or IPv6.'

def _testServerAddress(self, interface, addressFamily, adressClass):

    def connected(protocols):
        (client, server, port) = protocols
        try:
            self.assertEqual(('<AccumulatingProtocol    #%s    on    %s>' % (server.transport.sessionno, port.getHost().port)), str(server.transport))
            self.assertEqual(('AccumulatingProtocol,%s,%s' % (server.transport.sessionno, interface)), server.transport.logstr)
            [peerAddress] = server.factory.peerAddresses
            self.assertIsInstance(peerAddress, adressClass)
            self.assertEqual('TCP', peerAddress.type)
            self.assertEqual(interface, peerAddress.host)
        finally:
            server.transport.loseConnection()
    reactor = self.buildReactor()
    d = self.getConnectedClientAndServer(reactor, interface, addressFamily)
    d.addCallback(connected)
    d.addErrback(log.err)
    self.runReactor(reactor)
