Skip to content
Open
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
107 changes: 38 additions & 69 deletions tests/test_bake_project.py
Original file line number Diff line number Diff line change
Expand Up @@ -8,6 +8,7 @@
from cookiecutter.utils import rmtree

from click.testing import CliRunner
import pytest

import importlib

Expand Down Expand Up @@ -84,31 +85,19 @@ def test_bake_with_defaults(cookies):
assert 'tests' in found_toplevel_files


def test_bake_and_run_tests(cookies):
with bake_in_temp_dir(cookies) as result:
assert result.project.isdir()
run_inside_dir('python setup.py test', str(result.project)) == 0
print("test_bake_and_run_tests path", str(result.project))


def test_bake_withspecialchars_and_run_tests(cookies):
"""Ensure that a `full_name` with double quotes does not break setup.py"""
with bake_in_temp_dir(
cookies,
extra_context={'full_name': 'name "quote" name'}
) as result:
assert result.project.isdir()
run_inside_dir('python setup.py test', str(result.project)) == 0


def test_bake_with_apostrophe_and_run_tests(cookies):
"""Ensure that a `full_name` with apostrophes does not break setup.py"""
@pytest.mark.parametrize("extra_context", [
{},
{'full_name': 'name "quote" name'},
{'full_name': "O'connor"}
])
def test_bake_and_run_tests(cookies, extra_context):
with bake_in_temp_dir(
cookies,
extra_context={'full_name': "O'connor"}
cookies,
extra_context=extra_context,
) as result:
assert result.project.isdir()
run_inside_dir('python setup.py test', str(result.project)) == 0
run_inside_dir('python setup.py test', str(result.project))
print("test_bake_and_run_tests path", str(result.project))


# def test_bake_and_run_travis_pypi_setup(cookies):
Expand Down Expand Up @@ -178,23 +167,22 @@ def test_make_help(cookies):
output


def test_bake_selecting_license(cookies):
license_strings = {
'MIT license': 'MIT ',
'BSD license': 'Redistributions of source code must retain the ' +
'above copyright notice, this',
'ISC license': 'ISC License',
'Apache Software License 2.0':
'Licensed under the Apache License, Version 2.0',
'GNU General Public License v3': 'GNU GENERAL PUBLIC LICENSE',
}
for license, target_string in license_strings.items():
with bake_in_temp_dir(
cookies,
extra_context={'open_source_license': license}
) as result:
assert target_string in result.project.join('LICENSE').read()
assert license in result.project.join('setup.py').read()
@pytest.mark.parametrize("license_info", [
('MIT license', 'MIT '),
('BSD license', 'Redistributions of source code must retain the ' +
'above copyright notice, this'),
('ISC license', 'ISC License'),
('Apache Software License 2.0', 'Licensed under the Apache License, Version 2.0'),
('GNU General Public License v3', 'GNU GENERAL PUBLIC LICENSE'),
])
def test_bake_selecting_license(cookies, license_info):
license, target_string = license_info
with bake_in_temp_dir(
cookies,
extra_context={'open_source_license': license}
) as result:
assert target_string in result.project.join('LICENSE').read()
assert license in result.project.join('setup.py').read()


def test_bake_not_open_source(cookies):
Expand All @@ -220,9 +208,9 @@ def test_using_pytest(cookies):
lines = test_file_path.readlines()
assert "import pytest" in ''.join(lines)
# Test the new pytest target
run_inside_dir('python setup.py pytest', str(result.project)) == 0
run_inside_dir('python setup.py pytest', str(result.project))
# Test the test alias (which invokes pytest)
run_inside_dir('python setup.py test', str(result.project)) == 0
run_inside_dir('python setup.py test', str(result.project))


def test_not_using_pytest(cookies):
Expand Down Expand Up @@ -257,40 +245,21 @@ def test_not_using_pytest(cookies):
# "missing password config in .travis.yml"


def test_bake_with_no_console_script(cookies):
context = {'command_line_interface': "No command-line interface"}
result = cookies.bake(extra_context=context)
project_path, project_slug, project_dir = project_info(result)
found_project_files = os.listdir(project_dir)
assert "cli.py" not in found_project_files

setup_path = os.path.join(project_path, 'setup.py')
with open(setup_path, 'r') as setup_file:
assert 'entry_points' not in setup_file.read()


def test_bake_with_console_script_files(cookies):
context = {'command_line_interface': 'click'}
result = cookies.bake(extra_context=context)
project_path, project_slug, project_dir = project_info(result)
found_project_files = os.listdir(project_dir)
assert "cli.py" in found_project_files

setup_path = os.path.join(project_path, 'setup.py')
with open(setup_path, 'r') as setup_file:
assert 'entry_points' in setup_file.read()


def test_bake_with_argparse_console_script_files(cookies):
context = {'command_line_interface': 'argparse'}
@pytest.mark.parametrize("args", [
({'command_line_interface': "No command-line interface"}, False),
({'command_line_interface': 'click'}, True),
({'command_line_interface': 'argparse'}, True),
])
def test_bake_with_console_script(cookies, args):
context, is_present = args
result = cookies.bake(extra_context=context)
project_path, project_slug, project_dir = project_info(result)
found_project_files = os.listdir(project_dir)
assert "cli.py" in found_project_files
assert ("cli.py" in found_project_files) == is_present

setup_path = os.path.join(project_path, 'setup.py')
with open(setup_path, 'r') as setup_file:
assert 'entry_points' in setup_file.read()
assert ('entry_points' in setup_file.read()) == is_present


def test_bake_with_console_script_cli(cookies):
Expand Down