Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Added: docstrings for extensions feature test files #1373

Merged
merged 1 commit into from
Apr 18, 2020
Merged
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Jump to
Jump to file
Failed to load files.
Diff view
Diff view
Original file line number Diff line number Diff line change
Expand Up @@ -3,5 +3,9 @@
# flake8: noqa

"""Sample post-gen hook for testing that custom extensions are available and exposed methods are callable."""
import sys

print('{% hello cookiecutter.name %}')
if '{% hello cookiecutter.name %}' == 'Hello Cookiemonster!':
sys.exit(0)
else:
sys.exit(1)
Original file line number Diff line number Diff line change
Expand Up @@ -4,4 +4,9 @@

"""Sample pre-gen hook for testing that custom extensions are available and exposed methods are callable."""

print('{% hello cookiecutter.name %}')
import sys

if '{% hello cookiecutter.name %}' == 'Hello Cookiemonster!':
sys.exit(0)
else:
sys.exit(1)
2 changes: 2 additions & 0 deletions tests/test-extensions/hello_extension/hello_extension.py
Original file line number Diff line number Diff line change
Expand Up @@ -16,9 +16,11 @@ def __init__(self, environment):
super(HelloExtension, self).__init__(environment)

def _hello(self, name):
"""Do actual tag replace when invoked by parser."""
return 'Hello {name}!'.format(name=name)

def parse(self, parser):
"""Work when something match `tags` variable."""
lineno = next(parser.stream).lineno
node = parser.parse_expression()
call_method = self.call_method('_hello', [node], lineno=lineno)
Expand Down
9 changes: 8 additions & 1 deletion tests/test_custom_extensions_in_hooks.py
Original file line number Diff line number Diff line change
Expand Up @@ -23,23 +23,30 @@
'post_gen_hook',
])
def template(request):
"""Fixture. Allows to split pre and post hooks test directories."""
return 'tests/test-extensions/' + request.param


@pytest.fixture
def output_dir(tmpdir):
"""Fixture. Create and return custom temp directory for test."""
return str(tmpdir.mkdir('hello'))


@pytest.fixture(autouse=True)
def modify_syspath(monkeypatch):
# Make sure that the custom extension can be loaded
"""Fixture. Make sure that the custom extension can be loaded."""
monkeypatch.syspath_prepend(
'tests/test-extensions/hello_extension'
)


def test_hook_with_extension(template, output_dir):
"""Verify custom Jinja2 extension correctly work in hooks and file rendering.

Each file in hooks has simple tests inside and will raise error if not
correctly rendered.
"""
project_dir = main.cookiecutter(
template,
no_input=True,
Expand Down
12 changes: 5 additions & 7 deletions tests/test_default_extensions.py
Original file line number Diff line number Diff line change
@@ -1,11 +1,6 @@
# -*- coding: utf-8 -*-

"""
test_default_extensions.

Tests to ensure Jinja2 filters/extensions are available from within pre- and
post-gen hooks.
"""
"""Verify Jinja2 filters/extensions are available from pre-gen/post-gen hooks."""

import io
import os
Expand All @@ -16,15 +11,17 @@
from cookiecutter.main import cookiecutter


@pytest.yield_fixture(autouse=True)
@pytest.fixture(autouse=True)
def freeze():
"""Fixture. Make time stating during all tests in this file."""
freezer = freezegun.freeze_time("2015-12-09 23:33:01")
freezer.start()
yield
freezer.stop()


def test_jinja2_time_extension(tmpdir):
"""Verify Jinja2 time extension work correctly."""
project_dir = cookiecutter(
'tests/test-extensions/default/',
no_input=True,
Expand All @@ -49,6 +46,7 @@ def test_jinja2_time_extension(tmpdir):


def test_jinja2_slugify_extension(tmpdir):
"""Verify Jinja2 slugify extension work correctly."""
project_dir = cookiecutter(
'tests/test-extensions/default/',
no_input=True,
Expand Down