Detailed tests of bumpversion.py
================================

Several items are prepared for us.

A git checkout of a project:

    >>> gitsourcedir
    'TESTTEMP/tha.example-git'
    >>> import os
    >>> import sys
    >>> os.chdir(gitsourcedir)

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

Initially there are no tags, and we require them.  In the tests the
error is ugly, but in practice it looks fine, saying no bump is needed.

    >>> from zest.releaser import bumpversion
    >>> bumpversion.main()
    Traceback (most recent call last):
    ...
    RuntimeError: SYSTEM EXIT (code=0)

So first run the fullrelease:

    >>> from zest.releaser import fullrelease
    >>> utils.test_answer_book.set_answers(['', '', '2.9.4', '', '', '', '', '', '', '', 'n'])
    >>> fullrelease.main()
    Question...
    Question: Enter version [0.1]:
    Our reply: 2.9.4
    ...
    >>> githead('CHANGES.txt')
    Changelog of tha.example
    ========================
    <BLANKLINE>
    2.9.5 (unreleased)
    ------------------
    >>> githead('setup.py')
    from setuptools import setup, find_packages
    version = '2.9.5.dev0'

Try bumpversion again.  The first time we again get an error because
no version bump is needed: our current version is already higher than
the latest tag, and we have no feature or breaking change.  In the
tests it is again ugly, but the exit code is zero, which is good.

    >>> utils.test_answer_book.set_answers(['', '', '', '', '', ''])
    >>> bumpversion.main()
    Traceback (most recent call last):
    ...
    RuntimeError: SYSTEM EXIT (code=0)

Now a feature bump::

    >>> sys.argv[1:] = ['--feature']
    >>> bumpversion.main()
    Checking version bump for feature release.
    Last tag: 2.9.4
    Current version: 2.9.5.dev0
    Question: Enter version [2.10.0.dev0]:
    Our reply: <ENTER>
    Checking data dict
    Question: OK to commit this (Y/n)?
    Our reply: <ENTER>
    >>> githead('setup.py')
    from setuptools import setup, find_packages
    version = '2.10.0.dev0'
    >>> githead('CHANGES.txt')
    Changelog of tha.example
    ========================
    <BLANKLINE>
    2.10.0 (unreleased)
    -------------------

Now a breaking bump, and for this test we explicitly say to create a release candidate::

    >>> utils.test_answer_book.set_answers(['3.0.0rc1.dev0', ''])
    >>> sys.argv[1:] = ['--breaking']
    >>> bumpversion.main()
    Checking version bump for breaking release.
    Last tag: 2.9.4
    Current version: 2.10.0.dev0
    Question: Enter version [3.0.0.dev0]:
    Our reply: 3.0.0rc1.dev0
    Checking data dict
    Question: OK to commit this (Y/n)?
    Our reply: <ENTER>
    >>> githead('setup.py')
    from setuptools import setup, find_packages
    version = '3.0.0rc1.dev0'
    >>> githead('CHANGES.txt')
    Changelog of tha.example
    ========================
    <BLANKLINE>
    3.0.0rc1 (unreleased)
    ---------------------

Now a final release, where we keep the dev marker::

    >>> utils.test_answer_book.set_answers(['', ''])
    >>> sys.argv[1:] = ['--final']
    >>> bumpversion.main()
    Checking version bump for final release.
    Last tag: 2.9.4
    Current version: 3.0.0rc1.dev0
    Question: Enter version [3.0.0.dev0]:
    Our reply: <ENTER>
    Checking data dict
    Question: OK to commit this (Y/n)?
    Our reply: <ENTER>
    >>> githead('setup.py')
    from setuptools import setup, find_packages
    version = '3.0.0.dev0'
    >>> githead('CHANGES.txt')
    Changelog of tha.example
    ========================
    <BLANKLINE>
    3.0.0 (unreleased)
    ------------------

It will also work if we use Markdown::

    >>> lines = [
    ...     "[zest.releaser]",
    ...     "history_format = md"]
    >>> with open('setup.cfg', 'w') as f:
    ...     _ = f.write('\n'.join(lines))
    >>> lines = [
    ...     "# Changelog",
    ...     "",
    ...     "## 3.0.0 (unreleased)"]
    >>> with open('CHANGES.txt', 'w') as f:
    ...     _ = f.write('\n'.join(lines))
    >>> commit_all_changes()
    >>> utils.test_answer_book.set_answers(['', ''])
    >>> sys.argv[1:] = ['--final']
    >>> bumpversion.main()
    Checking version bump for final release.
    Last tag: 2.9.4
    Current version: 3.0.0.dev0
    Question: Enter version [3.0.1.dev0]:
    Our reply: <ENTER>
    Checking data dict
    Question: OK to commit this (Y/n)?
    Our reply: <ENTER>
    >>> githead('CHANGES.txt')
    # Changelog
    <BLANKLINE>
    ## 3.0.1 (unreleased)
