Example #1
0
 def test_goodSVNEntries_4(self):
     """
     Version should be able to parse an SVN format 4 entries file.
     """
     version = Version("dummy", 1, 0, 0)
     self.assertEquals(
         version._parseSVNEntries_4(StringIO(VERSION_4_ENTRIES)), '18211')
Example #2
0
 def test_goodSVNEntries_4(self):
     """
     Version should be able to parse an SVN format 4 entries file.
     """
     version = Version("dummy", 1, 0, 0)
     self.assertEquals(
         version._parseSVNEntries_4(StringIO(VERSION_4_ENTRIES)), '18211')
Example #3
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(StringIO(VERSION_10_ENTRIES)), '22715')
Example #4
0
    def test_wrappedModule(self):
        """
        Deprecating an attribute in a module replaces and wraps that module
        instance, in C{sys.modules}, with a
        L{twisted.python.deprecate._ModuleProxy} instance but only if it hasn't
        already been wrapped.
        """
        sys.modules[self._testModuleName] = mod = types.ModuleType('foo')
        self.addCleanup(sys.modules.pop, self._testModuleName)

        setattr(mod, 'first', 1)
        setattr(mod, 'second', 2)

        deprecate.deprecatedModuleAttribute(Version('Twisted', 8, 0,
                                                    0), 'message',
                                            self._testModuleName, 'first')

        proxy = sys.modules[self._testModuleName]
        self.assertNotEqual(proxy, mod)

        deprecate.deprecatedModuleAttribute(Version('Twisted', 8, 0,
                                                    0), 'message',
                                            self._testModuleName, 'second')

        self.assertIdentical(proxy, sys.modules[self._testModuleName])
Example #5
0
 def test_goodSVNEntries_9(self):
     """
     Version should be able to parse an SVN format 9 entries file.
     """
     version = Version("dummy", 1, 0, 0)
     self.assertEqual(
         version._parseSVNEntries_9(StringIO(VERSION_9_ENTRIES)), '22715')
Example #6
0
 def test_comparingPrereleasesWithReleases(self):
     """
     Prereleases are always less than versions without prereleases.
     """
     va = Version("whatever", 1, 0, 0, prerelease=1)
     vb = Version("whatever", 1, 0, 0)
     self.assertTrue(va < vb)
     self.assertFalse(va > vb)
     self.assertNotEquals(vb, va)
Example #7
0
 def test_comparingPrereleases(self):
     """
     The value specified as the prerelease is used in version comparisons.
     """
     va = Version("whatever", 1, 0, 0, prerelease=1)
     vb = Version("whatever", 1, 0, 0, prerelease=2)
     self.assertTrue(va < vb)
     self.assertFalse(va > vb)
     self.assertNotEqual(va, vb)
Example #8
0
 def test_str(self):
     """
     Calling C{str} on a version returns a human-readable string
     representation of the version.
     """
     self.assertEquals(str(Version("dummy", 1, 2, 3)),
                       "[dummy, version 1.2.3]")
Example #9
0
 def test_repr(self):
     """
     Calling C{repr} on a version returns a human-readable string
     representation of the version.
     """
     self.assertEquals(repr(Version("dummy", 1, 2, 3)),
                       "Version('dummy', 1, 2, 3)")
