import os

from click.testing import CliRunner

from cookiepatcher.__main__ import main


def test_help():
    runner = CliRunner()
    result = runner.invoke(main, ['--help'])

    assert (
        result.output
        == '''Usage: main [OPTIONS] TEMPLATE TARGET

Options:
  -V, --version        Show the version and exit.
  --no-input           Do not prompt for parameters and only use
                       cookiecutter.json file content
  -c, --checkout TEXT  branch, tag or commit to checkout after git clone
  -v, --verbose        Print debug information
  --help               Show this message and exit.
'''
    )
    assert result.exit_code == 0


def test_run():
    runner = CliRunner()
    result = runner.invoke(main, ['tests/template', 'tests/example', '--no-input'])
    assert result.output == ''
    assert result.exit_code == 0
    with open('tests/example/.cookiecutterrc') as fh:
        assert (
            fh.read()
            == '''# Generated by cookiepatcher, a small shim around cookiecutter (pip install cookiepatcher)

default_context:
    name: example
'''
        )
    with open('tests/example/example.txt') as fh:
        assert fh.read() == 'example\n'

    assert 'default' not in os.listdir('tests')
