Ticket #4086: twisted4086.patch

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

Patch to deprecate "unsigned" flag, with test

  • twisted/scripts/test/test_tap2rpm.py

     
    55Tests for L{twisted.scripts.tap2rpm}.
    66"""
    77import os
     8import warnings
     9
    810from twisted.trial.unittest import TestCase, SkipTest
    911from twisted.python import procutils
     12from twisted.python import versions
    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            "The 'unsigned' flag is deprecated, as it's not currently used.",
     397            warnings[0]['message'])
     398        self.assertEqual(1, len(warnings))
  • twisted/scripts/tap2rpm.py

     
    77import tempfile
    88import tarfile
    99from StringIO import StringIO
     10import warnings
    1011
    1112from twisted.python import usage, log
    1213
     
    138139
    139140###############################
    140141class MyOptions(usage.Options):
    141     optFlags = [["unsigned", "u"], ['quiet', 'q']]
     142    optFlags = [['unsigned', 'u'], ['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        # Deprecated 'unsigned' flag
     181        msg = "The 'unsigned' flag is deprecated, as it's not currently used."
     182        warnings.warn(msg, category=DeprecationWarning, stacklevel=2)
    179183
    180184
    181185type_dict = {