Example #10
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.
     """
     self.assertEquals(repr(Version("dummy", 1, 2, 3, prerelease=4)),
                       "Version('dummy', 1, 2, 3, prerelease=4)")
Example #11
0
class ThreadSafeList:
    """
    In Jython 2.1 lists aren't thread-safe, so this wraps it.  Newer versions
    of Jython are completely different than 2.1, so this class is deprecated
    to make way for future versions of Jython.
    """

    deprecatedModuleAttribute(
        Version("Twisted", 10, 1, 0),
        "This was an internal implementation detail of support for Jython 2.1,"
        " which is now obsolete.", __name__, "ThreadSafeList")

    def __init__(self):
        self.lock = threading.Lock()
        self.l = []

    def append(self, i):
        self.lock.acquire()
        try:
            self.l.append(i)
        finally:
            self.lock.release()

    def remove(self, i):
        self.lock.acquire()
        try:
            self.l.remove(i)
        finally:
            self.lock.release()

    def __len__(self):
        return len(self.l)
Example #12
0
 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)))
Example #13
0
 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")
Example #14
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 #15
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 #16
0
 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 #17
0
    def test_deprecatedUpdatesDocstring(self):
        """
        The docstring of the deprecated function is appended with information
        about the deprecation.
        """

        version = Version('Twisted', 8, 0, 0)
        dummy = deprecated(version)(dummyCallable)

        _appendToDocstring(dummyCallable, _getDeprecationDocstring(version))

        self.assertEqual(dummyCallable.__doc__, dummy.__doc__)
Example #18
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),
         "twisted.python.test.test_deprecate.TestDeprecationWarnings."
         "test_getDeprecationWarningString was deprecated in "
         "Twisted 8.0.0")
Example #19
0
    def test_versionComparison(self):
        """
        Versions can be compared for equality and order.
        """
        va = Version("dummy", 1, 0, 0)
        vb = Version("dummy", 0, 1, 0)
        self.failUnless(va > vb)
        self.failUnless(vb < va)
        self.failUnless(va >= vb)
        self.failUnless(vb <= va)
        self.failUnless(va != vb)
        self.failUnless(vb == Version("dummy", 0, 1, 0))
        self.failUnless(vb == vb)

        # BREAK IT DOWN@!!
        self.failIf(va < vb)
        self.failIf(vb > va)
        self.failIf(va <= vb)
        self.failIf(vb >= va)
        self.failIf(va == vb)
        self.failIf(vb != Version("dummy", 0, 1, 0))
        self.failIf(vb != vb)
Example #20
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()

        self.assertWarns(DeprecationWarning,
                         getDeprecationWarningString(dummyCallable, version),
                         __file__, addStackLevel)
Example #21
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 = deprecate.DEPRECATION_WARNING_FORMAT + ': This is a message'
     self.assertEquals(
         getDeprecationWarningString(self.test_getDeprecationWarningString,
                                     version, format),
         'twisted.python.test.test_deprecate.TestDeprecationWarnings.'
         'test_getDeprecationWarningString was deprecated in '
         'Twisted 8.0.0: This is a message')
Example #22
0
def changeAllProjectVersions(root, versionTemplate, today=None):
    """
    Change the version of all projects (including core and all subprojects).

    If the current version of a project is pre-release, then also change the
    versions in the current NEWS entries for that project.

    @type root: L{FilePath}
    @param root: The root of the Twisted source tree.
    @type versionTemplate: L{Version}
    @param versionTemplate: The version of all projects.  The name will be
        replaced for each respective project.
    @type today: C{str}
    @param today: A YYYY-MM-DD formatted string. If not provided, defaults to
        the current day, according to the system clock.
    """
    if not today:
        today = date.today().strftime('%Y-%m-%d')
    for project in findTwistedProjects(root):
        if project.directory.basename() == "twisted":
            packageName = "twisted"
        else:
            packageName = "twisted." + project.directory.basename()
        oldVersion = project.getVersion()
        newVersion = Version(packageName,
                             versionTemplate.major,
                             versionTemplate.minor,
                             versionTemplate.micro,
                             prerelease=versionTemplate.prerelease)

        if oldVersion.prerelease:
            builder = NewsBuilder()
            builder._changeNewsVersion(root.child("NEWS"),
                                       builder._getNewsName(project),
                                       oldVersion, newVersion, today)
            builder._changeNewsVersion(
                project.directory.child("topfiles").child("NEWS"),
                builder._getNewsName(project), oldVersion, newVersion, today)

        # The placement of the top-level README with respect to other files (eg
        # _version.py) is sufficiently different from the others that we just
        # have to handle it specially.
        if packageName == "twisted":
            _changeVersionInFile(oldVersion, newVersion,
                                 root.child('README').path)

        project.updateVersion(newVersion)
Example #23
0
def getNextVersion(version, now=None):
    """
    Calculate the version number for a new release of Twisted based on
    the previous version number.

    @param version: The previous version number.
    @param now: (optional) The current date.
    """
    # XXX: This has no way of incrementing the patch number. Currently, we
    # don't need it. See bug 2915. Jonathan Lange, 2007-11-20.
    if now is None:
        now = date.today()
    major = now.year - VERSION_OFFSET
    if major != version.major:
        minor = 0
    else:
        minor = version.minor + 1
    return Version(version.package, major, minor, 0)
Example #24
0
    def main(self, args):
        """
        Given a list of command-line arguments, change all the Twisted versions
        in the current directory.

        @type args: list of str
        @param args: List of command line arguments.  This should only
            contain the version number.
        """
        version_format = (
            "Version should be in a form kind of like '1.2.3[pre4]'")
        if len(args) != 1:
            sys.exit("Must specify exactly one argument to change-versions")
        version = args[0]
        try:
            major, minor, micro_and_pre = version.split(".")
        except ValueError:
            raise SystemExit(version_format)
        if "pre" in micro_and_pre:
            micro, pre = micro_and_pre.split("pre")
        else:
            micro = micro_and_pre
            pre = None
        try:
            major = int(major)
            minor = int(minor)
            micro = int(micro)
            if pre is not None:
                pre = int(pre)
        except ValueError:
            raise SystemExit(version_format)
        version_template = Version("Whatever",
                                   major,
                                   minor,
                                   micro,
                                   prerelease=pre)
        self.changeAllProjectVersions(FilePath("."), version_template)
Example #25
0
# Import reflect first, so that circular imports (between deprecate and
# reflect) don't cause headaches.
import reqs.twisted.python.reflect
from reqs.twisted.python.versions import Version
from reqs.twisted.python.deprecate import deprecatedModuleAttribute


# Known module-level attributes.
DEPRECATED_ATTRIBUTE = 42
ANOTHER_ATTRIBUTE = 'hello'


version = Version('Twisted', 8, 0, 0)
message = 'Oh noes!'


deprecatedModuleAttribute(
    version,
    message,
    __name__,
    'DEPRECATED_ATTRIBUTE')
Example #26
0
    m.update(pszRealm)
    m.update(":")
    m.update(pszPassword)
    HA1 = m.digest()
    if pszAlg == "md5-sess":
        m = md5()
        m.update(HA1)
        m.update(":")
        m.update(pszNonce)
        m.update(":")
        m.update(pszCNonce)
        HA1 = m.digest()
    return HA1.encode('hex')


DigestCalcHA1 = deprecated(Version("Twisted", 9, 0, 0))(DigestCalcHA1)


def DigestCalcResponse(
    HA1,
    pszNonce,
    pszNonceCount,
    pszCNonce,
    pszQop,
    pszMethod,
    pszDigestUri,
    pszHEntity,
):
    m = md5()
    m.update(pszMethod)
    m.update(":")
Example #27
0
    """
    Emitted when L{IReactorProcess.spawnProcess} is called in a way which may
    result in termination of the created child process not being reported.

    Deprecated in Twisted 10.0.
    """
    MESSAGE = ("spawnProcess called, but the SIGCHLD handler is not "
               "installed. This probably means you have not yet "
               "called reactor.run, or called "
               "reactor.run(installSignalHandler=0). You will probably "
               "never see this process finish, and it may become a "
               "zombie process.")


deprecate.deprecatedModuleAttribute(
    Version("Twisted", 10, 0,
            0), "There is no longer any potential for zombie process.",
    __name__, "PotentialZombieWarning")


class ProcessDone(ConnectionDone):
    """A process has ended without apparent errors"""
    def __init__(self, status):
        Exception.__init__(self, "process finished with exit code 0")
        self.exitCode = 0
        self.signal = None
        self.status = status


class ProcessTerminated(ConnectionLost):
    """A process has ended with a probable error condition"""
    def __init__(self, exitCode=None, signal=None, status=None):
Example #28
0
 def test_baseWithPrerelease(self):
     """
     The base version includes 'preX' for versions with prereleases.
     """
     self.assertEquals(
         Version("foo", 1, 0, 0, prerelease=8).base(), "1.0.0pre8")
Example #29
0
 def test_base(self):
     """
     The L{base} method returns a very simple representation of the version.
     """
     self.assertEquals(Version("foo", 1, 0, 0).base(), "1.0.0")
Example #30
0
 def testDontAllowBuggyComparisons(self):
     self.assertRaises(IncomparableVersions, cmp, Version("dummy", 1, 0, 0),
                       Version("dumym", 1, 0, 0))
Example #31
0
 def test_strWithPrerelease(self):
     """
     Calling C{str} on a version with a prerelease includes the prerelease.
     """
     self.assertEquals(str(Version("dummy", 1, 0, 0, prerelease=1)),
                       "[dummy, version 1.0.0pre1]")
Example #32
0
 def testShort(self):
     self.assertEquals(Version('dummy', 1, 2, 3).short(), '1.2.3')