123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115116117118119120121122123124125126127128129130131132133134135136137138139140141142143144145146147148149150151152153154155156157158159160161162163164165166167168169170171172173174175176177178179180181182183184185186187188189190191192193194195196197198199200201202203204205206207208209210211212213214215216217218219220221222223224225226227228229230231232233234235236237238239240241242243244245246247248249250251252253254255256257258259260261262263264265266267268269270271272273274275276277278279280281282283284285286287288289290291292293294295296297298299300301302303304305306307308309310311312313314315316317318319320321322323324325326327328329330331332333334335336337338339340341342343344345346347348349350351352353354355356357358359360361362363364365366367368369370371372373374375376377378379380381382383384385386387388389390391392393394395396397398399400401402403404405406407408409410411412413414415416417418419420421422423424425426427428429430431432433434435436437438439440441442443444445446447448449450451452453454455456457458459460461462463464465466467468469470471472473474475476477478479480481482483484485486487488489490491492493494495496497498499500501502503504505506507508509510511512513514515516517518519520521522523524525526527528529530531532533534535536537538539540541542543544545546547548549550551552 |
- # Copyright (c) Twisted Matrix Laboratories.
- # See LICENSE for details.
-
- """
- Tests for L{incremental}.
- """
-
- from __future__ import division, absolute_import
-
- import sys
- import unittest
- import operator
-
- from incremental import getVersionString, IncomparableVersions
- from incremental import Version, _inf
-
- from twisted.trial.unittest import TestCase
-
-
- class VersionsTests(TestCase):
- def test_localIsShort(self):
- """
- The local version is the same as the short version.
- """
- va = Version("dummy", 1, 0, 0, release_candidate=1, post=2, dev=3)
- self.assertEqual(va.local(), va.short())
-
- 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.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)
-
- @unittest.skipIf(sys.version_info < (3,), "Comparisons do not raise on py2")
- def test_versionComparisonNonVersion(self):
- """
- Versions can be compared with non-versions.
- """
- v = Version("dummy", 1, 0, 0)
- o = object()
-
- with self.assertRaises(TypeError):
- v > o
-
- with self.assertRaises(TypeError):
- v < o
-
- with self.assertRaises(TypeError):
- v >= o
-
- with self.assertRaises(TypeError):
- v <= o
-
- self.assertFalse(v == o)
- self.assertTrue(v != o)
-
- def test_versionComparisonCaseInsensitive(self):
- """
- Version package names are case insensitive.
- """
- 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_comparingNEXTReleases(self):
- """
- NEXT releases are always larger than numbered releases.
- """
- va = Version("whatever", "NEXT", 0, 0)
- vb = Version("whatever", 1, 0, 0)
- self.assertTrue(va > vb)
- self.assertFalse(va < vb)
- self.assertNotEquals(vb, va)
-
- def test_NEXTMustBeAlone(self):
- """
- NEXT releases must always have the rest of the numbers set to 0.
- """
- with self.assertRaises(ValueError):
- Version("whatever", "NEXT", 1, 0, release_candidate=0, post=0, dev=0)
-
- with self.assertRaises(ValueError):
- Version("whatever", "NEXT", 0, 1, release_candidate=0, post=0, dev=0)
-
- with self.assertRaises(ValueError):
- Version("whatever", "NEXT", 0, 0, release_candidate=1, post=0, dev=0)
-
- with self.assertRaises(ValueError):
- Version("whatever", "NEXT", 0, 0, release_candidate=0, post=1, dev=0)
-
- with self.assertRaises(ValueError):
- Version("whatever", "NEXT", 0, 0, release_candidate=0, post=0, dev=1)
-
- def test_comparingNEXTReleasesEqual(self):
- """
- NEXT releases are equal to each other.
- """
- va = Version("whatever", "NEXT", 0, 0)
- vb = Version("whatever", "NEXT", 0, 0)
- self.assertEquals(vb, va)
-
- 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)
-
- 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_prereleaseAttributeDeprecated(self):
- """
- Accessing 'prerelease' on a Version is deprecated.
- """
- va = Version("whatever", 1, 0, 0, release_candidate=1)
- va.prerelease
- warnings = self.flushWarnings([self.test_prereleaseAttributeDeprecated])
- 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 test_comparingReleaseCandidatesWithReleases(self):
- """
- Release Candidates are always less than versions without release
- candidates.
- """
- va = Version("whatever", 1, 0, 0, release_candidate=1)
- vb = Version("whatever", 1, 0, 0)
- self.assertTrue(va < vb)
- self.assertFalse(va > vb)
- self.assertNotEquals(vb, va)
-
- def test_comparingPostReleasesWithReleases(self):
- """
- Post releases are always greater than versions without post
- releases.
- """
- va = Version("whatever", 1, 0, 0, post=1)
- vb = Version("whatever", 1, 0, 0)
- self.assertTrue(va > vb)
- self.assertFalse(va < vb)
- self.assertNotEquals(vb, va)
-
- def test_comparingDevReleasesWithPreviousPostReleases(self):
- """
- Dev releases are always greater than postreleases based on previous
- releases.
- """
- va = Version("whatever", 1, 0, 1, dev=1)
- vb = Version("whatever", 1, 0, 0, post=1)
- self.assertTrue(va > vb)
- self.assertFalse(va < vb)
- self.assertNotEquals(vb, va)
-
- def test_comparingDevReleasesWithReleases(self):
- """
- Dev releases are always less than versions without dev releases.
- """
- va = Version("whatever", 1, 0, 0, dev=1)
- vb = Version("whatever", 1, 0, 0)
- self.assertTrue(va < vb)
- self.assertFalse(va > vb)
- self.assertNotEquals(vb, va)
-
- def test_rcEqualspre(self):
- """
- Release Candidates are equal to prereleases.
- """
- va = Version("whatever", 1, 0, 0, release_candidate=1)
- vb = Version("whatever", 1, 0, 0, prerelease=1)
- self.assertTrue(va == vb)
- self.assertFalse(va != vb)
-
- def test_rcOrpreButNotBoth(self):
- """
- Release Candidate and prerelease can't both be given.
- """
- with self.assertRaises(ValueError):
- Version("whatever", 1, 0, 0, prerelease=1, release_candidate=1)
-
- def test_comparingReleaseCandidates(self):
- """
- The value specified as the release candidate is used in version
- comparisons.
- """
- va = Version("whatever", 1, 0, 0, release_candidate=1)
- vb = Version("whatever", 1, 0, 0, release_candidate=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, release_candidate=2))
- self.assertTrue(va == va)
-
- def test_comparingPost(self):
- """
- The value specified as the postrelease is used in version comparisons.
- """
- va = Version("whatever", 1, 0, 0, post=1)
- vb = Version("whatever", 1, 0, 0, post=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, post=2))
- self.assertTrue(va == va)
-
- def test_comparingDev(self):
- """
- The value specified as the dev release is used in version comparisons.
- """
- va = Version("whatever", 1, 0, 0, dev=1)
- vb = Version("whatever", 1, 0, 0, dev=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, dev=2))
- self.assertTrue(va == va)
-
- def test_comparingDevAndRC(self):
- """
- The value specified as the dev release and release candidate is used in
- version comparisons.
- """
- va = Version("whatever", 1, 0, 0, release_candidate=1, dev=1)
- vb = Version("whatever", 1, 0, 0, release_candidate=1, dev=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, release_candidate=1, dev=2))
- self.assertTrue(va == va)
-
- def test_comparingDevAndRCDifferent(self):
- """
- The value specified as the dev release and release candidate is used in
- version comparisons.
- """
- va = Version("whatever", 1, 0, 0, release_candidate=1, dev=1)
- vb = Version("whatever", 1, 0, 0, release_candidate=2, dev=1)
- 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, release_candidate=2, dev=1))
- self.assertTrue(va == va)
-
- def test_infComparison(self):
- """
- L{_inf} is equal to L{_inf}.
-
- This is a regression test.
- """
- o = object()
- self.assertEqual(_inf, _inf)
- self.assertTrue(_inf > o)
- self.assertFalse(_inf < o)
- self.assertTrue(_inf >= o)
- self.assertFalse(_inf <= o)
- self.assertTrue(_inf != o)
- self.assertFalse(_inf == o)
-
- def test_disallowBuggyComparisons(self):
- """
- 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):
- """
- 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_repr(self):
- """
- 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):
- """
- 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_reprWithReleaseCandidate(self):
- """
- Calling C{repr} on a version with a release candidate returns a
- human-readable string representation of the version including the rc.
- """
- self.assertEqual(
- repr(Version("dummy", 1, 2, 3, release_candidate=4)),
- "Version('dummy', 1, 2, 3, release_candidate=4)",
- )
-
- 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_reprWithDev(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_str(self):
- """
- 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):
- """
- Calling C{str} on a version with a prerelease includes the prerelease
- as a release candidate.
- """
- self.assertEqual(
- str(Version("dummy", 1, 0, 0, prerelease=1)), "[dummy, version 1.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 test_strWithPost(self):
- """
- Calling C{str} on a version with a postrelease includes the
- postrelease.
- """
- self.assertEqual(
- str(Version("dummy", 1, 0, 0, post=1)), "[dummy, version 1.0.0.post1]"
- )
-
- 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.0.rc1.dev2]",
- )
-
- def test_strWithDev(self):
- """
- Calling C{str} on a version with a dev release includes the dev
- release.
- """
- self.assertEqual(
- str(Version("dummy", 1, 0, 0, dev=1)), "[dummy, version 1.0.0.dev1]"
- )
-
- 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 testShort(self):
- self.assertEqual(Version("dummy", 1, 2, 3).short(), "1.2.3")
-
- 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)))
-
- 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_getVersionStringWithReleaseCandidate(self):
- """
- L{getVersionString} includes the release candidate, if any.
- """
- self.assertEqual(
- getVersionString(Version("whatever", 8, 0, 0, release_candidate=1)),
- "whatever 8.0.0.rc1",
- )
-
- 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",
- )
-
- def test_getVersionStringWithDev(self):
- """
- L{getVersionString} includes the dev release, if any.
- """
- self.assertEqual(
- getVersionString(Version("whatever", 8, 0, 0, dev=1)), "whatever 8.0.0.dev1"
- )
-
- 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.0.rc2.dev1",
- )
-
- 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.0.post2.dev1",
- )
-
- def test_baseWithNEXT(self):
- """
- The C{base} method returns just "NEXT" when NEXT is the major version.
- """
- self.assertEqual(Version("foo", "NEXT", 0, 0).base(), "NEXT")
-
- def test_base(self):
- """
- The C{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):
- """
- The base version includes 'rcX' for versions with prereleases.
- """
- self.assertEqual(Version("foo", 1, 0, 0, prerelease=8).base(), "1.0.0.rc8")
-
- def test_baseWithPost(self):
- """
- The base version includes 'postX' for versions with postreleases.
- """
- self.assertEqual(Version("foo", 1, 0, 0, post=8).base(), "1.0.0.post8")
-
- def test_baseWithDev(self):
- """
- The base version includes 'devX' for versions with dev releases.
- """
- self.assertEqual(Version("foo", 1, 0, 0, dev=8).base(), "1.0.0.dev8")
-
- def test_baseWithReleaseCandidate(self):
- """
- The base version includes 'rcX' for versions with prereleases.
- """
- self.assertEqual(
- Version("foo", 1, 0, 0, release_candidate=8).base(), "1.0.0.rc8"
- )
-
- 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.0.rc2.dev8"
- )
-
- def test_baseWithDevAndPost(self):
- """
- The base version includes 'postXdevX' for versions with dev releases
- and a postrelease.
- """
- self.assertEqual(
- Version("foo", 1, 0, 0, post=2, dev=8).base(), "1.0.0.post2.dev8"
- )
|