|
1 | 1 | # -*- coding: utf-8 -*-
|
2 | 2 |
|
3 | 3 | import json
|
4 |
| -import collections |
5 |
| - |
6 | 4 | import pytest
|
7 | 5 |
|
8 | 6 |
|
@@ -30,28 +28,6 @@ def test_valid_fixture(cookies):
|
30 | 28 | assert result.ret == 0
|
31 | 29 |
|
32 | 30 |
|
33 |
| -@pytest.fixture |
34 |
| -def cookiecutter_template(tmpdir): |
35 |
| - template = tmpdir.ensure('cookiecutter-template', dir=True) |
36 |
| - |
37 |
| - template_config = collections.OrderedDict([ |
38 |
| - ('repo_name', 'foobar'), |
39 |
| - ('short_description', 'Test Project'), |
40 |
| - ]) |
41 |
| - template.join('cookiecutter.json').write(json.dumps(template_config)) |
42 |
| - |
43 |
| - template_readme = '\n'.join([ |
44 |
| - '{{cookiecutter.repo_name}}', |
45 |
| - '{% for _ in cookiecutter.repo_name %}={% endfor %}', |
46 |
| - '{{cookiecutter.short_description}}', |
47 |
| - ]) |
48 |
| - |
49 |
| - repo = template.ensure('{{cookiecutter.repo_name}}', dir=True) |
50 |
| - repo.join('README.rst').write(template_readme) |
51 |
| - |
52 |
| - return template |
53 |
| - |
54 |
| - |
55 | 31 | def test_cookies_bake_with_template_kwarg(testdir, cookiecutter_template):
|
56 | 32 | """bake accepts a template kwarg."""
|
57 | 33 | testdir.makepyfile("""
|
@@ -344,3 +320,47 @@ def test_bake_should_fail(cookies):
|
344 | 320 | result.stdout.fnmatch_lines([
|
345 | 321 | '*::test_bake_should_fail PASSED*',
|
346 | 322 | ])
|
| 323 | + |
| 324 | + |
| 325 | +@pytest.mark.parametrize('choice', ['mkdocs', 'sphinx', 'none']) |
| 326 | +def test_cookies_bake_choices(testdir, choice): |
| 327 | + """Programmatically create a **Cookiecutter** template and make sure that |
| 328 | + cookies.bake() works with choice variables. |
| 329 | + """ |
| 330 | + template = testdir.tmpdir.ensure('cookiecutter-choices', dir=True) |
| 331 | + template_config = { |
| 332 | + 'repo_name': 'docs', |
| 333 | + 'docs_tool': ['mkdocs', 'sphinx', 'none'], |
| 334 | + } |
| 335 | + template.join('cookiecutter.json').write(json.dumps(template_config)) |
| 336 | + |
| 337 | + repo = template.ensure('{{cookiecutter.repo_name}}', dir=True) |
| 338 | + repo.join('README.rst').write("docs_tool: {{cookiecutter.docs_tool}}") |
| 339 | + |
| 340 | + testdir.makepyfile(""" |
| 341 | + # -*- coding: utf-8 -*- |
| 342 | +
|
| 343 | + def test_bake_project(cookies): |
| 344 | + result = cookies.bake( |
| 345 | + extra_context={'docs_tool': '%s'}, |
| 346 | + template=r'%s', |
| 347 | + ) |
| 348 | +
|
| 349 | + assert result.exit_code == 0 |
| 350 | + assert result.exception is None |
| 351 | + assert result.project.basename == 'docs' |
| 352 | + assert result.project.isdir() |
| 353 | +
|
| 354 | + assert result.project.join('README.rst').read() == 'docs_tool: %s' |
| 355 | +
|
| 356 | + assert str(result) == '<Result {}>'.format(result.project) |
| 357 | + """ % (choice, template, choice)) |
| 358 | + |
| 359 | + # run pytest without the template cli arg |
| 360 | + result = testdir.runpytest('-v') |
| 361 | + |
| 362 | + result.stdout.fnmatch_lines([ |
| 363 | + '*::test_bake_project PASSED*', |
| 364 | + ]) |
| 365 | + |
| 366 | + result = testdir.runpytest('-v', '--template={}'.format(template)) |
0 commit comments