if _PY3: test_reprWithClassicProtocol.skip = ( "Classic classes do not exist on Python 3.") def test_reprWithNewStyleProtocol(self): """ The two string representations of the L{IListeningPort} returned by L{IReactorUNIXDatagram.listenUNIXDatagram} contains the name of the new-style protocol class being used and the filename on which the port is listening or indicates that the port is not listening. """ class NewStyleProtocol(object): def makeConnection(self, transport): pass def doStop(self): pass # Sanity check self.assertIsInstance(NewStyleProtocol, type) return self._reprTest(NewStyleProtocol(), "twisted.test.test_unix.NewStyleProtocol") if not interfaces.IReactorUNIX(reactor, None): UnixSocketTests.skip = "This reactor does not support UNIX domain sockets" if not interfaces.IReactorUNIXDatagram(reactor, None): DatagramUnixSocketTests.skip = "This reactor does not support UNIX datagram sockets"
def stopProtocol(self): self.stopped = True def startProtocol(self): self.started = True self.deferredStarted.callback(None) def datagramReceived(self, data, addr): self.gotfrom = addr self.transport.write(b"hi back", addr) self.gotwhat = data self.deferredGotWhat.callback(None) @skipIf(not interfaces.IReactorUNIXDatagram(reactor, None), "This reactor does not support UNIX datagram sockets") class DatagramUnixSocketTests(unittest.TestCase): """ Test datagram UNIX sockets. """ def test_exchange(self): """ Test that a datagram can be sent to and received by a server and vice versa. """ clientaddr = self.mktemp() serveraddr = self.mktemp() sp = ServerProto() cp = ClientProto() s = reactor.listenUNIXDatagram(serveraddr, sp)