def test_deprecatedPreservesName(self): """ The decorated function has the same name as the original. """ version = Version("Twisted", 8, 0, 0) dummy = deprecated(version)(dummyCallable) self.assertEqual(dummyCallable.__name__, dummy.__name__) self.assertEqual(fullyQualifiedName(dummyCallable), fullyQualifiedName(dummy))
def test_deprecatedPreservesName(self): """ The decorated function has the same name as the original. """ version = Version('Twisted', 8, 0, 0) dummy = deprecated(version)(dummyCallable) self.assertEqual(dummyCallable.__name__, dummy.__name__) self.assertEqual(fullyQualifiedName(dummyCallable), fullyQualifiedName(dummy))
def buildReactor(self): """ Create and return a reactor using C{self.reactorFactory}. """ try: from twisted.internet.cfreactor import CFReactor from twisted.internet import reactor as globalReactor except ImportError: pass else: if (isinstance(globalReactor, CFReactor) and self.reactorFactory is CFReactor): raise SkipTest( "CFReactor uses APIs which manipulate global state, " "so it's not safe to run its own reactor-builder tests " "under itself") try: reactor = self.reactorFactory() except: # Unfortunately, not all errors which result in a reactor # being unusable are detectable without actually # instantiating the reactor. So we catch some more here # and skip the test if necessary. We also log it to aid # with debugging, but flush the logged error so the test # doesn't fail. log.err(None, "Failed to install reactor") self.flushLoggedErrors() raise SkipTest(Failure().getErrorMessage()) else: if self.requiredInterfaces is not None: missing = [ required for required in self.requiredInterfaces if not required.providedBy(reactor) ] if missing: self.unbuildReactor(reactor) raise SkipTest( "%s does not provide %s" % (fullyQualifiedName(reactor.__class__), ",".join( [fullyQualifiedName(x) for x in missing]))) self.addCleanup(self.unbuildReactor, reactor) return reactor
def _getDeprecationSuppression(f): """ Returns a tuple of arguments needed to suppress deprecation warnings from a specified function. @param f: function to suppress dperecation warnings for @type f: L{callable} @return: tuple to add to C{suppress} attribute """ return SUPPRESS(category=DeprecationWarning, message='%s was deprecated' % (fullyQualifiedName(f), ))
def buildReactor(self): """ Create and return a reactor using C{self.reactorFactory}. """ try: from twisted.internet.cfreactor import CFReactor from twisted.internet import reactor as globalReactor except ImportError: pass else: if (isinstance(globalReactor, CFReactor) and self.reactorFactory is CFReactor): raise SkipTest( "CFReactor uses APIs which manipulate global state, " "so it's not safe to run its own reactor-builder tests " "under itself") try: reactor = self.reactorFactory() except: # Unfortunately, not all errors which result in a reactor # being unusable are detectable without actually # instantiating the reactor. So we catch some more here # and skip the test if necessary. We also log it to aid # with debugging, but flush the logged error so the test # doesn't fail. log.err(None, "Failed to install reactor") self.flushLoggedErrors() raise SkipTest(Failure().getErrorMessage()) else: if self.requiredInterfaces is not None: missing = [ required for required in self.requiredInterfaces if not required.providedBy(reactor)] if missing: self.unbuildReactor(reactor) raise SkipTest("%s does not provide %s" % ( fullyQualifiedName(reactor.__class__), ",".join([fullyQualifiedName(x) for x in missing]))) self.addCleanup(self.unbuildReactor, reactor) return reactor
def _getDeprecationSuppression(f): """ Returns a tuple of arguments needed to suppress deprecation warnings from a specified function. @param f: function to suppress dperecation warnings for @type f: L{callable} @return: tuple to add to C{suppress} attribute """ return SUPPRESS( category=DeprecationWarning, message='%s was deprecated' % (fullyQualifiedName(f),))
def test_getDeprecationWarningStringReplacement(self): """ L{getDeprecationWarningString} takes an additional replacement parameter that can be used to add information to the deprecation. If the replacement parameter is a string, it will be interpolated directly into the result. """ version = Version('Twisted', 8, 0, 0) warningString = getDeprecationWarningString( self.test_getDeprecationWarningString, version, replacement="something.foobar") self.assertEqual( warningString, "%s was deprecated in Twisted 8.0.0; please use something.foobar " "instead" % ( fullyQualifiedName(self.test_getDeprecationWarningString),))
def test_getDeprecationWarningStringReplacementWithCallable(self): """ L{getDeprecationWarningString} takes an additional replacement parameter that can be used to add information to the deprecation. If the replacement parameter is a callable, its fully qualified name will be interpolated into the result. """ version = Version('Twisted', 8, 0, 0) warningString = getDeprecationWarningString( self.test_getDeprecationWarningString, version, replacement=dummyReplacementMethod) self.assertEqual( warningString, "%s was deprecated in Twisted 8.0.0; please use " "%s.dummyReplacementMethod instead" % (fullyQualifiedName( self.test_getDeprecationWarningString), __name__))
def test_getDeprecationWarningStringReplacementWithCallable(self): """ L{getDeprecationWarningString} takes an additional replacement parameter that can be used to add information to the deprecation. If the replacement parameter is a callable, its fully qualified name will be interpolated into the result. """ version = Version('Twisted', 8, 0, 0) warningString = getDeprecationWarningString( self.test_getDeprecationWarningString, version, replacement=dummyReplacementMethod) self.assertEqual( warningString, "%s was deprecated in Twisted 8.0.0; please use " "%s.dummyReplacementMethod instead" % ( fullyQualifiedName(self.test_getDeprecationWarningString), __name__))
def _checkFullyQualifiedName(self, obj, expected): """ Helper to check that fully qualified name of C{obj} results to C{expected}. """ self.assertEqual(fullyQualifiedName(obj), expected)