Skip to content

Commit

Permalink
tests: Add tests for deprecation warnings
Browse files Browse the repository at this point in the history
  • Loading branch information
pawamoy committed Jul 14, 2024
1 parent 7d4182f commit ae24a13
Show file tree
Hide file tree
Showing 7 changed files with 41 additions and 0 deletions.
3 changes: 3 additions & 0 deletions tests/fixtures/deprecation_warning_hook_return/copier.yml
Original file line number Diff line number Diff line change
@@ -0,0 +1,3 @@
_jinja_extensions:
- copier_templates_extensions.TemplateExtensionLoader
- extensions.py:ContextUpdater
6 changes: 6 additions & 0 deletions tests/fixtures/deprecation_warning_hook_return/extensions.py
Original file line number Diff line number Diff line change
@@ -0,0 +1,6 @@
from copier_templates_extensions import ContextHook


class ContextUpdater(ContextHook):
def hook(self, context):
return {"success": True}
Original file line number Diff line number Diff line change
@@ -0,0 +1 @@
Success variable: {{ success|default("not set") }}
3 changes: 3 additions & 0 deletions tests/fixtures/deprecation_warning_update_attr/copier.yml
Original file line number Diff line number Diff line change
@@ -0,0 +1,3 @@
_jinja_extensions:
- copier_templates_extensions.TemplateExtensionLoader
- extensions.py:ContextUpdater
8 changes: 8 additions & 0 deletions tests/fixtures/deprecation_warning_update_attr/extensions.py
Original file line number Diff line number Diff line change
@@ -0,0 +1,8 @@
from copier_templates_extensions import ContextHook


class ContextUpdater(ContextHook):
update = "not sentinel"

def hook(self, context):
context["success"] = True
Original file line number Diff line number Diff line change
@@ -0,0 +1 @@
Success variable: {{ success|default("not set") }}
19 changes: 19 additions & 0 deletions tests/test_extensions.py
Original file line number Diff line number Diff line change
Expand Up @@ -58,3 +58,22 @@ def test_extensions_raising_exceptions(tmp_path: Path, template_name: str, excep
copier.run_copy(str(template_path), tmp_path, defaults=True, overwrite=True, unsafe=True)
assert not (tmp_path / "result.txt").exists()
assert not (tmp_path / "extensions.py").exists()


@pytest.mark.parametrize(
"template_name",
["deprecation_warning_hook_return", "deprecation_warning_update_attr"],
)
def test_deprecated_usage(tmp_path: Path, template_name: str) -> None:
"""Test deprecation warnings.
Arguments:
tmp_path: A pytest fixture.
template_name: The parametrized template to use.
"""
template_path = TEMPLATES_DIRECTORY / template_name
with pytest.warns(DeprecationWarning):
copier.run_copy(str(template_path), tmp_path, defaults=True, overwrite=True, unsafe=True)
result_file = tmp_path / "result.txt"
assert result_file.exists()
assert result_file.read_text() == "Success variable: True"

0 comments on commit ae24a13

Please sign in to comment.