def test_failsWithIncorrectDeprecation(self): """ callDeprecated raises a test failure if the callable was deprecated at a different version to the one expected. """ differentVersion = Version("Foo", 1, 2, 3) exception = self.assertRaises(self.failureException, self.callDeprecated, differentVersion, oldMethod, "foo") self.assertIn(getVersionString(self.version), str(exception)) self.assertIn(getVersionString(differentVersion), str(exception))
def test_failsWithIncorrectDeprecation(self): """ callDeprecated raises a test failure if the callable was deprecated at a different version to the one expected. """ differentVersion = Version('Foo', 1, 2, 3) exception = self.assertRaises(self.failureException, self.callDeprecated, differentVersion, oldMethod, 'foo') self.assertIn(getVersionString(self.version), str(exception)) self.assertIn(getVersionString(differentVersion), str(exception))
def test_getVersionString(self): """ L{getVersionString} returns a string with the package name and the short version number. """ self.assertEqual( 'Twisted 8.0.0', getVersionString(Version('Twisted', 8, 0, 0)))
def _getDeprecationWarningString(fqpn, version, format=None, replacement=None): """ Return a string indicating that the Python name was deprecated in the given version. @param fqpn: Fully qualified Python name of the thing being deprecated @type fqpn: C{str} @param version: Version that C{fqpn} was deprecated in. @type version: L{twisted.python.versions.Version} @param format: A user-provided format to interpolate warning values into, or L{DEPRECATION_WARNING_FORMAT <twisted.python.deprecate.DEPRECATION_WARNING_FORMAT>} if C{None} is given. @type format: C{str} @param replacement: what should be used in place of C{fqpn}. Either pass in a string, which will be inserted into the warning message, or a callable, which will be expanded to its full import path. @type replacement: C{str} or callable @return: A textual description of the deprecation @rtype: C{str} """ if format is None: format = DEPRECATION_WARNING_FORMAT warningString = format % { 'fqpn': fqpn, 'version': getVersionString(version)} if replacement: warningString = "%s; %s" % ( warningString, _getReplacementString(replacement)) return warningString
def test_getVersionString(self): """ L{getVersionString} returns a string with the package name and the short version number. """ self.assertEqual( 'Twisted 8.0.0', getVersionString(Version('Twisted', 8, 0, 0)))
def _getDeprecationWarningString(fqpn, version, format=None, replacement=None): """ Return a string indicating that the Python name was deprecated in the given version. @param fqpn: Fully qualified Python name of the thing being deprecated @type fqpn: C{str} @param version: Version that C{fqpn} was deprecated in. @type version: L{twisted.python.versions.Version} @param format: A user-provided format to interpolate warning values into, or L{DEPRECATION_WARNING_FORMAT <twisted.python.deprecate.DEPRECATION_WARNING_FORMAT>} if L{None} is given. @type format: C{str} @param replacement: what should be used in place of C{fqpn}. Either pass in a string, which will be inserted into the warning message, or a callable, which will be expanded to its full import path. @type replacement: C{str} or callable @return: A textual description of the deprecation @rtype: C{str} """ if format is None: format = DEPRECATION_WARNING_FORMAT warningString = format % { 'fqpn': fqpn, 'version': getVersionString(version)} if replacement: warningString = "%s; %s" % ( warningString, _getReplacementString(replacement)) return warningString
def test_getVersionStringWithPrerelease(self): """ L{getVersionString} includes the prerelease, if any. """ self.assertEqual( getVersionString(Version("whatever", 8, 0, 0, prerelease=1)), "whatever 8.0.0pre1")
def test_getVersionStringWithPrerelease(self): """ L{getVersionString} includes the prerelease, if any. """ self.assertEqual( getVersionString(Version("whatever", 8, 0, 0, prerelease=1)), "whatever 8.0.0rc1")
def test_callDeprecationWithWrongMessage(self): """ If the message passed to L{callDeprecated} doesn't match, L{callDeprecated} raises a test failure. """ exception = self.assertRaises( self.failureException, self.callDeprecated, (self.version, "something.wrong"), oldMethodReplaced, 1 ) self.assertIn(getVersionString(self.version), str(exception)) self.assertIn("please use newMethod instead", str(exception))
def test_getVersionStringWithRevision(self): """ L{getVersionString} includes the discovered revision number. """ self.svnEntries.child(b"format").setContent(b"9\n") self.svnEntries.child(b"entries").setContent(VERSION_10_ENTRIES) version = getVersionString(self.getVersion()) self.assertEqual("twisted_python_versions_package 1.0.0+r22715", version) self.assertTrue(isinstance(version, type("")))
def test_callDeprecationWithWrongMessage(self): """ If the message passed to L{callDeprecated} doesn't match, L{callDeprecated} raises a test failure. """ exception = self.assertRaises(self.failureException, self.callDeprecated, (self.version, "something.wrong"), oldMethodReplaced, 1) self.assertIn(getVersionString(self.version), str(exception)) self.assertIn("please use newMethod instead", str(exception))
def test_getVersionStringWithRevision(self): """ L{getVersionString} includes the discovered revision number. """ self.svnEntries.child(b"format").setContent(b"9\n") self.svnEntries.child(b"entries").setContent(VERSION_10_ENTRIES) version = getVersionString(self.getVersion()) self.assertEqual( "twisted_python_versions_package 1.0.0+r22715", version) self.assertTrue(isinstance(version, type("")))
def getDeprecationWarningString(callableThing, version): """ Return a string indicating that the callable was deprecated in the given version. @param callableThing: A callable to be deprecated. @param version: The L{twisted.python.versions.Version} that the callable was deprecated in. @return: A string describing the deprecation. """ return "%s was deprecated in %s" % ( fullyQualifiedName(callableThing), getVersionString(version))
def getDeprecationWarningString(callableThing, version): """ Return a string indicating that the callable was deprecated in the given version. @param callableThing: A callable to be deprecated. @param version: The L{twisted.python.versions.Version} that the callable was deprecated in. @return: A string describing the deprecation. """ return "%s was deprecated in %s" % (qual(callableThing), getVersionString(version))
def _getDeprecationDocstring(version, replacement=None): """ Generate an addition to a deprecated object's docstring that explains its deprecation. @param version: the version it was deprecated. @type version: L{Version} @param replacement: The replacement, if specified. @type replacement: C{str} or callable @return: a string like "Deprecated in Twisted 27.2.0; please use twisted.timestream.tachyon.flux instead." """ doc = "Deprecated in %s" % (getVersionString(version),) if replacement: doc = "%s; %s" % (doc, _getReplacementString(replacement)) return doc + "."
def _getDeprecationDocstring(version, replacement=None): """ Generate an addition to a deprecated object's docstring that explains its deprecation. @param version: the version it was deprecated. @type version: L{Version} @param replacement: The replacement, if specified. @type replacement: C{str} or callable @return: a string like "Deprecated in Twisted 27.2.0; please use twisted.timestream.tachyon.flux instead." """ doc = "Deprecated in %s" % (getVersionString(version),) if replacement: doc = "%s; %s" % (doc, _getReplacementString(replacement)) return doc + "."
def _getDeprecationWarningString(fqpn, version, format=None): """ Return a string indicating that the Python name was deprecated in the given version. @type fqpn: C{str} @param fqpn: Fully qualified Python name of the thing being deprecated @type version: L{twisted.python.versions.Version} @param version: Version that C{fqpn} was deprecated in @type format: C{str} @param format: A user-provided format to interpolate warning values into, or L{DEPRECATION_WARNING_FORMAT} if C{None} is given @rtype: C{str} @return: A textual description of the deprecation """ if format is None: format = DEPRECATION_WARNING_FORMAT return format % {'fqpn': fqpn, 'version': getVersionString(version)}
def _getDeprecationWarningString(fqpn, version, format=None): """ Return a string indicating that the Python name was deprecated in the given version. @type fqpn: C{str} @param fqpn: Fully qualified Python name of the thing being deprecated @type version: L{twisted.python.versions.Version} @param version: Version that C{fqpn} was deprecated in @type format: C{str} @param format: A user-provided format to interpolate warning values into, or L{DEPRECATION_WARNING_FORMAT} if C{None} is given @rtype: C{str} @return: A textual description of the deprecation """ if format is None: format = DEPRECATION_WARNING_FORMAT return format % { 'fqpn': fqpn, 'version': getVersionString(version)}
# -*- test-case-name: twisted.test.test_enterprise -*- # Copyright (c) 2001-2008 Twisted Matrix Laboratories. # See LICENSE for details. import warnings, types from twisted.python.versions import Version, getVersionString from twisted.python.deprecate import deprecated from twisted.enterprise.adbapi import _safe # Common deprecation decorator used for all deprecations. _deprecatedVersion = Version("Twisted", 8, 0, 0) _releasedDeprecation = deprecated(_deprecatedVersion) warnings.warn("twisted.enterprise.util is deprecated since %s." % (getVersionString(_deprecatedVersion), ), category=DeprecationWarning) NOQUOTE = 1 USEQUOTE = 2 dbTypeMap = { "bigint": NOQUOTE, "bool": USEQUOTE, "boolean": USEQUOTE, "bytea": USEQUOTE, "date": USEQUOTE, "int2": NOQUOTE, "int4": NOQUOTE, "int8": NOQUOTE, "int": NOQUOTE,
def _getDeprecationDocstring(version): return "Deprecated in %s." % getVersionString(version)
def opt_version(self): """ Display version information. """ print versions.getVersionString(version) sys.exit(0)
def _getDeprecationDocstring(version): return "Deprecated in %s." % getVersionString(version)
# See LICENSE for details. import warnings, types from twisted.python.versions import Version, getVersionString from twisted.python.deprecate import deprecated from twisted.enterprise.adbapi import _safe # Common deprecation decorator used for all deprecations. _deprecatedVersion = Version("Twisted", 8, 0, 0) _releasedDeprecation = deprecated(_deprecatedVersion) warnings.warn( "twisted.enterprise.util is deprecated since %s." % ( getVersionString(_deprecatedVersion),), category=DeprecationWarning) NOQUOTE = 1 USEQUOTE = 2 dbTypeMap = { "bigint": NOQUOTE, "bool": USEQUOTE, "boolean": USEQUOTE, "bytea": USEQUOTE, "date": USEQUOTE, "int2": NOQUOTE, "int4": NOQUOTE, "int8": NOQUOTE, "int": NOQUOTE,