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

Add simple_test for custom test extensions #1871

Open
wants to merge 10 commits into
base: main
Choose a base branch
from

Conversation

mlasevich
Copy link

Currently there is a decorator to create a simple filter Jinja extension. This PR adds a similar decorator to create custom test extensions. Included is the decorator, test updatres, and docs updates

tests/test-extensions/local_extension/cookiecutter.json Outdated Show resolved Hide resolved
tests/test_cli.py Outdated Show resolved Hide resolved
mlasevich and others added 2 commits June 23, 2023 08:22
Co-authored-by: Kurt McKee <contactme@kurtmckee.org>
Co-authored-by: Kurt McKee <contactme@kurtmckee.org>
@mlasevich
Copy link
Author

All the corrections have been done, would it be possible to get this reviewed again :-)

Thank you. :-)

Copy link
Member

@kurtmckee kurtmckee left a comment

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Thanks for addressing my concerns regarding the tests! I've given it a more thorough code review.

@jensens / @ericof, I can't say whether this feature is needed or helpful. Please review this as a new feature and determine whether it should be merged. Thanks!

cookiecutter/utils.py Outdated Show resolved Hide resolved
docs/advanced/local_extensions.rst Outdated Show resolved Hide resolved
docs/advanced/local_extensions.rst Outdated Show resolved Hide resolved
docs/advanced/local_extensions.rst Outdated Show resolved Hide resolved
Comment on lines +138 to +139
"""
Register a function for use as a test extension for Jinja templates.
Copy link
Member

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

I think flake8 is upset with this:

Suggested change
"""
Register a function for use as a test extension for Jinja templates.
"""Register a function for use as a test extension for Jinja templates.

Comment on lines +110 to +111
"""
Register a function for use as a filter extension for Jinja templates.
Copy link
Member

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

I think flake8 is upset with this:

Suggested change
"""
Register a function for use as a filter extension for Jinja templates.
"""Register a function for use as a filter extension for Jinja templates.


This decorator allows creation of a filter extension to Jinja as a function
instead of writing a full class extending jinja2's Extension. The function
name becomes the filter name
Copy link
Member

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Suggested change
name becomes the filter name
name becomes the filter name.

Comment on lines +119 to +120
@simple_test
def mirror(value):
Copy link
Member

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

This will be rendered in the API documentation. This should be a more complete example, including RST syntax:

Suggested change
@simple_test
def mirror(value):
.. codeblock:: python
@simple_test
def mirror(value):
return value[::-1]

This suggestion applies to the code changes lower in this file, too.


Which can then be used in jinja template as

{{ cookiecutter.param | mirror }}
Copy link
Member

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

This needs to be a codeblock so that it renders in the API documentation. I don't think pygments has a Jinja lexer specifically, so I'm suggesting text here to avoid incorrect syntax highlighting:

Suggested change
{{ cookiecutter.param | mirror }}
.. codeblock:: text
{{ cookiecutter.param | mirror }}

This suggestion applies to the code changes lower in this file, too.

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
None yet
Projects
None yet
Development

Successfully merging this pull request may close these issues.

None yet

2 participants