Detailed tests of postrelease.py ================================ .. :doctest: .. :setup: zest.releaser.tests.functional.setup .. :teardown: zest.releaser.tests.functional.teardown Several items are prepared for us. An svn repository: >>> repo_url 'file://TESTREPO' An svn checkout of a project: >>> svnsourcedir 'TESTTEMP/tha.example-svn' >>> import os >>> os.chdir(svnsourcedir) >>> from zest.releaser.utils import execute_command >>> print(execute_command("svn info %s" % svnsourcedir)) Path: ... URL: file://TESTREPO/tha.example/trunk ... The version is at 0.1.dev0: >>> svnhead('setup.py') from setuptools import setup, find_packages import os.path version = '0.1.dev0' Asking input on the prompt is not unittestable unless we use the prepared testing hack in utils.py: >>> from zest.releaser import utils >>> utils.TESTMODE = True Run the postrelease script: >>> utils.test_answer_book.set_answers(['', '']) >>> from zest.releaser import postrelease >>> postrelease.main() Current version is 0.1 Question: Enter new development version ('.dev0' will be appended) [0.2]: Our reply: Checking data dict Question: OK to commit this (Y/n)? Our reply: The changelog and setup.py are at 0.2 and indicate dev mode: >>> svnhead('CHANGES.txt') Changelog of tha.example ======================== 0.2 (unreleased) ---------------- >>> svnhead('setup.py') from setuptools import setup, find_packages import os.path version = '0.2.dev0' Now we set the version to something that does not end in a number and is not recognized as development version (with setuptools 8 or higher the version is actually reported with a zero at the end): >>> from zest.releaser.svn import Subversion >>> vcs = Subversion() >>> vcs.version '0.2.dev0' >>> vcs.version = '0.1b' >>> vcs.version '0.1b0' Run the postrelease script. Since the version number does not end with a number, the script cannot make a suggestion, except when the number is normalized by setuptools already: >>> utils.test_answer_book.set_answers(['0.2', '']) >>> from zest.releaser import postrelease >>> postrelease.main() Current version is 0.1b0 Question: Enter new development version ('.dev0' will be appended) [0.1b1]: Our reply: 0.2 Checking data dict Question: OK to commit this (Y/n)? Our reply: The changelog and setup.py are at 0.2 and indicate dev mode: >>> svnhead('CHANGES.txt') Changelog of tha.example ======================== 0.2 (unreleased) ---------------- >>> svnhead('setup.py') from setuptools import setup, find_packages import os.path version = '0.2.dev0' The prerelease part would complain when the changelog still contains '- Nothing changed yet.' So change it. >>> add_changelog_entry() To check some corner cases we switch back and forth between prerelease and postrelease. The next version after 0.2.19 should not be 0.2.110 but 0.2.20: >>> from zest.releaser import prerelease >>> utils.test_answer_book.set_answers(['', '', '', '0.2.19', '']) >>> prerelease.main() Question... Question: Enter version [0.2]: Our reply: 0.2.19 Checking data dict Question: OK to commit this (Y/n)? Our reply: >>> utils.test_answer_book.set_answers(['', '']) >>> postrelease.main() Current version is 0.2.19 Question: Enter new development version ('.dev0' will be appended) [0.2.20]: Our reply: Checking data dict Question: OK to commit this (Y/n)? Our reply: Releases without numbers at the end should not fluster us even when we cannot suggest a reasonable number. We'll ask for a version until we get one: >>> add_changelog_entry() >>> utils.test_answer_book.set_answers(['', '', '', '0.3beta', '']) >>> prerelease.main() Question... Question: Enter version [0.2.20]: Our reply: 0.3beta Checking data dict Question: OK to commit this (Y/n)? Our reply: >>> utils.test_answer_book.set_answers(['0.3rc', '']) >>> postrelease.main() Current version is 0.3b0 Question: Enter new development version ('.dev0' will be appended) [0.3b1]: Our reply: 0.3rc Checking data dict Question: OK to commit this (Y/n)? Our reply: Numbers and characters can be combined: >>> add_changelog_entry() >>> utils.test_answer_book.set_answers(['', '', '', '1.0a1', '']) >>> prerelease.main() Question... Question: Enter version [0.3rc0]: Our reply: 1.0a1 Checking data dict Question: OK to commit this (Y/n)? Our reply: >>> utils.test_answer_book.set_answers(['', '']) >>> postrelease.main() Current version is 1.0a1 Question: Enter new development version ('.dev0' will be appended) [1.0a2]: Our reply: Checking data dict Question: OK to commit this (Y/n)? Our reply: If there's an empty history file, it gets a fresh header. >>> add_changelog_entry() >>> utils.test_answer_book.set_answers(['', '', '', '1.0', '']) >>> prerelease.main() Question: ... >>> dont_care = open('CHANGES.txt', 'w').write('') >>> utils.test_answer_book.set_answers(['', '']) >>> postrelease.main() Current ... >>> print(open('CHANGES.txt', 'r').read()) 1.1 (unreleased) ---------------- - Nothing changed yet. If there is no history file, we get no errors and a new history file is not created: >>> add_changelog_entry() >>> utils.test_answer_book.set_answers(['', '', '', '', '']) >>> prerelease.main() Question: ... >>> os.remove('CHANGES.txt') >>> utils.test_answer_book.set_answers(['8.2', '']) >>> postrelease.main() # The setup.py complains and quits. Our test setup catches this. Traceback (most recent call last): ... RuntimeError: SYSTEM EXIT (code=1) >>> open('CHANGES.txt') # Nope, doesn't exist. Traceback (most recent call last): ... FileNotFoundError: [Errno 2] No such file or directory: 'CHANGES.txt' Re-instate the history file again, but omit the restructuredtext header line: >>> dont_care = open('CHANGES.txt', 'w').write('1.0 (1972-12-25)\n\n- hello\n') >>> utils.test_answer_book.set_answers(['', '', '', '1.3', '']) >>> prerelease.main() Question: ... >>> utils.test_answer_book.set_answers(['', '']) >>> postrelease.main() Current ... No errors are raised and an ``----`` underline is assumed for the new header. The old one is left untouched: >>> print(open('CHANGES.txt').read()) 1.4 (unreleased) ---------------- - Nothing changed yet. 1.3 (2009-11-26) - hello