Skip to content

Commit 090b2ae

Browse files
committed
Merge branch 'main' of github.com:pawamoy/copier-templates-extensions
2 parents 844781e + 3abff79 commit 090b2ae

File tree

4 files changed

+23
-0
lines changed

4 files changed

+23
-0
lines changed
Lines changed: 3 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,3 @@
1+
_jinja_extensions:
2+
- copier_templates_extensions.TemplateExtensionLoader
3+
- extensions.py:ContextUpdater
Lines changed: 6 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,6 @@
1+
from copier_templates_extensions import ContextHook
2+
3+
4+
class ContextUpdater(ContextHook):
5+
def hook(self, context):
6+
context["success"] = context["foo"] == "bar"
Lines changed: 1 addition & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1 @@
1+
Success variable: {{ success }}

tests/test_extensions.py

Lines changed: 13 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -78,3 +78,16 @@ def test_deprecated_usage(tmp_path: Path, template_name: str) -> None:
7878
result_file = tmp_path / "result.txt"
7979
assert result_file.exists()
8080
assert result_file.read_text() == "Success variable: True"
81+
82+
83+
def test_answer_access(tmp_path: Path) -> None:
84+
"""Test accessing an answer.
85+
86+
Arguments:
87+
tmp_path: A pytest fixture.
88+
"""
89+
template_path = TEMPLATES_DIRECTORY / "answer_access"
90+
copier.run_copy(str(template_path), tmp_path, data={"foo": "bar"}, defaults=True, overwrite=True, unsafe=True)
91+
result_file = tmp_path / "result.txt"
92+
assert result_file.exists()
93+
assert result_file.read_text() == "Success variable: True"

0 commit comments

Comments
 (0)