Skip to content

Commit

Permalink
Revert "twisted#12254 Use Incremental 24.7.0" (twisted#12266)
Browse files Browse the repository at this point in the history
  • Loading branch information
glyph authored Jul 27, 2024
2 parents f6d54d6 + e678e32 commit 578c7d0
Show file tree
Hide file tree
Showing 4 changed files with 167 additions and 4 deletions.
8 changes: 5 additions & 3 deletions pyproject.toml
Original file line number Diff line number Diff line change
Expand Up @@ -2,7 +2,7 @@
requires = [
"hatchling >= 1.10.0",
"hatch-fancy-pypi-readme >= 22.5.0",
"incremental >= 24.7.0",
"incremental >= 22.10.0",
]
build-backend = "hatchling.build"

Expand Down Expand Up @@ -33,7 +33,7 @@ classifiers = [
dependencies = [
"zope.interface >= 5",
"constantly >= 15.1",
"incremental >= 24.7.0",
"incremental >= 22.10.0",
"Automat >= 0.8.0",
"hyperlink >= 17.1.1",
"attrs >= 21.3.0",
Expand Down Expand Up @@ -158,7 +158,9 @@ Twitter = "https://twitter.com/twistedmatrix"
allow-ambiguous-features = true

[tool.hatch.version]
source = "incremental"
source = "code"
path = "src/twisted/__init__.py"
search-paths = ["src"]

[tool.hatch.metadata.hooks.fancy-pypi-readme]
content-type = "text/x-rst"
Expand Down
Empty file.
161 changes: 161 additions & 0 deletions src/twisted/python/test/test_versions.py
Original file line number Diff line number Diff line change
@@ -0,0 +1,161 @@
# Copyright (c) Twisted Matrix Laboratories.
# See LICENSE for details.

"""
Tests for L{twisted.python.versions}.
"""


import operator

from incremental import _inf

from twisted.python.versions import IncomparableVersions, Version, getVersionString
from twisted.trial.unittest import SynchronousTestCase as TestCase


class VersionsTests(TestCase):
def test_versionComparison(self) -> None:
"""
Versions can be compared for equality and order.
"""
va = Version("dummy", 1, 0, 0)
vb = Version("dummy", 0, 1, 0)
self.assertTrue(va > vb)
self.assertTrue(vb < va)
self.assertTrue(va >= vb)
self.assertTrue(vb <= va)
self.assertTrue(va != vb)
self.assertTrue(vb == Version("dummy", 0, 1, 0))
self.assertTrue(vb == vb)

def test_versionComparisonCaseInsensitive(self) -> None:
"""
Version packages are compared case insensitively.
"""
va = Version("twisted", 1, 0, 0)
vb = Version("Twisted", 0, 1, 0)
self.assertTrue(va > vb)
self.assertTrue(vb < va)
self.assertTrue(va >= vb)
self.assertTrue(vb <= va)
self.assertTrue(va != vb)
self.assertTrue(vb == Version("twisted", 0, 1, 0))
self.assertTrue(vb == Version("TWISted", 0, 1, 0))
self.assertTrue(vb == vb)

def test_comparingPrereleasesWithReleases(self) -> None:
"""
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.assertNotEqual(vb, va)

def test_comparingPrereleases(self) -> None:
"""
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.assertTrue(vb > va)
self.assertTrue(va <= vb)
self.assertTrue(vb >= va)
self.assertTrue(va != vb)
self.assertTrue(vb == Version("whatever", 1, 0, 0, prerelease=2))
self.assertTrue(va == va)

def test_infComparison(self) -> None:
"""
L{_inf} is equal to L{_inf}.
This is a regression test.
"""
self.assertEqual(_inf, _inf)

def test_disallowBuggyComparisons(self) -> None:
"""
The package names of the Version objects need to be the same,
"""
self.assertRaises(
IncomparableVersions,
operator.eq,
Version("dummy", 1, 0, 0),
Version("dumym", 1, 0, 0),
)

def test_notImplementedComparisons(self) -> None:
"""
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
result = va.__cmp__(vb) # type:ignore[arg-type]
self.assertEqual(result, NotImplemented)

def test_repr(self) -> None:
"""
Calling C{repr} on a version returns a human-readable string
representation of the version.
"""
self.assertEqual(repr(Version("dummy", 1, 2, 3)), "Version('dummy', 1, 2, 3)")

def test_reprWithPrerelease(self) -> None:
"""
Calling C{repr} on a version with a prerelease returns a human-readable
string representation of the version including the prerelease.
"""
self.assertEqual(
repr(Version("dummy", 1, 2, 3, prerelease=4)),
"Version('dummy', 1, 2, 3, release_candidate=4)",
)

def test_str(self) -> None:
"""
Calling C{str} on a version returns a human-readable string
representation of the version.
"""
self.assertEqual(str(Version("dummy", 1, 2, 3)), "[dummy, version 1.2.3]")

def test_strWithPrerelease(self) -> None:
"""
Calling C{str} on a version with a prerelease includes the prerelease.
"""
self.assertEqual(
str(Version("dummy", 1, 0, 0, prerelease=1)), "[dummy, version 1.0.0.rc1]"
)

def testShort(self) -> None:
self.assertEqual(Version("dummy", 1, 2, 3).short(), "1.2.3")

def test_getVersionString(self) -> None:
"""
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 test_getVersionStringWithPrerelease(self) -> None:
"""
L{getVersionString} includes the prerelease, if any.
"""
self.assertEqual(
getVersionString(Version("whatever", 8, 0, 0, prerelease=1)),
"whatever 8.0.0.rc1",
)

def test_base(self) -> None:
"""
The L{base} method returns a very simple representation of the version.
"""
self.assertEqual(Version("foo", 1, 0, 0).base(), "1.0.0")

def test_baseWithPrerelease(self) -> None:
"""
The base version includes 'preX' for versions with prereleases.
"""
self.assertEqual(Version("foo", 1, 0, 0, prerelease=8).base(), "1.0.0.rc8")
2 changes: 1 addition & 1 deletion tox.ini
Original file line number Diff line number Diff line change
Expand Up @@ -74,7 +74,7 @@ deps =
# IOCP is skipped since our CI is designed for Linux.
mindeps: zope.interface == 5.0.0
mindeps: constantly == 15.1
mindeps: incremental == 24.7.0
mindeps: incremental == 21.3.0
mindeps: Automat == 0.8.0
mindeps: hyperlink == 17.1.1
mindeps: attrs == 21.3.0
Expand Down

0 comments on commit 578c7d0

Please sign in to comment.