Skip to content

Commit 0245ba0

Browse files
committed
Add a test for choice variables and extra context
1 parent 2011902 commit 0245ba0

File tree

1 file changed

+43
-0
lines changed

1 file changed

+43
-0
lines changed

tests/test_cookies.py

Lines changed: 43 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -344,3 +344,46 @@ def test_bake_should_fail(cookies):
344344
result.stdout.fnmatch_lines([
345345
'*::test_bake_should_fail PASSED*',
346346
])
347+
348+
@pytest.mark.parametrize('choice', ['mkdocs', 'sphinx', 'none'])
349+
def test_cookies_bake_choices(testdir, choice):
350+
"""Programmatically create a **Cookiecutter** template and make sure that
351+
cookies.bake() works with choice variables.
352+
"""
353+
template = testdir.tmpdir.ensure('cookiecutter-choices', dir=True)
354+
template_config = {
355+
'repo_name': 'docs',
356+
'docs_tool': ['mkdocs', 'sphinx', 'none'],
357+
}
358+
template.join('cookiecutter.json').write(json.dumps(template_config))
359+
360+
repo = template.ensure('{{cookiecutter.repo_name}}', dir=True)
361+
repo.join('README.rst').write("docs_tool: {{cookiecutter.docs_tool}}")
362+
363+
testdir.makepyfile("""
364+
# -*- coding: utf-8 -*-
365+
366+
def test_bake_project(cookies):
367+
result = cookies.bake(
368+
extra_context={'docs_tool': '%s'},
369+
template=r'%s',
370+
)
371+
372+
assert result.exit_code == 0
373+
assert result.exception is None
374+
assert result.project.basename == 'docs'
375+
assert result.project.isdir()
376+
377+
assert result.project.join('README.rst').read() == 'docs_tool: %s'
378+
379+
assert str(result) == '<Result {}>'.format(result.project)
380+
""" % (choice, template, choice))
381+
382+
# run pytest without the template cli arg
383+
result = testdir.runpytest('-v')
384+
385+
result.stdout.fnmatch_lines([
386+
'*::test_bake_project PASSED*',
387+
])
388+
389+
result = testdir.runpytest('-v', '--template={}'.format(template))

0 commit comments

Comments
 (0)