Detailed tests of release.py
============================

.. :doctest:
.. :setup: zest.releaser.tests.functional.setup
.. :teardown: zest.releaser.tests.functional.teardown

Some initial imports:

    >>> from zest.releaser import release
    >>> from zest.releaser import utils
    >>> import os
    >>> from zest.releaser import utils
    >>> utils.TESTMODE = True


Check availability on pypi
--------------------------

"Testing" means "don't really poll pypi", so the test setup does some
monkeypatching for us:

    >>> import urllib2
    >>> urllib2.urlopen
    <function _mock_urlopen at ...>

There's a mock list of packages that our mock pypi provides:

    >>> mock_pypi_available
    []

Search a non-existing package:

    >>> release.package_in_pypi('zest.releaser')
    False

Now search for an "existing" package:

    >>> mock_pypi_available.append('zest.releaser')
    >>> release.package_in_pypi('zest.releaser')
    True


Version grabbing
----------------

    >>> os.chdir(svnsourcedir)
    >>> releaser = release.Releaser()

Grab the version:

    >>> releaser._grab_version()
    >>> releaser.data['version']
    '0.1.dev0'

If, by some weird twist of fate, there's no release: we exit.

    >>> releaser.vcs.get_setup_py_version = lambda: None
    >>> releaser._grab_version()
    Traceback (most recent call last):
    ...
    RuntimeError: SYSTEM EXIT (code=None)


Check tag existence
-------------------

We check if a tag already exists.  First set the version to 0.1:

    >>> releaser = release.Releaser()
    >>> releaser.vcs.version = '0.1'
    >>> releaser._grab_version()
    >>> releaser._check_if_tag_already_exists()
    >>> releaser.data['tag_already_exists']
    False

Mock that the tag exists and check again:

    >>> orig = releaser.vcs.tag_exists
    >>> releaser.vcs.tag_exists = lambda x: True
    >>> utils.answers_for_testing = ['n']
    >>> releaser._check_if_tag_already_exists()
    Question: There is already a tag 0.1, show if there are differences? (Y/n)?
    Our reply: n
    >>> releaser.data['tag_already_exists']
    True
    >>> utils.answers_for_testing = ['y']
    >>> releaser._check_if_tag_already_exists()
    Question: There is already a tag 0.1, show if there are differences? (Y/n)?
    Our reply: y
    svn --non-interactive diff file://TESTREPO/tha.example/tags/0.1 file://TESTREPO/tha.example/trunk
    ...
    >>> # ^^^ The diff itself fails as we mocked its existence
    >>> releaser.data['tag_already_exists']
    True
    >>> releaser.vcs.tag_exists = orig # Revert mock


Making tags
-----------

If the tag doesn't exist yet, we can make one.  The actual tag creation is
tested already, here we test that you get a sys.exit if you refuse to run the
tag command:

    >>> releaser = release.Releaser()
    >>> releaser.data['tag_already_exists'] = False
    >>> releaser.data['version'] = '0.1'
    >>> utils.answers_for_testing = ['n']
    >>> releaser._make_tag()
    Traceback (most recent call last):
    ...
    RuntimeError: SYSTEM EXIT (code=None)

If the the tag already exists, we just return without doing anything.

    >>> releaser.data['tag_already_exists'] = True
    >>> releaser._make_tag()

