Ticket #4086: twisted4086.2.patch

File twisted4086.2.patch, 2.8 KB (added by necaris, 5 years ago)

Patch to deprecate "unsigned" flag, with test and news file

  • twisted/topfiles/4086.removal

     
     1The 'unsigned' flag to twisted.scripts.tap2rpm.MyOptions is now deprecated.
  • twisted/scripts/test/test_tap2rpm.py

     
    55Tests for L{twisted.scripts.tap2rpm}.
    66"""
    77import os
     8
    89from twisted.trial.unittest import TestCase, SkipTest
    910from twisted.python import procutils
     11from twisted.python import versions
     12from twisted.python import deprecate
    1013from twisted.python.failure import Failure
    1114from twisted.internet import utils
    1215from twisted.scripts import tap2rpm
     
    378381
    379382        # Try and make an RPM from that tapfile.
    380383        _makeRPMs(tapfile=tapfile)
     384
     385
     386    def test_unsignedFlagDeprecationWarning(self):
     387        """
     388        The 'unsigned' flag in tap2rpm should be deprecated, and its use
     389        should raise a warning as such.
     390        """
     391        config = tap2rpm.MyOptions()
     392        config.parseOptions(['--unsigned'])
     393        warnings = self.flushWarnings()
     394        self.assertEqual(DeprecationWarning, warnings[0]['category'])
     395        self.assertEqual(
     396            deprecate.getDeprecationWarningString(
     397                config.opt_unsigned, versions.Version("Twisted", 12, 2, 0)),
     398            warnings[0]['message'])
     399        self.assertEqual(1, len(warnings))
  • twisted/scripts/tap2rpm.py

     
    77import tempfile
    88import tarfile
    99from StringIO import StringIO
     10import warnings
    1011
    11 from twisted.python import usage, log
     12from twisted.python import usage, log, versions, deprecate
    1213
    1314
    1415#################################
     
    138139
    139140###############################
    140141class MyOptions(usage.Options):
    141     optFlags = [["unsigned", "u"], ['quiet', 'q']]
     142    optFlags = [['quiet', 'q']]
    142143    optParameters = [
    143144                     ["tapfile", "t", "twistd.tap"],
    144145                     ["maintainer", "m", "tap2rpm"],
     
    176177        self['twistd_option'] = type_dict[self['type']]
    177178        self['release-name'] = '%s-%s' % (self['rpmfile'], self['set-version'])
    178179
     180    def opt_unsigned(self):
     181        """
     182        Handle the 'unsigned' command-line flag, which is now deprecated in
     183        any case.
     184        """
     185        msg = deprecate.getDeprecationWarningString(
     186            self.opt_unsigned, versions.Version("Twisted", 12, 2, 0))
     187        warnings.warn(msg, category=DeprecationWarning, stacklevel=2)
    179188
    180189
    181190type_dict = {