[Python-modules-commits] [cookiecutter] 02/09: Import cookiecutter_1.2.1.orig.tar.gz
Vincent Bernat
bernat at moszumanska.debian.org
Sun Nov 15 23:12:43 UTC 2015
This is an automated email from the git hooks/post-receive script.
bernat pushed a commit to branch master
in repository cookiecutter.
commit db64feff584643eec95fb180dd7e84f2a7c4ba8a
Author: Vincent Bernat <bernat at debian.org>
Date: Sun Nov 15 23:18:40 2015 +0100
Import cookiecutter_1.2.1.orig.tar.gz
---
.travis.yml | 3 +-
AUTHORS.rst | 4 +
HISTORY.rst | 38 ++++++++-
README.rst | 15 ++--
cookiecutter/__init__.py | 2 +-
cookiecutter/config.py | 5 +-
cookiecutter/generate.py | 34 +++++++-
cookiecutter/main.py | 2 +-
setup.py | 14 +++-
...if generate_file == 'y' %}cheese.txt{% endif %} | 1 +
tests/test-generate-context/choices_template.json | 7 ++
tests/test_cookiecutter_local_no_input.py | 7 ++
tests/test_cookiecutter_repo_arg.py | 19 +++--
tests/test_cookiecutters.py | 12 ++-
tests/test_generate_context.py | 93 ++++++++++++++++++++++
tests/test_generate_file.py | 27 +++++++
tests/test_generate_files.py | 15 ++++
tests/test_more_cookiecutters.py | 4 +-
18 files changed, 263 insertions(+), 39 deletions(-)
diff --git a/.travis.yml b/.travis.yml
index e315d1b..7c31e24 100644
--- a/.travis.yml
+++ b/.travis.yml
@@ -2,11 +2,12 @@
sudo: false
language: python
-python: 2.7
+python: 3.5
env:
- TOX_ENV=py27
- TOX_ENV=py33
- TOX_ENV=py34
+ - TOX_ENV=py35
- TOX_ENV=pypy
- TOX_ENV=flake8
diff --git a/AUTHORS.rst b/AUTHORS.rst
index 4b0888b..2e736f4 100644
--- a/AUTHORS.rst
+++ b/AUTHORS.rst
@@ -75,6 +75,8 @@ Contributors
* maiksensi (`@maiksensi`_)
* Andrew Conti (`@agconti`_)
* Valentin Lab (`@vaab`_)
+* Ilja Bauer (`@iljabauer`_)
+* Elias Dorneles (`@eliasdorneles`_)
.. _`@maiksensi`: https://github.com/maiksensi
.. _`@svisser`: https://github.com/svisser
@@ -138,3 +140,5 @@ Contributors
.. _`@drgarcia1986`: https://github.com/drgarcia1986
.. _`@agconti`: https://github.com/agconti
.. _`@vaab`: https://github.com/vaab
+.. _`@iljabauer`: https://github.com/iljabauer
+.. _`@eliasdorneles`: https://github.com/eliasdorneles
diff --git a/HISTORY.rst b/HISTORY.rst
index 7c45b52..25bfce5 100644
--- a/HISTORY.rst
+++ b/HISTORY.rst
@@ -3,15 +3,43 @@
History
-------
-1.1.0 (2015-09-26)
-~~~~~~~~~~~~~~~~~~~~~~~~
+1.2.1 (2015-10-18) Zimtsterne
+~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~
-The goals of this release is to add extra content via the command-line and `copy without render`_.
+*Zimtsterne are cinnamon star cookies*
+
+New Feature:
+
+* Returns rendered project dir, thanks to `@hackebrot`_ (#553)
+
+Bug Fixes:
+
+* Factor in *choice* variables (as introduced in 1.1.0) when using a user config or extra context, thanks to `@ionelmc`_ and `@hackebrot`_ (#536, #542).
+
+Other Changes:
+
+* Enable py35 support on Travis by using Python 3.5 as base Python (`@maiksensi`_ / #540)
+* If a filename is empty, do not generate. Log instead (`@iljabauer`_ / #444)
+* Fix tests as per last changes in `cookiecutter-pypackage`_, thanks to `@eliasdorneles`_ (#555).
+* Removed deprecated cookiecutter-pylibrary-minimal from the list, thanks to `@ionelmc`_ (#556)
+* Moved to using `rualmel.yaml` instead of `PyYAML`, except for Windows users on Python 2.7, thanks to `@pydanny`_ (#557)
+
+.. _`cookiecutter-pypackage`: https://github.com/audreyr/cookiecutter-pypackage
+.. _`@iljabauer`: https://github.com/iljabauer
+.. _`@eliasdorneles`: https://github.com/eliasdorneles
+
+*Why 1.2.1 instead of 1.2.0? There was a problem in the distribution that we pushed to PyPI. Since you can't replace previous files uploaded to PyPI, we deleted the files on PyPI and released 1.2.1.*
+
+
+1.1.0 (2015-09-26) Snickerdoodle
+~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~
+
+The goals of this release were `copy without render` and a few additional command-line options such as `--overwrite-if-exists`, `—replay`, and `output-dir`.
Features:
* Added `copy without render`_ feature, making it much easier for developers of Ansible, Salt Stack, and other recipe-based tools to work with Cookiecutter. Thanks to `@osantana`_ and `@LucianU`_ for their innovation, as well as `@hackebrot`_ for fixing the Windows problems (#132, #184, #425).
-* Added `specify output directory`, thanks to `tony` and `@hackebrot`_ (#531, #452),
+* Added `specify output directory`, thanks to `@tony`_ and `@hackebrot`_ (#531, #452).
* Abort template rendering if the project output directory already exists, thanks to `@lgp171188`_ (#470, #471).
* Add a flag to overwrite existing output directory, thanks to `@lgp171188`_ for the implementation (#495) and `@schacki`_, `@ionelmc`_, `@pydanny`_ and `@hackebrot`_ for submitting issues and code reviews (#475, #493).
* Remove test command in favor of tox, thanks to `@hackebrot`_ (#480).
@@ -20,6 +48,7 @@ Features:
* Add replay feature, thanks to `@hackebrot`_ (#501).
* Be more precise when raising an error for an invalid user config file, thanks to `@vaab`_ and `@hackebrot`_ (#378, #528).
* Added official Python 3.5 support, thanks to `@pydanny`_ and `@hackebrot`_ (#522).
+* Added support for *choice* variables and switch to click style prompts, thanks to `@hackebrot`_ (#441, #455).
Other Changes:
@@ -72,6 +101,7 @@ Other Changes:
.. _`@vaab`: https://github.com/vaab
.. _`@christabor`: https://github.com/christabor
.. _`@torchbox`: https://github.com/torchbox
+.. _`@tony`: https://github.com/tony
.. _`cookiecutter-beamer`: https://github.com/luismartingil/cookiecutter-beamer
.. _`@luismartingil`: https://github.com/luismartingil
diff --git a/README.rst b/README.rst
index 4e96806..7456660 100644
--- a/README.rst
+++ b/README.rst
@@ -3,7 +3,7 @@ Cookiecutter
=============
.. image:: https://img.shields.io/pypi/v/cookiecutter.svg
- :target: https://pypi.python.org/pypi/cookiecutter/1.0.0
+ :target: https://pypi.python.org/pypi/cookiecutter
.. image:: https://travis-ci.org/audreyr/cookiecutter.png?branch=master
:target: https://travis-ci.org/audreyr/cookiecutter
@@ -12,7 +12,7 @@ Cookiecutter
:target: https://ci.appveyor.com/project/audreyr/cookiecutter/branch/master
.. image:: https://img.shields.io/pypi/dm/cookiecutter.svg
- :target: https://pypi.python.org/pypi/cookiecutter/1.0.0
+ :target: https://pypi.python.org/pypi/cookiecutter
.. image:: https://codecov.io/github/audreyr/cookiecutter/coverage.svg?branch=master
:target: https://codecov.io/github/audreyr/cookiecutter?branch=master
@@ -163,7 +163,6 @@ Python
* `cookiecutter-pypackage-minimal`_: A mimimal Python package template.
* `cookiecutter-ansible-role`_: A template to create ansible roles. Forget about file creation and focus on actions.
* `cookiecutter-pylibrary`_: An intricate template designed to quickly get started with good testing and packaging (working configuration for Tox, Pytest, Travis-CI, Coveralls, AppVeyor, Sphinx docs, isort, bumpversion, packaging checks etc).
-* `cookiecutter-pylibrary-minimal`_: Same as above but without Pytest and static configuration for Tox/Travis/AppVeyor (no generator).
* `cookiecutter-pyvanguard`_: A template for cutting edge Python development. `Invoke`_, pytest, bumpversion, and Python 2/3 compatability.
* `Python-iOS-template`_: A template to create a Python project that will run on iOS devices.
* `Python-Android-template`_: A template to create a Python project that will run on Android devices.
@@ -176,9 +175,9 @@ Python
Python-Django
^^^^^^^^^^^^^
+* `cookiecutter-django`_: A bleeding edge Django project template with Bootstrap 4, customizable users app, starter templates, working user registration, celery setup, and much more.
* `cookiecutter-django-rest`_: For creating REST apis for mobile and web applications.
* `cookiecutter-simple-django`_: A cookiecutter template for creating reusable Django projects quickly.
-* `cookiecutter-django`_: A bleeding edge Django project template with Bootstrap 3, customizable users app, starter templates, and working user registration.
* `cookiecutter-djangopackage`_: A template designed to create reusable third-party PyPI friendly Django apps. Documentation is written in tutorial format.
* `cookiecutter-django-cms`_: A template for Django CMS with simple Bootstrap 3 template. It has a quick start and deploy documentation.
* `cookiecutter-djangocms-plugin`_: A template to get started with custom plugins for django-cms
@@ -280,7 +279,6 @@ HTML
.. _`cookiecutter-avr`: https://github.com/solarnz/cookiecutter-avr
.. _`cookiecutter-tumblr-theme`: https://github.com/relekang/cookiecutter-tumblr-theme
.. _`cookiecutter-pylibrary`: https://github.com/ionelmc/cookiecutter-pylibrary
-.. _`cookiecutter-pylibrary-minimal`: https://github.com/ionelmc/cookiecutter-pylibrary-minimal
.. _`cookiecutter-pyvanguard`: https://github.com/robinandeer/cookiecutter-pyvanguard
.. _`Python-iOS-template`: https://github.com/pybee/Python-iOS-template
.. _`Python-Android-template`: https://github.com/pybee/Python-Android-template
@@ -371,7 +369,7 @@ Stuck? Try one of the following:
* You are strongly encouraged to `file an issue`_ about the problem, even if
it's just "I can't get it to work on this cookiecutter" with a link to your
cookiecutter. Don't worry about naming/pinpointing the issue properly.
-* Ask for help in #cookiecutter if you must (but please try one of the other
+* Ask for help on `Gitter`_ if you must (but please try one of the other
options first, so that others can benefit from the discussion)
Development on Cookiecutter is community-driven:
@@ -381,9 +379,9 @@ Development on Cookiecutter is community-driven:
* Everyone is invited to contribute. Read the `contributing instructions`_,
then get started.
-Connect with other Cookiecutter contributors and users in IRC:
+Connect with other Cookiecutter contributors and users on `Gitter`_:
-* #cookiecutter on irc.freenode.net (note: due to work and commitments,
+* https://gitter.im/audreyr/cookiecutter (note: due to work and commitments,
a core committer might not always be available)
Encouragement is unbelievably motivating. If you want more work done on
@@ -435,3 +433,4 @@ rooms, and mailing lists is expected to follow the `PyPA Code of Conduct`_.
.. _`@michaeljoseph`: https://github.com/michaeljoseph
.. _`@pfmoore`: https://github.com/pfmoore
.. _`@hackebrot`: https://github.com/hackebrot
+.. _`Gitter`: https://gitter.im/audreyr/cookiecutter
diff --git a/cookiecutter/__init__.py b/cookiecutter/__init__.py
index b390c28..caf230e 100755
--- a/cookiecutter/__init__.py
+++ b/cookiecutter/__init__.py
@@ -8,4 +8,4 @@ cookiecutter
Main package for Cookiecutter.
"""
-__version__ = '1.1.0'
+__version__ = '1.2.1'
diff --git a/cookiecutter/config.py b/cookiecutter/config.py
index 3418a96..00c8113 100755
--- a/cookiecutter/config.py
+++ b/cookiecutter/config.py
@@ -14,7 +14,10 @@ import logging
import os
import io
-import yaml
+try:
+ import ruamel.yaml as yaml
+except ImportError:
+ import yaml
from .exceptions import ConfigDoesNotExistException
from .exceptions import InvalidConfiguration
diff --git a/cookiecutter/generate.py b/cookiecutter/generate.py
index 536aa1e..94e6e94 100755
--- a/cookiecutter/generate.py
+++ b/cookiecutter/generate.py
@@ -50,6 +50,28 @@ def copy_without_render(path, context):
return False
+def apply_overwrites_to_context(context, overwrite_context):
+ """Modify the given context in place based on the overwrite_context."""
+ for variable, overwrite in overwrite_context.items():
+ if variable not in context:
+ # Do not include variables which are not used in the template
+ continue
+
+ context_value = context[variable]
+
+ if isinstance(context_value, list):
+ # We are dealing with a choice variable
+ if overwrite in context_value:
+ # This overwrite is actually valid for the given context
+ # Let's set it as default (by definition first item in list)
+ # see ``cookiecutter.prompt.prompt_choice_for_config``
+ context_value.remove(overwrite)
+ context_value.insert(0, overwrite)
+ else:
+ # Simply overwrite the value for this variable
+ context[variable] = overwrite
+
+
def generate_context(context_file='cookiecutter.json', default_context=None,
extra_context=None):
"""
@@ -85,9 +107,9 @@ def generate_context(context_file='cookiecutter.json', default_context=None,
# Overwrite context variable defaults with the default context from the
# user's global config, if available
if default_context:
- obj.update(default_context)
+ apply_overwrites_to_context(obj, default_context)
if extra_context:
- obj.update(extra_context)
+ apply_overwrites_to_context(obj, extra_context)
logging.debug('Context generated is {0}'.format(context))
return context
@@ -119,7 +141,13 @@ def generate_file(project_dir, infile, context, env):
# Render the path to the output file (not including the root project dir)
outfile_tmpl = Template(infile)
+
outfile = os.path.join(project_dir, outfile_tmpl.render(**context))
+ file_name_is_empty = os.path.isdir(outfile)
+ if file_name_is_empty:
+ logging.debug('The resulting file name is empty: {0}'.format(outfile))
+ return
+
logging.debug('outfile is {0}'.format(outfile))
# Just copy over binary files. Don't render.
@@ -288,3 +316,5 @@ def generate_files(repo_dir, context=None, output_dir='.',
# run post-gen hook from repo_dir
with work_in(repo_dir):
run_hook('post_gen_project', project_dir, context)
+
+ return project_dir
diff --git a/cookiecutter/main.py b/cookiecutter/main.py
index 2e21103..eae455b 100755
--- a/cookiecutter/main.py
+++ b/cookiecutter/main.py
@@ -131,7 +131,7 @@ def cookiecutter(
dump(template_name, context)
# Create project from local context and project template.
- generate_files(
+ return generate_files(
repo_dir=repo_dir,
context=context,
overwrite_if_exists=overwrite_if_exists,
diff --git a/setup.py b/setup.py
index 2d50482..eff59cf 100755
--- a/setup.py
+++ b/setup.py
@@ -1,6 +1,7 @@
#!/usr/bin/env python
import os
+import platform
import sys
try:
@@ -8,7 +9,7 @@ try:
except ImportError:
from distutils.core import setup
-version = "1.1.0"
+version = "1.2.1"
if sys.argv[-1] == 'publish':
os.system('python setup.py sdist upload')
@@ -30,11 +31,18 @@ requirements = [
'future>=0.15.2',
'binaryornot>=0.2.0',
'jinja2>=2.7',
- 'PyYAML>=3.10',
'click>=5.0',
'whichcraft>=0.1.1'
]
+# Use PyYAML for 2.7 on Windows, ruamel.yaml everywhere else
+PY2 = sys.version_info[0] == 2
+windows = platform.system().lower().startswith('windows')
+if PY2 and windows:
+ requirements.append('PyYAML>=3.10')
+else:
+ requirements.append('ruamel.yaml>=0.10.12')
+
long_description = readme + '\n\n' + history
if sys.argv[-1] == 'readme':
@@ -66,7 +74,7 @@ setup(
license='BSD',
zip_safe=False,
classifiers=[
- 'Development Status :: 3 - Alpha',
+ 'Development Status :: 5 - Production/Stable',
'Environment :: Console',
'Intended Audience :: Developers',
'Natural Language :: English',
diff --git a/tests/files/{% if generate_file == 'y' %}cheese.txt{% endif %} b/tests/files/{% if generate_file == 'y' %}cheese.txt{% endif %}
new file mode 100644
index 0000000..5f47c92
--- /dev/null
+++ b/tests/files/{% if generate_file == 'y' %}cheese.txt{% endif %}
@@ -0,0 +1 @@
+Testing that generate_file was {{ generate_file }}
\ No newline at end of file
diff --git a/tests/test-generate-context/choices_template.json b/tests/test-generate-context/choices_template.json
new file mode 100644
index 0000000..5c61797
--- /dev/null
+++ b/tests/test-generate-context/choices_template.json
@@ -0,0 +1,7 @@
+{
+ "full_name": "Raphael Pierzina",
+ "github_username": "hackebrot",
+ "project_name": "Kivy Project",
+ "repo_name": "{{cookiecutter.project_name|lower}}",
+ "orientation": ["all", "landscape", "portrait"]
+}
diff --git a/tests/test_cookiecutter_local_no_input.py b/tests/test_cookiecutter_local_no_input.py
index cc4a020..6f02b87 100644
--- a/tests/test_cookiecutter_local_no_input.py
+++ b/tests/test_cookiecutter_local_no_input.py
@@ -74,3 +74,10 @@ def test_cookiecutter_templated_context():
no_input=True
)
assert os.path.isdir('fake-project-templated')
+
+
+ at pytest.mark.usefixtures('clean_system', 'remove_additional_dirs')
+def test_cookiecutter_no_input_return_project_dir():
+ """Call `cookiecutter()` with `no_input=True`."""
+ project_dir = main.cookiecutter('tests/fake-repo-pre', no_input=True)
+ assert project_dir == os.path.abspath('fake-project')
diff --git a/tests/test_cookiecutter_repo_arg.py b/tests/test_cookiecutter_repo_arg.py
index 71f1438..103b370 100644
--- a/tests/test_cookiecutter_repo_arg.py
+++ b/tests/test_cookiecutter_repo_arg.py
@@ -26,8 +26,8 @@ def remove_additional_folders(request):
def fin_remove_additional_folders():
if os.path.isdir('cookiecutter-pypackage'):
utils.rmtree('cookiecutter-pypackage')
- if os.path.isdir('boilerplate'):
- utils.rmtree('boilerplate')
+ if os.path.isdir('python_boilerplate'):
+ utils.rmtree('python_boilerplate')
if os.path.isdir('cookiecutter-trytonmodule'):
utils.rmtree('cookiecutter-trytonmodule')
if os.path.isdir('module_name'):
@@ -37,20 +37,19 @@ def remove_additional_folders(request):
@skipif_no_network
@pytest.mark.usefixtures('clean_system', 'remove_additional_folders')
-def test_cookiecutter_git(monkeypatch):
- monkeypatch.setattr(
- 'cookiecutter.prompt.read_user_variable',
- lambda var, default: default
+def test_cookiecutter_git():
+ main.cookiecutter(
+ 'https://github.com/audreyr/cookiecutter-pypackage.git',
+ no_input=True
)
- main.cookiecutter('https://github.com/audreyr/cookiecutter-pypackage.git')
clone_dir = os.path.join(
os.path.expanduser('~/.cookiecutters'),
'cookiecutter-pypackage'
)
assert os.path.exists(clone_dir)
- assert os.path.isdir('boilerplate')
- assert os.path.isfile('boilerplate/README.rst')
- assert os.path.exists('boilerplate/setup.py')
+ assert os.path.isdir('python_boilerplate')
+ assert os.path.isfile('python_boilerplate/README.rst')
+ assert os.path.exists('python_boilerplate/setup.py')
@skipif_no_network
diff --git a/tests/test_cookiecutters.py b/tests/test_cookiecutters.py
index b56246b..31ce920 100644
--- a/tests/test_cookiecutters.py
+++ b/tests/test_cookiecutters.py
@@ -25,12 +25,10 @@ def remove_additional_dirs(request):
Remove special directories which are creating during the tests.
"""
def fin_remove_additional_dirs():
- if os.path.isdir('cookiecutter-pypackage'):
- utils.rmtree('cookiecutter-pypackage')
- if os.path.isdir('cookiecutter-jquery'):
- utils.rmtree('cookiecutter-jquery')
- if os.path.isdir('boilerplate'):
- utils.rmtree('boilerplate')
+ for path in ('cookiecutter-pypackage', 'cookiecutter-jquery',
+ 'python_boilerplate', 'boilerplate'):
+ if os.path.isdir(path):
+ utils.rmtree(path)
request.addfinalizer(fin_remove_additional_dirs)
@@ -39,7 +37,7 @@ def bake_data():
'git clone https://github.com/audreyr/cookiecutter-pypackage.git',
'cookiecutter --no-input cookiecutter-pypackage/',
'cookiecutter-pypackage',
- 'boilerplate/README.rst'
+ 'python_boilerplate/README.rst'
)
jquery_data = (
diff --git a/tests/test_generate_context.py b/tests/test_generate_context.py
index 41d33e9..0aa112c 100644
--- a/tests/test_generate_context.py
+++ b/tests/test_generate_context.py
@@ -16,6 +16,8 @@ from __future__ import unicode_literals
import pytest
import os
import re
+from collections import OrderedDict
+
from cookiecutter import generate
from cookiecutter.exceptions import ContextDecodingException
@@ -97,3 +99,94 @@ def test_generate_context_with_json_decoding_error():
['tests', 'test-generate-context', 'invalid-syntax.json']
)
assert path in str(excinfo.value)
+
+
+ at pytest.fixture
+def default_context():
+ return {
+ 'not_in_template': 'foobar',
+ 'project_name': 'Kivy Project',
+ 'orientation': 'landscape'
+ }
+
+
+ at pytest.fixture
+def extra_context():
+ return {
+ 'also_not_in_template': 'foobar2',
+ 'github_username': 'hackebrot',
+ }
+
+
+ at pytest.fixture
+def context_file():
+ return 'tests/test-generate-context/choices_template.json'
+
+
+def test_choices(context_file, default_context, extra_context):
+ """Make sure that the default for list variables is based on the user
+ config and the list as such is not changed to a single value.
+ """
+ expected_context = {
+ 'choices_template': OrderedDict([
+ ('full_name', 'Raphael Pierzina'),
+ ('github_username', 'hackebrot'),
+ ('project_name', 'Kivy Project'),
+ ('repo_name', '{{cookiecutter.project_name|lower}}'),
+ ('orientation', ['landscape', 'all', 'portrait']),
+ ])
+ }
+
+ generated_context = generate.generate_context(
+ context_file, default_context, extra_context
+ )
+
+ assert generated_context == expected_context
+
+
+ at pytest.fixture
+def template_context():
+ return OrderedDict([
+ ('full_name', 'Raphael Pierzina'),
+ ('github_username', 'hackebrot'),
+ ('project_name', 'Kivy Project'),
+ ('repo_name', '{{cookiecutter.project_name|lower}}'),
+ ('orientation', ['all', 'landscape', 'portrait']),
+ ])
+
+
+def test_apply_overwrites_does_include_unused_variables(template_context):
+ generate.apply_overwrites_to_context(
+ template_context,
+ {'not in template': 'foobar'}
+ )
+
+ assert 'not in template' not in template_context
+
+
+def test_apply_overwrites_sets_non_list_value(template_context):
+ generate.apply_overwrites_to_context(
+ template_context,
+ {'repo_name': 'foobar'}
+ )
+
+ assert template_context['repo_name'] == 'foobar'
+
+
+def test_apply_overwrites_does_not_modify_choices_for_invalid_overwrite(
+ template_context):
+ generate.apply_overwrites_to_context(
+ template_context,
+ {'orientation': 'foobar'}
+ )
+
+ assert template_context['orientation'] == ['all', 'landscape', 'portrait']
+
+
+def test_apply_overwrites_sets_default_for_choice_variable(template_context):
+ generate.apply_overwrites_to_context(
+ template_context,
+ {'orientation': 'landscape'}
+ )
+
+ assert template_context['orientation'] == ['landscape', 'all', 'portrait']
diff --git a/tests/test_generate_file.py b/tests/test_generate_file.py
old mode 100644
new mode 100755
index 33ab611..187973e
--- a/tests/test_generate_file.py
+++ b/tests/test_generate_file.py
@@ -54,6 +54,33 @@ def test_generate_file(env):
assert generated_text == 'Testing cheese'
+ at pytest.mark.usefixtures('remove_cheese_file')
+def test_generate_file_with_false_condition(env):
+ infile = 'tests/files/{% if generate_file == \'y\' %}cheese.txt{% endif %}'
+ generate.generate_file(
+ project_dir=".",
+ infile=infile,
+ context={'generate_file': 'n'},
+ env=env
+ )
+ assert not os.path.exists('tests/files/cheese.txt')
+
+
+ at pytest.mark.usefixtures('remove_cheese_file')
+def test_generate_file_with_true_conditional(env):
+ infile = 'tests/files/{% if generate_file == \'y\' %}cheese.txt{% endif %}'
+ generate.generate_file(
+ project_dir=".",
+ infile=infile,
+ context={'generate_file': 'y'},
+ env=env
+ )
+ assert os.path.isfile('tests/files/cheese.txt')
+ with open('tests/files/cheese.txt', 'rt') as f:
+ generated_text = f.read()
+ assert generated_text == 'Testing that generate_file was y'
+
+
@pytest.fixture
def expected_msg():
msg = (
diff --git a/tests/test_generate_files.py b/tests/test_generate_files.py
index 85142ce..f75b0db 100644
--- a/tests/test_generate_files.py
+++ b/tests/test_generate_files.py
@@ -150,6 +150,21 @@ def test_generate_files_output_dir():
@pytest.mark.usefixtures('clean_system', 'remove_additional_folders')
+def test_return_rendered_project_dir():
+ os.mkdir('tests/custom_output_dir')
+ project_dir = generate.generate_files(
+ context={
+ 'cookiecutter': {'food': 'pizzä'}
+ },
+ repo_dir=os.path.abspath('tests/test-generate-files'),
+ output_dir='tests/custom_output_dir'
+ )
+ assert project_dir == os.path.abspath(
+ 'tests/custom_output_dir/inputpizzä/'
+ )
+
+
+ at pytest.mark.usefixtures('clean_system', 'remove_additional_folders')
def test_generate_files_permissions():
"""
simple.txt and script.sh should retain their respective 0o644 and
diff --git a/tests/test_more_cookiecutters.py b/tests/test_more_cookiecutters.py
index c9d6d5f..4fa30f0 100644
--- a/tests/test_more_cookiecutters.py
+++ b/tests/test_more_cookiecutters.py
@@ -30,6 +30,8 @@ def remove_additional_dirs(request):
utils.rmtree('cookiecutter-pypackage')
if os.path.isdir('boilerplate'):
utils.rmtree('boilerplate')
+ if os.path.isdir('python_boilerplate'):
+ utils.rmtree('python_boilerplate')
request.addfinalizer(fin_remove_additional_dirs)
@@ -64,4 +66,4 @@ def test_cookiecutter_pypackage_git():
# Just skip all the prompts
proc.communicate(input=b'\n\n\n\n\n\n\n\n\n\n\n\n')
- assert os.path.isfile('boilerplate/README.rst')
+ assert os.path.isfile('python_boilerplate/README.rst')
--
Alioth's /usr/local/bin/git-commit-notice on /srv/git.debian.org/git/python-modules/packages/cookiecutter.git
More information about the Python-modules-commits
mailing list