Ticket #3910: t.w.p.irc-action-2.patch

File t.w.p.irc-action-2.patch, 3.7 KB (added by stefanor, 12 years ago)

Improve tests and test deprecation

  • twisted/words/test/test_irc.py

    class ClientTests(TestCase): 
    723723                username, hostname, servername, self.protocol.realname),
    724724            '']
    725725        self.assertEquals(self.transport.value().split('\r\n'), expected)
     726
     727
     728    def test_describe(self):
     729        """
     730        L{IRCClient.desrcibe} sends a CTCP ACTION message to the target
     731        specified.
     732        """
     733        target = 'foo'
     734        channel = '#bar'
     735        action = 'waves'
     736        self.protocol.describe(target, action)
     737        self.protocol.describe(channel, action)
     738        expected = [
     739            'PRIVMSG %s :\01ACTION %s\01' % (target, action),
     740            'PRIVMSG %s :\01ACTION %s\01' % (channel, action),
     741            '']
     742        self.assertEquals(self.transport.value().split('\r\n'), expected)
     743
     744
     745    def test_me(self):
     746        """
     747        L{IRCClient.me} sends a CTCP ACTION message to the target channel
     748        specified.
     749        If the target does not begin with a standard channel prefix,
     750        '#' is prepended.
     751        """
     752        target = 'foo'
     753        channel = '#bar'
     754        action = 'waves'
     755        self.protocol.me(target, action)
     756        self.protocol.me(channel, action)
     757        expected = [
     758            'PRIVMSG %s :\01ACTION %s\01' % ('#' + target, action),
     759            'PRIVMSG %s :\01ACTION %s\01' % (channel, action),
     760            '']
     761        self.assertEquals(self.transport.value().split('\r\n'), expected)
     762        warnings = self.flushWarnings(
     763            offendingFunctions=[self.test_me])
     764        self.assertEquals(
     765            warnings[0]['message'],
     766            "me() is deprecated since Twisted 9.0. Use IRCClient.describe().")
     767        self.assertEquals(warnings[0]['category'], DeprecationWarning)
     768        self.assertEquals(len(warnings), 2)
  • twisted/words/protocols/irc.py

    Test coverage needs to be better. 
    3030
    3131import errno, os, random, re, stat, struct, sys, time, types, traceback
    3232import string, socket
     33import warnings
    3334from os import path
    3435
    3536from twisted.internet import reactor, protocol
    class IRCClient(basic.LineReceiver): 
    10671068
    10681069    ### user input commands, client->client
    10691070
     1071    def describe(self, channel, action):
     1072        """
     1073        Strike a pose.
     1074
     1075        @type channel: C{str}
     1076        @param channel: The name of the channel to have an action on. If it
     1077            has no prefix, it is sent to the user of that name.
     1078        @type action: C{str}
     1079        @param action: The action to preform.
     1080        @since: 9.0
     1081        """
     1082        self.ctcpMakeQuery(channel, [('ACTION', action)])
     1083
     1084
    10701085    def me(self, channel, action):
    10711086        """
    10721087        Strike a pose.
    10731088
     1089        This function is deprecated since Twisted 9.0. Use describe().
     1090
    10741091        @type channel: C{str}
    10751092        @param channel: The name of the channel to have an action on. If it
    10761093            has no prefix, C{'#'} will to prepended to it.
    10771094        @type action: C{str}
    10781095        @param action: The action to preform.
    10791096        """
     1097        warnings.warn("me() is deprecated since Twisted 9.0. Use IRCClient.describe().",
     1098                DeprecationWarning, stacklevel=2)
     1099
    10801100        if channel[0] not in '&#!+': channel = '#' + channel
    1081         self.ctcpMakeQuery(channel, [('ACTION', action)])
     1101        self.describe(channel, action)
    10821102
     1103
    10831104    _pings = None
    10841105    _MAX_PINGRING = 12
    10851106