def test_getVersionStringWithReleaseCandidate(self): """ L{getVersionString} includes the release candidate, if any. """ self.assertEqual( getVersionString(Version("whatever", 8, 0, 0, release_candidate=1)), "whatever 8.0.0rc1")
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_baseWithDevAndRC(self): """ The base version includes 'rcXdevX' for versions with dev releases and a release candidate. """ self.assertEqual( Version("foo", 1, 0, 0, release_candidate=2, dev=8).base(), "1.0.0rc2dev8")
def test_strWithDevAndReleaseCandidate(self): """ Calling C{str} on a version with a release candidate and dev release includes the release candidate and the dev release. """ self.assertEqual( str(Version("dummy", 1, 0, 0, release_candidate=1, dev=2)), "[dummy, version 1.0.0rc1dev2]")
def test_goodSVNEntriesTenPlus(self): """ Version should be able to parse an SVN format 10 entries file. """ version = Version("dummy", 1, 0, 0) self.assertEqual( version._parseSVNEntriesTenPlus(BytesIO(VERSION_10_ENTRIES)), b'22715')
def test_reprWithPrerelease(self): """ Calling C{repr} on a version with a prerelease returns a human-readable string representation of the version including the prerelease as a release candidate.. """ self.assertEqual(repr(Version("dummy", 1, 2, 3, prerelease=4)), "Version('dummy', 1, 2, 3, release_candidate=4)")
def test_devWithReleaseCandidate(self): """ Calling C{repr} on a version with a dev release returns a human-readable string representation of the version including the dev release. """ self.assertEqual(repr(Version("dummy", 1, 2, 3, dev=4)), "Version('dummy', 1, 2, 3, dev=4)")
def test_getDeprecationDocstring(self): """ L{_getDeprecationDocstring} returns a note about the deprecation to go into a docstring. """ version = Version("Twisted", 8, 0, 0) self.assertEqual("Deprecated in Twisted 8.0.0.", _getDeprecationDocstring(version, ""))
def test_notImplementedComparisons(self): """ Comparing a L{Version} to some other object type results in C{NotImplemented}. """ va = Version("dummy", 1, 0, 0) vb = ("dummy", 1, 0, 0) # a tuple is not a Version object self.assertEqual(va.__cmp__(vb), NotImplemented)
def test_versionMetadata(self): """ Deprecating a function adds version information to the decorated version of that function. """ version = Version("Twisted", 8, 0, 0) dummy = deprecated(version)(dummyCallable) self.assertEqual(version, dummy.deprecatedVersion)
def test_getVersionStringWithDevAndPost(self): """ L{getVersionString} includes the dev release and postrelease, if any. """ self.assertEqual( getVersionString(Version("whatever", 8, 0, 0, post=2, dev=1)), "whatever 8.0.0post2dev1")
def test_reprWithPost(self): """ Calling C{repr} on a version with a postrelease returns a human-readable string representation of the version including the postrelease. """ self.assertEqual(repr(Version("dummy", 1, 2, 3, post=4)), "Version('dummy', 1, 2, 3, post=4)")
def test_getVersionStringWithPost(self): """ L{getVersionString} includes the postrelease, if any. """ self.assertEqual( getVersionString(Version("whatever", 8, 0, 0, post=1)), "whatever 8.0.0.post1", )
class InvalidRPCServicesConfError(InvalidConfError): """ DEPRECATED. Invalid rpc services file """ deprecatedModuleAttribute( Version("Twisted", 16, 2, 0), "The RPC service configuration is no longer maintained.", __name__, "InvalidRPCServicesConfError")
def test_getVersionStringWithPrerelease(self): """ L{getVersionString} includes the prerelease as a release candidate, if any. """ self.assertEqual( getVersionString(Version("whatever", 8, 0, 0, prerelease=1)), "whatever 8.0.0.rc1", )
def test_strWithReleaseCandidate(self): """ Calling C{str} on a version with a release candidate includes the release candidate. """ self.assertEqual( str(Version("dummy", 1, 0, 0, release_candidate=1)), "[dummy, version 1.0.0.rc1]", )
def versionToUsefulObject(version): """ Change an AST C{Version()} to a real one. """ from incremental import Version package = version.args[0].s major = getattr(version.args[1], "n", getattr(version.args[1], "s", None)) return Version(package, major, *(x.n for x in version.args[2:] if x))
def test_getVersionStringWithDevAndRC(self): """ L{getVersionString} includes the dev release and release candidate, if any. """ self.assertEqual( getVersionString( Version("whatever", 8, 0, 0, release_candidate=2, dev=1)), "whatever 8.0.0rc2dev1")
def test_strWithDevAndPost(self): """ Calling C{str} on a version with a postrelease and dev release includes the postrelease and the dev release. """ self.assertEqual( str(Version("dummy", 1, 0, 0, post=1, dev=2)), "[dummy, version 1.0.0.post1.dev2]", )
def genVersion(*args, **kwargs): """ A convenience for generating _version.py data. @param args: Arguments to pass to L{Version}. @param kwargs: Keyword arguments to pass to L{Version}. """ return "from incremental import Version\n__version__={!r}".format( Version(*args, **kwargs))
def test_prereleaseDeprecated(self): """ Passing 'prerelease' to Version is deprecated. """ Version("whatever", 1, 0, 0, prerelease=1) warnings = self.flushWarnings([self.test_prereleaseDeprecated]) self.assertEqual(len(warnings), 1) self.assertEqual( warnings[0]['message'], ("Passing prerelease to incremental.Version was deprecated in " "Incremental 16.9.0. Please pass release_candidate instead."))
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_getDeprecationWarningString(self): """ L{getDeprecationWarningString} returns a string that tells us that a callable was deprecated at a certain released version of Twisted. """ version = Version('Twisted', 8, 0, 0) self.assertEqual( getDeprecationWarningString(self.test_getDeprecationWarningString, version), "%s.DeprecationWarningsTests.test_getDeprecationWarningString " "was deprecated in Twisted 8.0.0" % (__name__,))
def test_prereleaseAttributeDeprecated(self): """ Accessing 'prerelease' on a Version is deprecated. """ va = Version("whatever", 1, 0, 0, release_candidate=1) va.prerelease warnings = self.flushWarnings() self.assertEqual(len(warnings), 1) self.assertEqual( warnings[0]['message'], ("Accessing incremental.Version.prerelease was deprecated in " "Incremental 16.9.0. Use Version.release_candidate instead."))
def deferred(self): """ DEPRECATED. L{Deferred} fired when loop stops or fails. Use the L{Deferred} returned by L{LoopingCall.start}. """ warningString = _getDeprecationWarningString( "twisted.internet.task.LoopingCall.deferred", Version("Twisted", 16, 0, 0), replacement='the deferred returned by start()') warnings.warn(warningString, DeprecationWarning, stacklevel=2) return self._deferred
def test_getDeprecationWarningStringWithFormat(self): """ L{getDeprecationWarningString} returns a string that tells us that a callable was deprecated at a certain released version of Twisted, with a message containing additional information about the deprecation. """ version = Version('Twisted', 8, 0, 0) format = DEPRECATION_WARNING_FORMAT + ': This is a message' self.assertEqual( getDeprecationWarningString(self.test_getDeprecationWarningString, version, format), '%s.DeprecationWarningsTests.test_getDeprecationWarningString was ' 'deprecated in Twisted 8.0.0: This is a message' % (__name__,))
def test_git(self): gitDir = FilePath(self.mktemp()) gitDir.makedirs() gitDir.child("HEAD").setContent(b"ref: refs/heads/master\n") heads = gitDir.child("refs").child("heads") heads.makedirs() heads.child("master").setContent( b"a96d61d94949c0dc097d6e1c3515792e99a724d5\n") version = Version("foo", 1, 0, 0) self.assertEqual(version._parseGitDir(gitDir.path), "a96d61d94949c0dc097d6e1c3515792e99a724d5")
def test_deprecateEmitsWarning(self): """ Decorating a callable with L{deprecated} emits a warning. """ version = Version('Twisted', 8, 0, 0) dummy = deprecated(version)(dummyCallable) def addStackLevel(): dummy() with catch_warnings(record=True) as caught: simplefilter("always") addStackLevel() self.assertEqual(caught[0].category, DeprecationWarning) self.assertEqual(str(caught[0].message), getDeprecationWarningString(dummyCallable, version)) # rstrip in case .pyc/.pyo self.assertEqual(caught[0].filename.rstrip('co'), __file__.rstrip('co'))
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__))