Пример #1
0
class PortStringificationTests(unittest.TestCase):
    if interfaces.IReactorTCP(reactor, None) is not None:
        def testTCP(self):
            p = reactor.listenTCP(0, protocol.ServerFactory())
            portNo = p.getHost().port
            self.assertNotEqual(str(p).find(str(portNo)), -1,
                                "%d not found in %s" % (portNo, p))
            return p.stopListening()

    if interfaces.IReactorUDP(reactor, None) is not None:
        def testUDP(self):
            p = reactor.listenUDP(0, protocol.DatagramProtocol())
            portNo = p.getHost().port
            self.assertNotEqual(str(p).find(str(portNo)), -1,
                                "%d not found in %s" % (portNo, p))
            return p.stopListening()

    if interfaces.IReactorSSL(reactor, None) is not None and ssl:
        def testSSL(self, ssl=ssl):
            pem = util.sibpath(__file__, 'server.pem')
            p = reactor.listenSSL(0, protocol.ServerFactory(), ssl.DefaultOpenSSLContextFactory(pem, pem))
            portNo = p.getHost().port
            self.assertNotEqual(str(p).find(str(portNo)), -1,
                                "%d not found in %s" % (portNo, p))
            return p.stopListening()

        if _PY3:
            testSSL.skip = ("Re-enable once the Python 3 SSL port is done.")
Пример #2
0
class PortStringificationTests(TestCase):
    @skipIf(not interfaces.IReactorTCP(reactor, None), "IReactorTCP is needed")
    def testTCP(self):
        p = reactor.listenTCP(0, protocol.ServerFactory())
        portNo = p.getHost().port
        self.assertNotEqual(
            str(p).find(str(portNo)), -1, "%d not found in %s" % (portNo, p)
        )
        return p.stopListening()

    @skipIf(not interfaces.IReactorUDP(reactor, None), "IReactorUDP is needed")
    def testUDP(self):
        p = reactor.listenUDP(0, protocol.DatagramProtocol())
        portNo = p.getHost().port
        self.assertNotEqual(
            str(p).find(str(portNo)), -1, "%d not found in %s" % (portNo, p)
        )
        return p.stopListening()

    @skipIf(not interfaces.IReactorSSL(reactor, None), "IReactorSSL is needed")
    @skipIf(not ssl, "SSL support is missing")
    def testSSL(self, ssl=ssl):
        pem = util.sibpath(__file__, "server.pem")
        p = reactor.listenSSL(
            0, protocol.ServerFactory(), ssl.DefaultOpenSSLContextFactory(pem, pem)
        )
        portNo = p.getHost().port
        self.assertNotEqual(
            str(p).find(str(portNo)), -1, "%d not found in %s" % (portNo, p)
        )
        return p.stopListening()