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_update.py 33KB

1234567891011121314151617181920212223242526272829303132333435363738394041424344454647484950515253545556575859606162636465666768697071727374757677787980818283848586878889909192939495969798991001011021031041051061071081091101111121131141151161171181191201211221231241251261271281291301311321331341351361371381391401411421431441451461471481491501511521531541551561571581591601611621631641651661671681691701711721731741751761771781791801811821831841851861871881891901911921931941951961971981992002012022032042052062072082092102112122132142152162172182192202212222232242252262272282292302312322332342352362372382392402412422432442452462472482492502512522532542552562572582592602612622632642652662672682692702712722732742752762772782792802812822832842852862872882892902912922932942952962972982993003013023033043053063073083093103113123133143153163173183193203213223233243253263273283293303313323333343353363373383393403413423433443453463473483493503513523533543553563573583593603613623633643653663673683693703713723733743753763773783793803813823833843853863873883893903913923933943953963973983994004014024034044054064074084094104114124134144154164174184194204214224234244254264274284294304314324334344354364374384394404414424434444454464474484494504514524534544554564574584594604614624634644654664674684694704714724734744754764774784794804814824834844854864874884894904914924934944954964974984995005015025035045055065075085095105115125135145155165175185195205215225235245255265275285295305315325335345355365375385395405415425435445455465475485495505515525535545555565575585595605615625635645655665675685695705715725735745755765775785795805815825835845855865875885895905915925935945955965975985996006016026036046056066076086096106116126136146156166176186196206216226236246256266276286296306316326336346356366376386396406416426436446456466476486496506516526536546556566576586596606616626636646656666676686696706716726736746756766776786796806816826836846856866876886896906916926936946956966976986997007017027037047057067077087097107117127137147157167177187197207217227237247257267277287297307317327337347357367377387397407417427437447457467477487497507517527537547557567577587597607617627637647657667677687697707717727737747757767777787797807817827837847857867877887897907917927937947957967977987998008018028038048058068078088098108118128138148158168178188198208218228238248258268278288298308318328338348358368378388398408418428438448458468478488498508518528538548558568578588598608618628638648658668678688698708718728738748758768778788798808818828838848858868878888898908918928938948958968978988999009019029039049059069079089099109119129139149159169179189199209219229239249259269279289299309319329339349359369379389399409419429439449459469479489499509519529539549559569579589599609619629639649659669679689699709719729739749759769779789799809819829839849859869879889899909919929939949959969979989991000100110021003100410051006100710081009101010111012101310141015101610171018101910201021102210231024102510261027102810291030103110321033103410351036103710381039104010411042104310441045104610471048104910501051105210531054105510561057105810591060106110621063106410651066106710681069107010711072107310741075107610771078107910801081108210831084108510861087108810891090109110921093109410951096109710981099110011011102110311041105110611071108110911101111111211131114111511161117111811191120112111221123112411251126112711281129113011311132113311341135113611371138113911401141114211431144114511461147114811491150115111521153115411551156115711581159116011611162116311641165116611671168116911701171117211731174117511761177117811791180118111821183118411851186118711881189119011911192119311941195119611971198119912001201120212031204120512061207120812091210121112121213121412151216121712181219122012211222122312241225122612271228122912301231123212331234123512361237123812391240124112421243124412451246124712481249125012511252125312541255125612571258125912601261
  1. # Copyright (c) Twisted Matrix Laboratories.
  2. # See LICENSE for details.
  3. """
  4. Tests for L{incremental.update}.
  5. """
  6. from __future__ import division, absolute_import
  7. import sys
  8. import os
  9. import datetime
  10. from twisted.python.filepath import FilePath
  11. from twisted.python.compat import NativeStringIO
  12. from twisted.trial.unittest import TestCase
  13. from incremental.update import _run, run
  14. class NonCreatedUpdateTests(TestCase):
  15. def setUp(self):
  16. self.srcdir = FilePath(self.mktemp())
  17. self.srcdir.makedirs()
  18. packagedir = self.srcdir.child("inctestpkg")
  19. packagedir.makedirs()
  20. packagedir.child("__init__.py").setContent(
  21. b"""
  22. from incremental import Version
  23. introduced_in = Version("inctestpkg", "NEXT", 0, 0).short()
  24. next_released_version = "inctestpkg NEXT"
  25. """
  26. )
  27. self.getcwd = lambda: self.srcdir.path
  28. self.packagedir = packagedir
  29. class Date(object):
  30. year = 2016
  31. month = 8
  32. self.date = Date()
  33. def test_create(self):
  34. """
  35. `incremental.update package --create` initialises the version.
  36. """
  37. self.assertFalse(self.packagedir.child("_version.py").exists())
  38. out = []
  39. _run(
  40. "inctestpkg",
  41. path=None,
  42. newversion=None,
  43. patch=False,
  44. rc=False,
  45. post=False,
  46. dev=False,
  47. create=True,
  48. _date=self.date,
  49. _getcwd=self.getcwd,
  50. _print=out.append,
  51. )
  52. self.assertTrue(self.packagedir.child("_version.py").exists())
  53. self.assertEqual(
  54. self.packagedir.child("_version.py").getContent(),
  55. b'''"""
  56. Provides inctestpkg version information.
  57. """
  58. # This file is auto-generated! Do not edit!
  59. # Use `python -m incremental.update inctestpkg` to change this file.
  60. from incremental import Version
  61. __version__ = Version("inctestpkg", 16, 8, 0)
  62. __all__ = ["__version__"]
  63. ''',
  64. )
  65. class MissingTests(TestCase):
  66. def setUp(self):
  67. self.srcdir = FilePath(self.mktemp())
  68. self.srcdir.makedirs()
  69. self.srcdir.child("srca").makedirs()
  70. packagedir = self.srcdir.child("srca").child("inctestpkg")
  71. packagedir.makedirs()
  72. packagedir.child("__init__.py").setContent(
  73. b"""
  74. from incremental import Version
  75. introduced_in = Version("inctestpkg", "NEXT", 0, 0).short()
  76. next_released_version = "inctestpkg NEXT"
  77. """
  78. )
  79. packagedir.child("_version.py").setContent(
  80. b"""
  81. from incremental import Version
  82. __version__ = Version("inctestpkg", 1, 2, 3)
  83. __all__ = ["__version__"]
  84. """
  85. )
  86. self.getcwd = lambda: self.srcdir.path
  87. self.packagedir = packagedir
  88. class Date(object):
  89. year = 2016
  90. month = 8
  91. self.date = Date()
  92. def test_path(self):
  93. """
  94. `incremental.update package --dev` raises and quits if it can't find
  95. the package.
  96. """
  97. out = []
  98. with self.assertRaises(ValueError):
  99. _run(
  100. u"inctestpkg",
  101. path=None,
  102. newversion=None,
  103. patch=False,
  104. rc=False,
  105. post=False,
  106. dev=True,
  107. create=False,
  108. _date=self.date,
  109. _getcwd=self.getcwd,
  110. _print=out.append,
  111. )
  112. class CreatedUpdateInSrcTests(TestCase):
  113. def setUp(self):
  114. self.srcdir = FilePath(self.mktemp())
  115. self.srcdir.makedirs()
  116. self.srcdir.child("src").makedirs()
  117. packagedir = self.srcdir.child("src").child("inctestpkg")
  118. packagedir.makedirs()
  119. packagedir.child("__init__.py").setContent(
  120. b"""
  121. from incremental import Version
  122. introduced_in = Version("inctestpkg", "NEXT", 0, 0).short()
  123. next_released_version = "inctestpkg NEXT"
  124. """
  125. )
  126. packagedir.child("_version.py").setContent(
  127. b"""
  128. from incremental import Version
  129. __version__ = Version("inctestpkg", 1, 2, 3)
  130. __all__ = ["__version__"]
  131. """
  132. )
  133. self.getcwd = lambda: self.srcdir.path
  134. self.packagedir = packagedir
  135. class Date(object):
  136. year = 2016
  137. month = 8
  138. self.date = Date()
  139. def test_path(self):
  140. """
  141. `incremental.update package --path=<path> --dev` increments the dev
  142. version of the package on the given path
  143. """
  144. out = []
  145. _run(
  146. u"inctestpkg",
  147. path=None,
  148. newversion=None,
  149. patch=False,
  150. rc=False,
  151. post=False,
  152. dev=True,
  153. create=False,
  154. _date=self.date,
  155. _getcwd=self.getcwd,
  156. _print=out.append,
  157. )
  158. self.assertTrue(self.packagedir.child("_version.py").exists())
  159. self.assertEqual(
  160. self.packagedir.child("_version.py").getContent(),
  161. b'''"""
  162. Provides inctestpkg version information.
  163. """
  164. # This file is auto-generated! Do not edit!
  165. # Use `python -m incremental.update inctestpkg` to change this file.
  166. from incremental import Version
  167. __version__ = Version("inctestpkg", 1, 2, 3, dev=0)
  168. __all__ = ["__version__"]
  169. ''',
  170. )
  171. _run(
  172. u"inctestpkg",
  173. path=None,
  174. newversion=None,
  175. patch=False,
  176. rc=False,
  177. post=False,
  178. dev=True,
  179. create=False,
  180. _date=self.date,
  181. _getcwd=self.getcwd,
  182. _print=out.append,
  183. )
  184. self.assertTrue(self.packagedir.child("_version.py").exists())
  185. self.assertEqual(
  186. self.packagedir.child("_version.py").getContent(),
  187. b'''"""
  188. Provides inctestpkg version information.
  189. """
  190. # This file is auto-generated! Do not edit!
  191. # Use `python -m incremental.update inctestpkg` to change this file.
  192. from incremental import Version
  193. __version__ = Version("inctestpkg", 1, 2, 3, dev=1)
  194. __all__ = ["__version__"]
  195. ''',
  196. )
  197. class CreatedUpdateTests(TestCase):
  198. maxDiff = None
  199. def setUp(self):
  200. self.srcdir = FilePath(self.mktemp())
  201. self.srcdir.makedirs()
  202. packagedir = self.srcdir.child("inctestpkg")
  203. packagedir.makedirs()
  204. packagedir.child("__init__.py").setContent(
  205. b"""
  206. from incremental import Version
  207. introduced_in = Version("inctestpkg", "NEXT", 0, 0).short()
  208. next_released_version = "inctestpkg NEXT"
  209. """
  210. )
  211. packagedir.child("_version.py").setContent(
  212. b"""
  213. from incremental import Version
  214. __version__ = Version("inctestpkg", 1, 2, 3)
  215. __all__ = ["__version__"]
  216. """
  217. )
  218. self.getcwd = lambda: self.srcdir.path
  219. self.packagedir = packagedir
  220. class Date(object):
  221. year = 2016
  222. month = 8
  223. self.date = Date()
  224. def test_path(self):
  225. """
  226. `incremental.update package --path=<path> --dev` increments the dev
  227. version of the package on the given path
  228. """
  229. out = []
  230. _run(
  231. u"inctestpkg",
  232. path=self.packagedir.path,
  233. newversion=None,
  234. patch=False,
  235. rc=False,
  236. post=False,
  237. dev=True,
  238. create=False,
  239. _date=self.date,
  240. _print=out.append,
  241. )
  242. self.assertTrue(self.packagedir.child("_version.py").exists())
  243. self.assertEqual(
  244. self.packagedir.child("_version.py").getContent(),
  245. b'''"""
  246. Provides inctestpkg version information.
  247. """
  248. # This file is auto-generated! Do not edit!
  249. # Use `python -m incremental.update inctestpkg` to change this file.
  250. from incremental import Version
  251. __version__ = Version("inctestpkg", 1, 2, 3, dev=0)
  252. __all__ = ["__version__"]
  253. ''',
  254. )
  255. def test_dev(self):
  256. """
  257. `incremental.update package --dev` increments the dev version.
  258. """
  259. out = []
  260. _run(
  261. u"inctestpkg",
  262. path=None,
  263. newversion=None,
  264. patch=False,
  265. rc=False,
  266. post=False,
  267. dev=True,
  268. create=False,
  269. _date=self.date,
  270. _getcwd=self.getcwd,
  271. _print=out.append,
  272. )
  273. self.assertTrue(self.packagedir.child("_version.py").exists())
  274. self.assertEqual(
  275. self.packagedir.child("_version.py").getContent(),
  276. b'''"""
  277. Provides inctestpkg version information.
  278. """
  279. # This file is auto-generated! Do not edit!
  280. # Use `python -m incremental.update inctestpkg` to change this file.
  281. from incremental import Version
  282. __version__ = Version("inctestpkg", 1, 2, 3, dev=0)
  283. __all__ = ["__version__"]
  284. ''',
  285. )
  286. def test_patch(self):
  287. """
  288. `incremental.update package --patch` increments the patch version.
  289. """
  290. out = []
  291. _run(
  292. u"inctestpkg",
  293. path=None,
  294. newversion=None,
  295. patch=True,
  296. rc=False,
  297. post=False,
  298. dev=False,
  299. create=False,
  300. _date=self.date,
  301. _getcwd=self.getcwd,
  302. _print=out.append,
  303. )
  304. self.assertEqual(
  305. self.packagedir.child("_version.py").getContent(),
  306. b'''"""
  307. Provides inctestpkg version information.
  308. """
  309. # This file is auto-generated! Do not edit!
  310. # Use `python -m incremental.update inctestpkg` to change this file.
  311. from incremental import Version
  312. __version__ = Version("inctestpkg", 1, 2, 4)
  313. __all__ = ["__version__"]
  314. ''',
  315. )
  316. self.assertEqual(
  317. self.packagedir.child("__init__.py").getContent(),
  318. b"""
  319. from incremental import Version
  320. introduced_in = Version("inctestpkg", 1, 2, 4).short()
  321. next_released_version = "inctestpkg 1.2.4"
  322. """,
  323. )
  324. def test_patch_with_prerelease_and_dev(self):
  325. """
  326. `incremental.update package --patch` increments the patch version, and
  327. disregards any old prerelease/dev versions.
  328. """
  329. self.packagedir.child("_version.py").setContent(
  330. b"""
  331. from incremental import Version
  332. __version__ = Version("inctestpkg", 1, 2, 3, release_candidate=1, dev=2)
  333. __all__ = ["__version__"]
  334. """
  335. )
  336. out = []
  337. _run(
  338. u"inctestpkg",
  339. path=None,
  340. newversion=None,
  341. patch=True,
  342. rc=False,
  343. post=False,
  344. dev=False,
  345. create=False,
  346. _date=self.date,
  347. _getcwd=self.getcwd,
  348. _print=out.append,
  349. )
  350. self.assertEqual(
  351. self.packagedir.child("_version.py").getContent(),
  352. b'''"""
  353. Provides inctestpkg version information.
  354. """
  355. # This file is auto-generated! Do not edit!
  356. # Use `python -m incremental.update inctestpkg` to change this file.
  357. from incremental import Version
  358. __version__ = Version("inctestpkg", 1, 2, 4)
  359. __all__ = ["__version__"]
  360. ''',
  361. )
  362. def test_rc_patch(self):
  363. """
  364. `incremental.update package --patch --rc` increments the patch
  365. version and makes it a release candidate.
  366. """
  367. out = []
  368. _run(
  369. u"inctestpkg",
  370. path=None,
  371. newversion=None,
  372. patch=True,
  373. rc=True,
  374. post=False,
  375. dev=False,
  376. create=False,
  377. _date=self.date,
  378. _getcwd=self.getcwd,
  379. _print=out.append,
  380. )
  381. self.assertEqual(
  382. self.packagedir.child("_version.py").getContent(),
  383. b'''"""
  384. Provides inctestpkg version information.
  385. """
  386. # This file is auto-generated! Do not edit!
  387. # Use `python -m incremental.update inctestpkg` to change this file.
  388. from incremental import Version
  389. __version__ = Version("inctestpkg", 1, 2, 4, release_candidate=1)
  390. __all__ = ["__version__"]
  391. ''',
  392. )
  393. self.assertEqual(
  394. self.packagedir.child("__init__.py").getContent(),
  395. b"""
  396. from incremental import Version
  397. introduced_in = Version("inctestpkg", 1, 2, 4, release_candidate=1).short()
  398. next_released_version = "inctestpkg 1.2.4.rc1"
  399. """,
  400. )
  401. def test_rc_with_existing_rc(self):
  402. """
  403. `incremental.update package --rc` increments the rc version if the
  404. existing version is an rc, and discards any dev version.
  405. """
  406. self.packagedir.child("_version.py").setContent(
  407. b"""
  408. from incremental import Version
  409. __version__ = Version("inctestpkg", 1, 2, 3, release_candidate=1, dev=2)
  410. __all__ = ["__version__"]
  411. """
  412. )
  413. out = []
  414. _run(
  415. u"inctestpkg",
  416. path=None,
  417. newversion=None,
  418. patch=False,
  419. rc=True,
  420. post=False,
  421. dev=False,
  422. create=False,
  423. _date=self.date,
  424. _getcwd=self.getcwd,
  425. _print=out.append,
  426. )
  427. self.assertEqual(
  428. self.packagedir.child("_version.py").getContent(),
  429. b'''"""
  430. Provides inctestpkg version information.
  431. """
  432. # This file is auto-generated! Do not edit!
  433. # Use `python -m incremental.update inctestpkg` to change this file.
  434. from incremental import Version
  435. __version__ = Version("inctestpkg", 1, 2, 3, release_candidate=2)
  436. __all__ = ["__version__"]
  437. ''',
  438. )
  439. self.assertEqual(
  440. self.packagedir.child("__init__.py").getContent(),
  441. b"""
  442. from incremental import Version
  443. introduced_in = Version("inctestpkg", 1, 2, 3, release_candidate=2).short()
  444. next_released_version = "inctestpkg 1.2.3.rc2"
  445. """,
  446. )
  447. def test_rc_with_no_rc(self):
  448. """
  449. `incremental.update package --rc`, when the package is not a release
  450. candidate, will issue a new major/minor rc, and disregards the micro
  451. and dev.
  452. """
  453. self.packagedir.child("_version.py").setContent(
  454. b"""
  455. from incremental import Version
  456. __version__ = Version("inctestpkg", 1, 2, 3, dev=2)
  457. __all__ = ["__version__"]
  458. """
  459. )
  460. out = []
  461. _run(
  462. u"inctestpkg",
  463. path=None,
  464. newversion=None,
  465. patch=False,
  466. rc=True,
  467. post=False,
  468. dev=False,
  469. create=False,
  470. _date=self.date,
  471. _getcwd=self.getcwd,
  472. _print=out.append,
  473. )
  474. self.assertEqual(
  475. self.packagedir.child("_version.py").getContent(),
  476. b'''"""
  477. Provides inctestpkg version information.
  478. """
  479. # This file is auto-generated! Do not edit!
  480. # Use `python -m incremental.update inctestpkg` to change this file.
  481. from incremental import Version
  482. __version__ = Version("inctestpkg", 16, 8, 0, release_candidate=1)
  483. __all__ = ["__version__"]
  484. ''',
  485. )
  486. self.assertEqual(
  487. self.packagedir.child("__init__.py").getContent(),
  488. b"""
  489. from incremental import Version
  490. introduced_in = Version("inctestpkg", 16, 8, 0, release_candidate=1).short()
  491. next_released_version = "inctestpkg 16.8.0.rc1"
  492. """,
  493. )
  494. def test_full_with_rc(self):
  495. """
  496. `incremental.update package`, when the package is a release
  497. candidate, will issue the major/minor, sans release candidate or dev.
  498. """
  499. out = []
  500. _run(
  501. u"inctestpkg",
  502. path=None,
  503. newversion=None,
  504. patch=False,
  505. rc=True,
  506. post=False,
  507. dev=False,
  508. create=False,
  509. _date=self.date,
  510. _getcwd=self.getcwd,
  511. _print=out.append,
  512. )
  513. self.assertEqual(
  514. self.packagedir.child("_version.py").getContent(),
  515. b'''"""
  516. Provides inctestpkg version information.
  517. """
  518. # This file is auto-generated! Do not edit!
  519. # Use `python -m incremental.update inctestpkg` to change this file.
  520. from incremental import Version
  521. __version__ = Version("inctestpkg", 16, 8, 0, release_candidate=1)
  522. __all__ = ["__version__"]
  523. ''',
  524. )
  525. self.assertEqual(
  526. self.packagedir.child("__init__.py").getContent(),
  527. b"""
  528. from incremental import Version
  529. introduced_in = Version("inctestpkg", 16, 8, 0, release_candidate=1).short()
  530. next_released_version = "inctestpkg 16.8.0.rc1"
  531. """,
  532. )
  533. _run(
  534. u"inctestpkg",
  535. path=None,
  536. newversion=None,
  537. patch=False,
  538. rc=False,
  539. post=False,
  540. dev=False,
  541. create=False,
  542. _date=self.date,
  543. _getcwd=self.getcwd,
  544. _print=out.append,
  545. )
  546. self.assertEqual(
  547. self.packagedir.child("_version.py").getContent(),
  548. b'''"""
  549. Provides inctestpkg version information.
  550. """
  551. # This file is auto-generated! Do not edit!
  552. # Use `python -m incremental.update inctestpkg` to change this file.
  553. from incremental import Version
  554. __version__ = Version("inctestpkg", 16, 8, 0)
  555. __all__ = ["__version__"]
  556. ''',
  557. )
  558. self.assertEqual(
  559. self.packagedir.child("__init__.py").getContent(),
  560. b"""
  561. from incremental import Version
  562. introduced_in = Version("inctestpkg", 16, 8, 0).short()
  563. next_released_version = "inctestpkg 16.8.0"
  564. """,
  565. )
  566. def test_full_without_rc(self):
  567. """
  568. `incremental.update package`, when the package is NOT a release
  569. candidate, will raise an error.
  570. """
  571. out = []
  572. with self.assertRaises(ValueError) as e:
  573. _run(
  574. u"inctestpkg",
  575. path=None,
  576. newversion=None,
  577. patch=False,
  578. rc=False,
  579. post=False,
  580. dev=False,
  581. create=False,
  582. _date=self.date,
  583. _getcwd=self.getcwd,
  584. _print=out.append,
  585. )
  586. self.assertEqual(
  587. e.exception.args[0],
  588. "You need to issue a rc before updating the major/minor",
  589. )
  590. def test_post(self):
  591. """
  592. `incremental.update package --post` increments the post version.
  593. """
  594. out = []
  595. _run(
  596. u"inctestpkg",
  597. path=None,
  598. newversion=None,
  599. patch=False,
  600. rc=False,
  601. post=True,
  602. dev=False,
  603. create=False,
  604. _date=self.date,
  605. _getcwd=self.getcwd,
  606. _print=out.append,
  607. )
  608. self.assertTrue(self.packagedir.child("_version.py").exists())
  609. self.assertEqual(
  610. self.packagedir.child("_version.py").getContent(),
  611. b'''"""
  612. Provides inctestpkg version information.
  613. """
  614. # This file is auto-generated! Do not edit!
  615. # Use `python -m incremental.update inctestpkg` to change this file.
  616. from incremental import Version
  617. __version__ = Version("inctestpkg", 1, 2, 3, post=0)
  618. __all__ = ["__version__"]
  619. ''',
  620. )
  621. def test_post_with_prerelease_and_dev(self):
  622. """
  623. `incremental.update package --post` increments the post version, and
  624. disregards any old prerelease/dev versions.
  625. """
  626. self.packagedir.child("_version.py").setContent(
  627. b"""
  628. from incremental import Version
  629. __version__ = Version("inctestpkg", 1, 2, 3, release_candidate=1, dev=2)
  630. __all__ = ["__version__"]
  631. """
  632. )
  633. out = []
  634. _run(
  635. u"inctestpkg",
  636. path=None,
  637. newversion=None,
  638. patch=False,
  639. rc=False,
  640. post=True,
  641. dev=False,
  642. create=False,
  643. _date=self.date,
  644. _getcwd=self.getcwd,
  645. _print=out.append,
  646. )
  647. self.assertEqual(
  648. self.packagedir.child("_version.py").getContent(),
  649. b'''"""
  650. Provides inctestpkg version information.
  651. """
  652. # This file is auto-generated! Do not edit!
  653. # Use `python -m incremental.update inctestpkg` to change this file.
  654. from incremental import Version
  655. __version__ = Version("inctestpkg", 1, 2, 3, post=0)
  656. __all__ = ["__version__"]
  657. ''',
  658. )
  659. def test_post_with_existing_post(self):
  660. """
  661. `incremental.update package --post` increments the post version if the
  662. existing version is an postrelease, and discards any dev version.
  663. """
  664. self.packagedir.child("_version.py").setContent(
  665. b"""
  666. from incremental import Version
  667. __version__ = Version("inctestpkg", 1, 2, 3, post=1, dev=2)
  668. __all__ = ["__version__"]
  669. """
  670. )
  671. out = []
  672. _run(
  673. u"inctestpkg",
  674. path=None,
  675. newversion=None,
  676. patch=False,
  677. rc=False,
  678. post=True,
  679. dev=False,
  680. create=False,
  681. _date=self.date,
  682. _getcwd=self.getcwd,
  683. _print=out.append,
  684. )
  685. self.assertEqual(
  686. self.packagedir.child("_version.py").getContent(),
  687. b'''"""
  688. Provides inctestpkg version information.
  689. """
  690. # This file is auto-generated! Do not edit!
  691. # Use `python -m incremental.update inctestpkg` to change this file.
  692. from incremental import Version
  693. __version__ = Version("inctestpkg", 1, 2, 3, post=2)
  694. __all__ = ["__version__"]
  695. ''',
  696. )
  697. self.assertEqual(
  698. self.packagedir.child("__init__.py").getContent(),
  699. b"""
  700. from incremental import Version
  701. introduced_in = Version("inctestpkg", 1, 2, 3, post=2).short()
  702. next_released_version = "inctestpkg 1.2.3.post2"
  703. """,
  704. )
  705. def test_no_mix_newversion(self):
  706. """
  707. The `--newversion` flag can't be mixed with --patch, --rc, --post,
  708. or --dev.
  709. """
  710. out = []
  711. with self.assertRaises(ValueError) as e:
  712. _run(
  713. u"inctestpkg",
  714. path=None,
  715. newversion="1",
  716. patch=True,
  717. rc=False,
  718. post=False,
  719. dev=False,
  720. create=False,
  721. _date=self.date,
  722. _getcwd=self.getcwd,
  723. _print=out.append,
  724. )
  725. self.assertEqual(e.exception.args[0], "Only give --newversion")
  726. with self.assertRaises(ValueError) as e:
  727. _run(
  728. u"inctestpkg",
  729. path=None,
  730. newversion="1",
  731. patch=False,
  732. rc=True,
  733. post=False,
  734. dev=False,
  735. create=False,
  736. _date=self.date,
  737. _getcwd=self.getcwd,
  738. _print=out.append,
  739. )
  740. self.assertEqual(e.exception.args[0], "Only give --newversion")
  741. with self.assertRaises(ValueError) as e:
  742. _run(
  743. u"inctestpkg",
  744. path=None,
  745. newversion="1",
  746. patch=False,
  747. rc=False,
  748. post=True,
  749. dev=False,
  750. create=False,
  751. _date=self.date,
  752. _getcwd=self.getcwd,
  753. _print=out.append,
  754. )
  755. self.assertEqual(e.exception.args[0], "Only give --newversion")
  756. with self.assertRaises(ValueError) as e:
  757. _run(
  758. u"inctestpkg",
  759. path=None,
  760. newversion="1",
  761. patch=False,
  762. rc=False,
  763. post=False,
  764. dev=True,
  765. create=False,
  766. _date=self.date,
  767. _getcwd=self.getcwd,
  768. _print=out.append,
  769. )
  770. self.assertEqual(e.exception.args[0], "Only give --newversion")
  771. def test_no_mix_dev(self):
  772. """
  773. The `--dev` flag can't be mixed with --patch, --rc, or --post.
  774. """
  775. out = []
  776. with self.assertRaises(ValueError) as e:
  777. _run(
  778. u"inctestpkg",
  779. path=None,
  780. newversion=None,
  781. patch=True,
  782. rc=False,
  783. post=False,
  784. dev=True,
  785. create=False,
  786. _date=self.date,
  787. _getcwd=self.getcwd,
  788. _print=out.append,
  789. )
  790. self.assertEqual(e.exception.args[0], "Only give --dev")
  791. with self.assertRaises(ValueError) as e:
  792. _run(
  793. u"inctestpkg",
  794. path=None,
  795. newversion=None,
  796. patch=False,
  797. rc=True,
  798. post=False,
  799. dev=True,
  800. create=False,
  801. _date=self.date,
  802. _getcwd=self.getcwd,
  803. _print=out.append,
  804. )
  805. self.assertEqual(e.exception.args[0], "Only give --dev")
  806. with self.assertRaises(ValueError) as e:
  807. _run(
  808. u"inctestpkg",
  809. path=None,
  810. newversion=None,
  811. patch=False,
  812. rc=False,
  813. post=True,
  814. dev=True,
  815. create=False,
  816. _date=self.date,
  817. _getcwd=self.getcwd,
  818. _print=out.append,
  819. )
  820. self.assertEqual(e.exception.args[0], "Only give --dev")
  821. def test_no_mix_create(self):
  822. """
  823. The `--create` flag can't be mixed with --patch, --rc, --post,
  824. --dev, or --newversion.
  825. """
  826. out = []
  827. with self.assertRaises(ValueError) as e:
  828. _run(
  829. u"inctestpkg",
  830. path=None,
  831. newversion=None,
  832. patch=True,
  833. rc=False,
  834. post=False,
  835. dev=False,
  836. create=True,
  837. _date=self.date,
  838. _getcwd=self.getcwd,
  839. _print=out.append,
  840. )
  841. self.assertEqual(e.exception.args[0], "Only give --create")
  842. with self.assertRaises(ValueError) as e:
  843. _run(
  844. u"inctestpkg",
  845. path=None,
  846. newversion="1",
  847. patch=False,
  848. rc=False,
  849. post=False,
  850. dev=False,
  851. create=True,
  852. _date=self.date,
  853. _getcwd=self.getcwd,
  854. _print=out.append,
  855. )
  856. self.assertEqual(e.exception.args[0], "Only give --create")
  857. with self.assertRaises(ValueError) as e:
  858. _run(
  859. u"inctestpkg",
  860. path=None,
  861. newversion=None,
  862. patch=False,
  863. rc=True,
  864. post=False,
  865. dev=False,
  866. create=True,
  867. _date=self.date,
  868. _getcwd=self.getcwd,
  869. _print=out.append,
  870. )
  871. self.assertEqual(e.exception.args[0], "Only give --create")
  872. with self.assertRaises(ValueError) as e:
  873. _run(
  874. u"inctestpkg",
  875. path=None,
  876. newversion=None,
  877. patch=False,
  878. rc=False,
  879. post=True,
  880. dev=False,
  881. create=True,
  882. _date=self.date,
  883. _getcwd=self.getcwd,
  884. _print=out.append,
  885. )
  886. self.assertEqual(e.exception.args[0], "Only give --create")
  887. with self.assertRaises(ValueError) as e:
  888. _run(
  889. u"inctestpkg",
  890. path=None,
  891. newversion=None,
  892. patch=False,
  893. rc=False,
  894. post=False,
  895. dev=True,
  896. create=True,
  897. _date=self.date,
  898. _getcwd=self.getcwd,
  899. _print=out.append,
  900. )
  901. self.assertEqual(e.exception.args[0], "Only give --create")
  902. def test_newversion(self):
  903. """
  904. `incremental.update package --newversion=1.2.3.rc1.post2.dev3`, will
  905. set that version in the package.
  906. """
  907. out = []
  908. _run(
  909. u"inctestpkg",
  910. path=None,
  911. newversion="1.2.3.rc1.post2.dev3",
  912. patch=False,
  913. rc=False,
  914. post=False,
  915. dev=False,
  916. create=False,
  917. _date=self.date,
  918. _getcwd=self.getcwd,
  919. _print=out.append,
  920. )
  921. self.assertEqual(
  922. self.packagedir.child("_version.py").getContent(),
  923. b'''"""
  924. Provides inctestpkg version information.
  925. """
  926. # This file is auto-generated! Do not edit!
  927. # Use `python -m incremental.update inctestpkg` to change this file.
  928. from incremental import Version
  929. __version__ = Version("inctestpkg", 1, 2, 3, '''
  930. b"""release_candidate=1, post=2, dev=3)
  931. __all__ = ["__version__"]
  932. """,
  933. )
  934. self.assertEqual(
  935. self.packagedir.child("__init__.py").getContent(),
  936. (
  937. b"""
  938. from incremental import Version
  939. introduced_in = Version("inctestpkg", 1, 2, 3, """
  940. b"""release_candidate=1, post=2, dev=3).short()
  941. next_released_version = "inctestpkg 1.2.3.rc1.post2.dev3"
  942. """
  943. ),
  944. )
  945. def test_newversion_bare(self):
  946. """
  947. `incremental.update package --newversion=1`, will set that
  948. version in the package.
  949. """
  950. out = []
  951. _run(
  952. u"inctestpkg",
  953. path=None,
  954. newversion="1",
  955. patch=False,
  956. rc=False,
  957. post=False,
  958. dev=False,
  959. create=False,
  960. _date=self.date,
  961. _getcwd=self.getcwd,
  962. _print=out.append,
  963. )
  964. self.assertEqual(
  965. self.packagedir.child("_version.py").getContent(),
  966. b'''"""
  967. Provides inctestpkg version information.
  968. """
  969. # This file is auto-generated! Do not edit!
  970. # Use `python -m incremental.update inctestpkg` to change this file.
  971. from incremental import Version
  972. __version__ = Version("inctestpkg", 1, 0, 0)
  973. __all__ = ["__version__"]
  974. ''',
  975. )
  976. self.assertEqual(
  977. self.packagedir.child("__init__.py").getContent(),
  978. b"""
  979. from incremental import Version
  980. introduced_in = Version("inctestpkg", 1, 0, 0).short()
  981. next_released_version = "inctestpkg 1.0.0"
  982. """,
  983. )
  984. def test_newversion_bare_major_minor(self):
  985. """
  986. `incremental.update package --newversion=1.1`, will set that
  987. version in the package.
  988. """
  989. out = []
  990. _run(
  991. u"inctestpkg",
  992. path=None,
  993. newversion="1.1",
  994. patch=False,
  995. rc=False,
  996. post=False,
  997. dev=False,
  998. create=False,
  999. _date=self.date,
  1000. _getcwd=self.getcwd,
  1001. _print=out.append,
  1002. )
  1003. self.assertEqual(
  1004. self.packagedir.child("_version.py").getContent(),
  1005. b'''"""
  1006. Provides inctestpkg version information.
  1007. """
  1008. # This file is auto-generated! Do not edit!
  1009. # Use `python -m incremental.update inctestpkg` to change this file.
  1010. from incremental import Version
  1011. __version__ = Version("inctestpkg", 1, 1, 0)
  1012. __all__ = ["__version__"]
  1013. ''',
  1014. )
  1015. self.assertEqual(
  1016. self.packagedir.child("__init__.py").getContent(),
  1017. b"""
  1018. from incremental import Version
  1019. introduced_in = Version("inctestpkg", 1, 1, 0).short()
  1020. next_released_version = "inctestpkg 1.1.0"
  1021. """,
  1022. )
  1023. class ScriptTests(TestCase):
  1024. def setUp(self):
  1025. self.srcdir = FilePath(self.mktemp())
  1026. self.srcdir.makedirs()
  1027. self.srcdir.child("src").makedirs()
  1028. packagedir = self.srcdir.child("src").child("inctestpkg")
  1029. packagedir.makedirs()
  1030. packagedir.child("__init__.py").setContent(
  1031. b"""
  1032. from incremental import Version
  1033. introduced_in = Version("inctestpkg", "NEXT", 0, 0).short()
  1034. next_released_version = "inctestpkg NEXT"
  1035. """
  1036. )
  1037. packagedir.child("_version.py").setContent(
  1038. b"""
  1039. from incremental import Version
  1040. __version__ = Version("inctestpkg", 1, 2, 3)
  1041. __all__ = ["__version__"]
  1042. """
  1043. )
  1044. self.getcwd = lambda: self.srcdir.path
  1045. self.packagedir = packagedir
  1046. class Date(object):
  1047. year = 2016
  1048. month = 8
  1049. class DateModule(object):
  1050. def today(self):
  1051. return Date()
  1052. self.date = DateModule()
  1053. def test_run(self):
  1054. """
  1055. Calling run() with no args will cause it to print help.
  1056. """
  1057. stringio = NativeStringIO()
  1058. self.patch(sys, "stdout", stringio)
  1059. with self.assertRaises(SystemExit) as e:
  1060. run(["--help"])
  1061. self.assertEqual(e.exception.args[0], 0)
  1062. self.assertIn("Show this message and exit", stringio.getvalue())
  1063. def test_insufficient_args(self):
  1064. """
  1065. Calling run() with no args will cause it to print help.
  1066. """
  1067. stringio = NativeStringIO()
  1068. self.patch(sys, "stdout", stringio)
  1069. self.patch(os, "getcwd", self.getcwd)
  1070. self.patch(datetime, "date", self.date)
  1071. with self.assertRaises(SystemExit) as e:
  1072. run(["inctestpkg", "--rc"])
  1073. self.assertEqual(e.exception.args[0], 0)
  1074. self.assertIn("Updating codebase", stringio.getvalue())
  1075. self.assertEqual(
  1076. self.packagedir.child("_version.py").getContent(),
  1077. b'''"""
  1078. Provides inctestpkg version information.
  1079. """
  1080. # This file is auto-generated! Do not edit!
  1081. # Use `python -m incremental.update inctestpkg` to change this file.
  1082. from incremental import Version
  1083. __version__ = Version("inctestpkg", 16, 8, 0, release_candidate=1)
  1084. __all__ = ["__version__"]
  1085. ''',
  1086. )
  1087. self.assertEqual(
  1088. self.packagedir.child("__init__.py").getContent(),
  1089. b"""
  1090. from incremental import Version
  1091. introduced_in = Version("inctestpkg", 16, 8, 0, release_candidate=1).short()
  1092. next_released_version = "inctestpkg 16.8.0.rc1"
  1093. """,
  1094. )