Funktionierender Prototyp des Serious Games zur Vermittlung von Wissen zu Software-Engineering-Arbeitsmodellen.
You can not select more than 25 topics Topics must start with a letter or number, can include dashes ('-') and can be up to 35 characters long.

test_version.py 18KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115116117118119120121122123124125126127128129130131132133134135136137138139140141142143144145146147148149150151152153154155156157158159160161162163164165166167168169170171172173174175176177178179180181182183184185186187188189190191192193194195196197198199200201202203204205206207208209210211212213214215216217218219220221222223224225226227228229230231232233234235236237238239240241242243244245246247248249250251252253254255256257258259260261262263264265266267268269270271272273274275276277278279280281282283284285286287288289290291292293294295296297298299300301302303304305306307308309310311312313314315316317318319320321322323324325326327328329330331332333334335336337338339340341342343344345346347348349350351352353354355356357358359360361362363364365366367368369370371372373374375376377378379380381382383384385386387388389390391392393394395396397398399400401402403404405406407408409410411412413414415416417418419420421422423424425426427428429430431432433434435436437438439440441442443444445446447448449450451452453454455456457458459460461462463464465466467468469470471472473474475476477478479480481482483484485486487488489490491492493494495496497498499500501502503504505506507508509510511512513514515516517518519520521522523524525526527528529530531532533534535536537538539540541542543544545546547548549550551552
  1. # Copyright (c) Twisted Matrix Laboratories.
  2. # See LICENSE for details.
  3. """
  4. Tests for L{incremental}.
  5. """
  6. from __future__ import division, absolute_import
  7. import sys
  8. import unittest
  9. import operator
  10. from incremental import getVersionString, IncomparableVersions
  11. from incremental import Version, _inf
  12. from twisted.trial.unittest import TestCase
  13. class VersionsTests(TestCase):
  14. def test_localIsShort(self):
  15. """
  16. The local version is the same as the short version.
  17. """
  18. va = Version("dummy", 1, 0, 0, release_candidate=1, post=2, dev=3)
  19. self.assertEqual(va.local(), va.short())
  20. def test_versionComparison(self):
  21. """
  22. Versions can be compared for equality and order.
  23. """
  24. va = Version("dummy", 1, 0, 0)
  25. vb = Version("dummy", 0, 1, 0)
  26. self.assertTrue(va > vb)
  27. self.assertTrue(vb < va)
  28. self.assertTrue(va >= vb)
  29. self.assertTrue(vb <= va)
  30. self.assertTrue(va != vb)
  31. self.assertTrue(vb == Version("dummy", 0, 1, 0))
  32. self.assertTrue(vb == vb)
  33. @unittest.skipIf(sys.version_info < (3,), "Comparisons do not raise on py2")
  34. def test_versionComparisonNonVersion(self):
  35. """
  36. Versions can be compared with non-versions.
  37. """
  38. v = Version("dummy", 1, 0, 0)
  39. o = object()
  40. with self.assertRaises(TypeError):
  41. v > o
  42. with self.assertRaises(TypeError):
  43. v < o
  44. with self.assertRaises(TypeError):
  45. v >= o
  46. with self.assertRaises(TypeError):
  47. v <= o
  48. self.assertFalse(v == o)
  49. self.assertTrue(v != o)
  50. def test_versionComparisonCaseInsensitive(self):
  51. """
  52. Version package names are case insensitive.
  53. """
  54. va = Version("dummy", 1, 0, 0)
  55. vb = Version("DuMmY", 0, 1, 0)
  56. self.assertTrue(va > vb)
  57. self.assertTrue(vb < va)
  58. self.assertTrue(va >= vb)
  59. self.assertTrue(vb <= va)
  60. self.assertTrue(va != vb)
  61. self.assertTrue(vb == Version("dummy", 0, 1, 0))
  62. self.assertTrue(vb == vb)
  63. def test_comparingNEXTReleases(self):
  64. """
  65. NEXT releases are always larger than numbered releases.
  66. """
  67. va = Version("whatever", "NEXT", 0, 0)
  68. vb = Version("whatever", 1, 0, 0)
  69. self.assertTrue(va > vb)
  70. self.assertFalse(va < vb)
  71. self.assertNotEquals(vb, va)
  72. def test_NEXTMustBeAlone(self):
  73. """
  74. NEXT releases must always have the rest of the numbers set to 0.
  75. """
  76. with self.assertRaises(ValueError):
  77. Version("whatever", "NEXT", 1, 0, release_candidate=0, post=0, dev=0)
  78. with self.assertRaises(ValueError):
  79. Version("whatever", "NEXT", 0, 1, release_candidate=0, post=0, dev=0)
  80. with self.assertRaises(ValueError):
  81. Version("whatever", "NEXT", 0, 0, release_candidate=1, post=0, dev=0)
  82. with self.assertRaises(ValueError):
  83. Version("whatever", "NEXT", 0, 0, release_candidate=0, post=1, dev=0)
  84. with self.assertRaises(ValueError):
  85. Version("whatever", "NEXT", 0, 0, release_candidate=0, post=0, dev=1)
  86. def test_comparingNEXTReleasesEqual(self):
  87. """
  88. NEXT releases are equal to each other.
  89. """
  90. va = Version("whatever", "NEXT", 0, 0)
  91. vb = Version("whatever", "NEXT", 0, 0)
  92. self.assertEquals(vb, va)
  93. def test_comparingPrereleasesWithReleases(self):
  94. """
  95. Prereleases are always less than versions without prereleases.
  96. """
  97. va = Version("whatever", 1, 0, 0, prerelease=1)
  98. vb = Version("whatever", 1, 0, 0)
  99. self.assertTrue(va < vb)
  100. self.assertFalse(va > vb)
  101. self.assertNotEquals(vb, va)
  102. def test_prereleaseDeprecated(self):
  103. """
  104. Passing 'prerelease' to Version is deprecated.
  105. """
  106. Version("whatever", 1, 0, 0, prerelease=1)
  107. warnings = self.flushWarnings([self.test_prereleaseDeprecated])
  108. self.assertEqual(len(warnings), 1)
  109. self.assertEqual(
  110. warnings[0]["message"],
  111. "Passing prerelease to incremental.Version was deprecated in "
  112. "Incremental 16.9.0. Please pass release_candidate instead.",
  113. )
  114. def test_prereleaseAttributeDeprecated(self):
  115. """
  116. Accessing 'prerelease' on a Version is deprecated.
  117. """
  118. va = Version("whatever", 1, 0, 0, release_candidate=1)
  119. va.prerelease
  120. warnings = self.flushWarnings([self.test_prereleaseAttributeDeprecated])
  121. self.assertEqual(len(warnings), 1)
  122. self.assertEqual(
  123. warnings[0]["message"],
  124. "Accessing incremental.Version.prerelease was deprecated in "
  125. "Incremental 16.9.0. Use Version.release_candidate instead.",
  126. )
  127. def test_comparingReleaseCandidatesWithReleases(self):
  128. """
  129. Release Candidates are always less than versions without release
  130. candidates.
  131. """
  132. va = Version("whatever", 1, 0, 0, release_candidate=1)
  133. vb = Version("whatever", 1, 0, 0)
  134. self.assertTrue(va < vb)
  135. self.assertFalse(va > vb)
  136. self.assertNotEquals(vb, va)
  137. def test_comparingPostReleasesWithReleases(self):
  138. """
  139. Post releases are always greater than versions without post
  140. releases.
  141. """
  142. va = Version("whatever", 1, 0, 0, post=1)
  143. vb = Version("whatever", 1, 0, 0)
  144. self.assertTrue(va > vb)
  145. self.assertFalse(va < vb)
  146. self.assertNotEquals(vb, va)
  147. def test_comparingDevReleasesWithPreviousPostReleases(self):
  148. """
  149. Dev releases are always greater than postreleases based on previous
  150. releases.
  151. """
  152. va = Version("whatever", 1, 0, 1, dev=1)
  153. vb = Version("whatever", 1, 0, 0, post=1)
  154. self.assertTrue(va > vb)
  155. self.assertFalse(va < vb)
  156. self.assertNotEquals(vb, va)
  157. def test_comparingDevReleasesWithReleases(self):
  158. """
  159. Dev releases are always less than versions without dev releases.
  160. """
  161. va = Version("whatever", 1, 0, 0, dev=1)
  162. vb = Version("whatever", 1, 0, 0)
  163. self.assertTrue(va < vb)
  164. self.assertFalse(va > vb)
  165. self.assertNotEquals(vb, va)
  166. def test_rcEqualspre(self):
  167. """
  168. Release Candidates are equal to prereleases.
  169. """
  170. va = Version("whatever", 1, 0, 0, release_candidate=1)
  171. vb = Version("whatever", 1, 0, 0, prerelease=1)
  172. self.assertTrue(va == vb)
  173. self.assertFalse(va != vb)
  174. def test_rcOrpreButNotBoth(self):
  175. """
  176. Release Candidate and prerelease can't both be given.
  177. """
  178. with self.assertRaises(ValueError):
  179. Version("whatever", 1, 0, 0, prerelease=1, release_candidate=1)
  180. def test_comparingReleaseCandidates(self):
  181. """
  182. The value specified as the release candidate is used in version
  183. comparisons.
  184. """
  185. va = Version("whatever", 1, 0, 0, release_candidate=1)
  186. vb = Version("whatever", 1, 0, 0, release_candidate=2)
  187. self.assertTrue(va < vb)
  188. self.assertTrue(vb > va)
  189. self.assertTrue(va <= vb)
  190. self.assertTrue(vb >= va)
  191. self.assertTrue(va != vb)
  192. self.assertTrue(vb == Version("whatever", 1, 0, 0, release_candidate=2))
  193. self.assertTrue(va == va)
  194. def test_comparingPost(self):
  195. """
  196. The value specified as the postrelease is used in version comparisons.
  197. """
  198. va = Version("whatever", 1, 0, 0, post=1)
  199. vb = Version("whatever", 1, 0, 0, post=2)
  200. self.assertTrue(va < vb)
  201. self.assertTrue(vb > va)
  202. self.assertTrue(va <= vb)
  203. self.assertTrue(vb >= va)
  204. self.assertTrue(va != vb)
  205. self.assertTrue(vb == Version("whatever", 1, 0, 0, post=2))
  206. self.assertTrue(va == va)
  207. def test_comparingDev(self):
  208. """
  209. The value specified as the dev release is used in version comparisons.
  210. """
  211. va = Version("whatever", 1, 0, 0, dev=1)
  212. vb = Version("whatever", 1, 0, 0, dev=2)
  213. self.assertTrue(va < vb)
  214. self.assertTrue(vb > va)
  215. self.assertTrue(va <= vb)
  216. self.assertTrue(vb >= va)
  217. self.assertTrue(va != vb)
  218. self.assertTrue(vb == Version("whatever", 1, 0, 0, dev=2))
  219. self.assertTrue(va == va)
  220. def test_comparingDevAndRC(self):
  221. """
  222. The value specified as the dev release and release candidate is used in
  223. version comparisons.
  224. """
  225. va = Version("whatever", 1, 0, 0, release_candidate=1, dev=1)
  226. vb = Version("whatever", 1, 0, 0, release_candidate=1, dev=2)
  227. self.assertTrue(va < vb)
  228. self.assertTrue(vb > va)
  229. self.assertTrue(va <= vb)
  230. self.assertTrue(vb >= va)
  231. self.assertTrue(va != vb)
  232. self.assertTrue(vb == Version("whatever", 1, 0, 0, release_candidate=1, dev=2))
  233. self.assertTrue(va == va)
  234. def test_comparingDevAndRCDifferent(self):
  235. """
  236. The value specified as the dev release and release candidate is used in
  237. version comparisons.
  238. """
  239. va = Version("whatever", 1, 0, 0, release_candidate=1, dev=1)
  240. vb = Version("whatever", 1, 0, 0, release_candidate=2, dev=1)
  241. self.assertTrue(va < vb)
  242. self.assertTrue(vb > va)
  243. self.assertTrue(va <= vb)
  244. self.assertTrue(vb >= va)
  245. self.assertTrue(va != vb)
  246. self.assertTrue(vb == Version("whatever", 1, 0, 0, release_candidate=2, dev=1))
  247. self.assertTrue(va == va)
  248. def test_infComparison(self):
  249. """
  250. L{_inf} is equal to L{_inf}.
  251. This is a regression test.
  252. """
  253. o = object()
  254. self.assertEqual(_inf, _inf)
  255. self.assertTrue(_inf > o)
  256. self.assertFalse(_inf < o)
  257. self.assertTrue(_inf >= o)
  258. self.assertFalse(_inf <= o)
  259. self.assertTrue(_inf != o)
  260. self.assertFalse(_inf == o)
  261. def test_disallowBuggyComparisons(self):
  262. """
  263. The package names of the Version objects need to be the same.
  264. """
  265. self.assertRaises(
  266. IncomparableVersions,
  267. operator.eq,
  268. Version("dummy", 1, 0, 0),
  269. Version("dumym", 1, 0, 0),
  270. )
  271. def test_notImplementedComparisons(self):
  272. """
  273. Comparing a L{Version} to some other object type results in
  274. C{NotImplemented}.
  275. """
  276. va = Version("dummy", 1, 0, 0)
  277. vb = ("dummy", 1, 0, 0) # a tuple is not a Version object
  278. self.assertEqual(va.__cmp__(vb), NotImplemented)
  279. def test_repr(self):
  280. """
  281. Calling C{repr} on a version returns a human-readable string
  282. representation of the version.
  283. """
  284. self.assertEqual(repr(Version("dummy", 1, 2, 3)), "Version('dummy', 1, 2, 3)")
  285. def test_reprWithPrerelease(self):
  286. """
  287. Calling C{repr} on a version with a prerelease returns a human-readable
  288. string representation of the version including the prerelease as a
  289. release candidate..
  290. """
  291. self.assertEqual(
  292. repr(Version("dummy", 1, 2, 3, prerelease=4)),
  293. "Version('dummy', 1, 2, 3, release_candidate=4)",
  294. )
  295. def test_reprWithReleaseCandidate(self):
  296. """
  297. Calling C{repr} on a version with a release candidate returns a
  298. human-readable string representation of the version including the rc.
  299. """
  300. self.assertEqual(
  301. repr(Version("dummy", 1, 2, 3, release_candidate=4)),
  302. "Version('dummy', 1, 2, 3, release_candidate=4)",
  303. )
  304. def test_reprWithPost(self):
  305. """
  306. Calling C{repr} on a version with a postrelease returns a
  307. human-readable string representation of the version including the
  308. postrelease.
  309. """
  310. self.assertEqual(
  311. repr(Version("dummy", 1, 2, 3, post=4)), "Version('dummy', 1, 2, 3, post=4)"
  312. )
  313. def test_reprWithDev(self):
  314. """
  315. Calling C{repr} on a version with a dev release returns a
  316. human-readable string representation of the version including the dev
  317. release.
  318. """
  319. self.assertEqual(
  320. repr(Version("dummy", 1, 2, 3, dev=4)), "Version('dummy', 1, 2, 3, dev=4)"
  321. )
  322. def test_str(self):
  323. """
  324. Calling C{str} on a version returns a human-readable string
  325. representation of the version.
  326. """
  327. self.assertEqual(str(Version("dummy", 1, 2, 3)), "[dummy, version 1.2.3]")
  328. def test_strWithPrerelease(self):
  329. """
  330. Calling C{str} on a version with a prerelease includes the prerelease
  331. as a release candidate.
  332. """
  333. self.assertEqual(
  334. str(Version("dummy", 1, 0, 0, prerelease=1)), "[dummy, version 1.0.0.rc1]"
  335. )
  336. def test_strWithReleaseCandidate(self):
  337. """
  338. Calling C{str} on a version with a release candidate includes the
  339. release candidate.
  340. """
  341. self.assertEqual(
  342. str(Version("dummy", 1, 0, 0, release_candidate=1)),
  343. "[dummy, version 1.0.0.rc1]",
  344. )
  345. def test_strWithPost(self):
  346. """
  347. Calling C{str} on a version with a postrelease includes the
  348. postrelease.
  349. """
  350. self.assertEqual(
  351. str(Version("dummy", 1, 0, 0, post=1)), "[dummy, version 1.0.0.post1]"
  352. )
  353. def test_strWithDevAndReleaseCandidate(self):
  354. """
  355. Calling C{str} on a version with a release candidate and dev release
  356. includes the release candidate and the dev release.
  357. """
  358. self.assertEqual(
  359. str(Version("dummy", 1, 0, 0, release_candidate=1, dev=2)),
  360. "[dummy, version 1.0.0.rc1.dev2]",
  361. )
  362. def test_strWithDev(self):
  363. """
  364. Calling C{str} on a version with a dev release includes the dev
  365. release.
  366. """
  367. self.assertEqual(
  368. str(Version("dummy", 1, 0, 0, dev=1)), "[dummy, version 1.0.0.dev1]"
  369. )
  370. def test_strWithDevAndPost(self):
  371. """
  372. Calling C{str} on a version with a postrelease and dev release
  373. includes the postrelease and the dev release.
  374. """
  375. self.assertEqual(
  376. str(Version("dummy", 1, 0, 0, post=1, dev=2)),
  377. "[dummy, version 1.0.0.post1.dev2]",
  378. )
  379. def testShort(self):
  380. self.assertEqual(Version("dummy", 1, 2, 3).short(), "1.2.3")
  381. def test_getVersionString(self):
  382. """
  383. L{getVersionString} returns a string with the package name and the
  384. short version number.
  385. """
  386. self.assertEqual("Twisted 8.0.0", getVersionString(Version("Twisted", 8, 0, 0)))
  387. def test_getVersionStringWithPrerelease(self):
  388. """
  389. L{getVersionString} includes the prerelease as a release candidate, if
  390. any.
  391. """
  392. self.assertEqual(
  393. getVersionString(Version("whatever", 8, 0, 0, prerelease=1)),
  394. "whatever 8.0.0.rc1",
  395. )
  396. def test_getVersionStringWithReleaseCandidate(self):
  397. """
  398. L{getVersionString} includes the release candidate, if any.
  399. """
  400. self.assertEqual(
  401. getVersionString(Version("whatever", 8, 0, 0, release_candidate=1)),
  402. "whatever 8.0.0.rc1",
  403. )
  404. def test_getVersionStringWithPost(self):
  405. """
  406. L{getVersionString} includes the postrelease, if any.
  407. """
  408. self.assertEqual(
  409. getVersionString(Version("whatever", 8, 0, 0, post=1)),
  410. "whatever 8.0.0.post1",
  411. )
  412. def test_getVersionStringWithDev(self):
  413. """
  414. L{getVersionString} includes the dev release, if any.
  415. """
  416. self.assertEqual(
  417. getVersionString(Version("whatever", 8, 0, 0, dev=1)), "whatever 8.0.0.dev1"
  418. )
  419. def test_getVersionStringWithDevAndRC(self):
  420. """
  421. L{getVersionString} includes the dev release and release candidate, if
  422. any.
  423. """
  424. self.assertEqual(
  425. getVersionString(Version("whatever", 8, 0, 0, release_candidate=2, dev=1)),
  426. "whatever 8.0.0.rc2.dev1",
  427. )
  428. def test_getVersionStringWithDevAndPost(self):
  429. """
  430. L{getVersionString} includes the dev release and postrelease, if
  431. any.
  432. """
  433. self.assertEqual(
  434. getVersionString(Version("whatever", 8, 0, 0, post=2, dev=1)),
  435. "whatever 8.0.0.post2.dev1",
  436. )
  437. def test_baseWithNEXT(self):
  438. """
  439. The C{base} method returns just "NEXT" when NEXT is the major version.
  440. """
  441. self.assertEqual(Version("foo", "NEXT", 0, 0).base(), "NEXT")
  442. def test_base(self):
  443. """
  444. The C{base} method returns a very simple representation of the version.
  445. """
  446. self.assertEqual(Version("foo", 1, 0, 0).base(), "1.0.0")
  447. def test_baseWithPrerelease(self):
  448. """
  449. The base version includes 'rcX' for versions with prereleases.
  450. """
  451. self.assertEqual(Version("foo", 1, 0, 0, prerelease=8).base(), "1.0.0.rc8")
  452. def test_baseWithPost(self):
  453. """
  454. The base version includes 'postX' for versions with postreleases.
  455. """
  456. self.assertEqual(Version("foo", 1, 0, 0, post=8).base(), "1.0.0.post8")
  457. def test_baseWithDev(self):
  458. """
  459. The base version includes 'devX' for versions with dev releases.
  460. """
  461. self.assertEqual(Version("foo", 1, 0, 0, dev=8).base(), "1.0.0.dev8")
  462. def test_baseWithReleaseCandidate(self):
  463. """
  464. The base version includes 'rcX' for versions with prereleases.
  465. """
  466. self.assertEqual(
  467. Version("foo", 1, 0, 0, release_candidate=8).base(), "1.0.0.rc8"
  468. )
  469. def test_baseWithDevAndRC(self):
  470. """
  471. The base version includes 'rcXdevX' for versions with dev releases and
  472. a release candidate.
  473. """
  474. self.assertEqual(
  475. Version("foo", 1, 0, 0, release_candidate=2, dev=8).base(), "1.0.0.rc2.dev8"
  476. )
  477. def test_baseWithDevAndPost(self):
  478. """
  479. The base version includes 'postXdevX' for versions with dev releases
  480. and a postrelease.
  481. """
  482. self.assertEqual(
  483. Version("foo", 1, 0, 0, post=2, dev=8).base(), "1.0.0.post2.dev8"
  484. )