Ticket #4817: 4817-2.patch

File 4817-2.patch, 9.0 KB (added by Adam, 11 years ago)
  • twisted/test/test_udp.py

     
    11# -*- test-case-name: twisted.test.test_udp -*-
    2 # Copyright (c) 2001-2010 Twisted Matrix Laboratories.
     2# Copyright (c) 2001-2011 Twisted Matrix Laboratories.
    33# See LICENSE for details.
    44
    55"""
     
    113113
    114114class UDPTestCase(unittest.TestCase):
    115115
    116     def testOldAddress(self):
     116    def test_oldAddress(self):
     117        """
     118        Assert that the L{DatagramProtocol} is correctly connected to a UDP port
     119        """
    117120        server = Server()
    118121        d = server.startedDeferred = defer.Deferred()
    119122        p = reactor.listenUDP(0, server, interface="127.0.0.1")
     
    122125            self.assertEquals(addr.type, 'UDP')
    123126            return p.stopListening()
    124127        return d.addCallback(cbStarted)
    125     testOldAddress.suppress = [
    126         util.suppress(message='IPv4Address.__getitem__',
    127                       category=DeprecationWarning)]
    128128
    129 
    130     def testStartStop(self):
     129    def test_startStop(self):
     130        """
     131        Ensure that the protocol's L{startProtocol} and L{stopProtocol} methods
     132        are called correctly
     133        """
    131134        server = Server()
    132135        d = server.startedDeferred = defer.Deferred()
    133136        port1 = reactor.listenUDP(0, server, interface="127.0.0.1")
     
    139142            self.assertEquals(server.stopped, 1)
    140143        return d.addCallback(cbStarted).addCallback(cbStopped)
    141144
    142     def testRebind(self):
    143         # Ensure binding the same DatagramProtocol repeatedly invokes all
    144         # the right callbacks.
     145    def test_rebind(self):
     146        """
     147        Ensure binding the same L{DatagramProtocol} repeatedly invokes all the
     148        right callbacks
     149        """
    145150        server = Server()
    146151        d = server.startedDeferred = defer.Deferred()
    147152        p = reactor.listenUDP(0, server, interface="127.0.0.1")
     
    157162        return d.addCallback(cbStarted, p)
    158163
    159164
    160     def testBindError(self):
     165    def test_bindError(self):
     166        """
     167        Assert that a L{CannotListenError} exception is raised when attempting
     168        to bind a second protocol instance to an already bound port
     169        """
    161170        server = Server()
    162171        d = server.startedDeferred = defer.Deferred()
    163172        port = reactor.listenUDP(0, server, interface='127.0.0.1')
    164173
    165174        def cbStarted(ignored):
    166175            self.assertEquals(port.getHost(), server.transport.getHost())
    167 
    168176            server2 = Server()
    169177            self.assertRaises(
    170178                error.CannotListenError,
     
    177185        d.addCallback(cbFinished)
    178186        return d
    179187
    180     def testSendPackets(self):
     188    def test_sendPackets(self):
     189        """
     190        Sets up a client and server, sending data from former to latter, and
     191        ensures the correct data is received
     192        """
    181193        server = Server()
    182194        serverStarted = server.startedDeferred = defer.Deferred()
    183195        port1 = reactor.listenUDP(0, server, interface="127.0.0.1")
     
    247259        return d
    248260
    249261
    250     def testConnectionRefused(self):
    251         # assume no one listening on port 80 UDP
     262    def test_connectionRefused(self):
     263        """
     264        Ensures that a L{connectionRefusedError} exception is raised when a
     265        connection attempt is actively refused by the other end
     266        Note: This test assumes no one is listening on port 80 UDP
     267        """
    252268        client = GoodClient()
    253269        clientStarted = client.startedDeferred = defer.Deferred()
    254270        port = reactor.listenUDP(0, client, interface="127.0.0.1")
     
    284300        d.addCallback(cbFinished)
    285301        return d
    286302
    287     def testBadConnect(self):
     303    def test_badConnect(self):
     304        """
     305        Ensure that:
     306        A call to the transport's connect method fails with a
     307        L{ValueError} when 'localhost' is passed as a host value.
     308        A call to a transport's connect method fails with a L{RuntimeError}
     309        when a successful call to the method has already been made with the
     310        same parameters.
     311        """
    288312        client = GoodClient()
    289313        port = reactor.listenUDP(0, client, interface="127.0.0.1")
    290314        self.assertRaises(ValueError, client.transport.connect,
     
    296320
    297321
    298322
    299     def testDatagramReceivedError(self):
     323    def test_datagramReceivedError(self):
    300324        """
    301325        Test that when datagramReceived raises an exception it is logged but
    302326        the port is not disconnected.
     
    395419        return finalDeferred
    396420
    397421
    398     def testPortRepr(self):
     422    def test_portRepr(self):
     423        """
     424        Ensure the correct port number can be found in the string returned from
     425        calling repr() on L{twisted.internet.udp.Port}
     426        """
    399427        client = GoodClient()
    400428        p = reactor.listenUDP(0, client)
    401429        portNo = str(p.getHost().port)
  • twisted/topfiles/4817.bugfix

     
     1IPv4Address and UNIXAddress object comparison operators fixed
  • twisted/topfiles/4817.removal

     
     1__getitem__ __getslice__ and __eq__ (tuple comparison, indexing) removed from twisted.internet.IPv4Address and twisted.internet.UNIXAddress classes
  • twisted/internet/address.py

     
    1 # Copyright (c) 2001-2010 Twisted Matrix Laboratories.
     1# Copyright (c) 2001-2011 Twisted Matrix Laboratories.
    22# See LICENSE for details.
    33
    44
     
    3939        self.port = port
    4040        self._bwHack = _bwHack
    4141
    42     def __getitem__(self, index):
    43         warnings.warn("IPv4Address.__getitem__ is deprecated.  Use attributes instead.",
    44                       category=DeprecationWarning, stacklevel=2)
    45         return (self._bwHack or self.type, self.host, self.port).__getitem__(index)
    46 
    47     def __getslice__(self, start, stop):
    48         warnings.warn("IPv4Address.__getitem__ is deprecated.  Use attributes instead.",
    49                       category=DeprecationWarning, stacklevel=2)
    50         return (self._bwHack or self.type, self.host, self.port)[start:stop]
    51 
    5242    def __repr__(self):
    5343        return 'IPv4Address(%s, %r, %d)' % (self.type, self.host, self.port)
    5444
     
    7060        self.name = name
    7161        self._bwHack = _bwHack
    7262
    73     def __getitem__(self, index):
    74         warnings.warn("UNIXAddress.__getitem__ is deprecated.  Use attributes instead.",
    75                       category=DeprecationWarning, stacklevel=2)
    76         return (self._bwHack, self.name).__getitem__(index)
     63    def __eq__(self, other):
     64        """
     65        overriding L{util.FancyEqMixin} to ensure the os level samefile check
     66        is done if the name attributes do not match.
     67        """
     68        res = super(UNIXAddress, self).__eq__(other)
     69        if res == False:
     70            try:
     71                return os.path.samefile(self.name, other.name)
     72            except OSError:
     73                pass
     74        return res
    7775
    78     def __getslice__(self, start, stop):
    79         warnings.warn("UNIXAddress.__getitem__ is deprecated.  Use attributes instead.",
    80                       category=DeprecationWarning, stacklevel=2)
    81         return (self._bwHack, self.name)[start:stop]
    82 
    8376    def __repr__(self):
    8477        return 'UNIXAddress(%r)' % (self.name,)
    8578
  • twisted/internet/test/test_address.py

     
    1 # Copyright (c) 2001-2010 Twisted Matrix Laboratories.
     1# Copyright (c) 2001-2011 Twisted Matrix Laboratories.
    22# See LICENSE for details.
    33
    44import re
     
    1111        """
    1212        Test that two different address instances, sharing the same
    1313        properties are considered equal, testing both __eq__ and __ne__ methods
     14        note: When applied via UNIXAddress class, this uses the same filename
     15        for both objects being compared
    1416        """
    15         self.assertEquals(self.buildAddress(), self.buildAddress())
     17        self.assertTrue(self.buildAddress() == self.buildAddress())
    1618        self.assertFalse(self.buildAddress() != self.buildAddress())
    1719
    1820
     
    8890
    8991    def buildAddress(self):
    9092        return UNIXAddress(self._socketAddress)
     93
     94    def test_differentNamesComparison(self):
     95        """
     96        Check that comparison operators work correctly on UNIXAddress objects
     97        when a different name is passed in
     98        """
     99        self.assertFalse(UNIXAddress(self.mktemp()) ==
     100                UNIXAddress(self.mktemp()))
     101        self.assertTrue(UNIXAddress(self.mktemp()) !=
     102                UNIXAddress(self.mktemp()))