Example #1
0
 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))
Example #3
0
 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")
Example #4
0
 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]")
Example #5
0
 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')
Example #6
0
 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)")
Example #7
0
 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)")
Example #8
0
 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, ""))
Example #9
0
 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)
Example #10
0
 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)
Example #11
0
 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")
Example #12
0
 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",
     )
Example #14
0
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]",
     )
Example #17
0
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))
Example #18
0
 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]",
     )
Example #20
0
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))
Example #21
0
 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."))
Example #22
0
 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))
Example #23
0
 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__,))
Example #24
0
 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."))
Example #25
0
    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
Example #26
0
 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__,))
Example #27
0
    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")
Example #28
0
 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'))
Example #29
0
 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),))
Example #30
0
 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__))