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

Fix regression where 'default_extension' no longer accepted as positional argument #412

Merged
merged 1 commit into from
Jan 28, 2024
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.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
4 changes: 3 additions & 1 deletion CHANGES.rst
Original file line number Diff line number Diff line change
Expand Up @@ -3,7 +3,9 @@ Changes

In next release ...

-
- Fix a regression where `default_extension` was no longer permitted
as a positional argument to `PageTemplateLoader`.
(`#411 <https://github.com/malthe/chameleon/issues/411>`_)

4.5.0 (2024-01-18)
------------------
Expand Down
22 changes: 20 additions & 2 deletions src/chameleon/tests/test_loader.py
Original file line number Diff line number Diff line change
Expand Up @@ -7,9 +7,9 @@


class LoadTests:
def _makeOne(self, search_path=None, **kwargs):
def _makeOne(self, *args, **kwargs):
klass = self._getTargetClass()
return klass(search_path, **kwargs)
return klass(*args, **kwargs)

def _getTargetClass(self):
from chameleon.loader import TemplateLoader
Expand All @@ -24,6 +24,15 @@ def test_load_relative(self):
result.filename,
os.path.join(here, 'hello_world.pt'))

def test_load_relative_default_extension(self):
import os
here = os.path.join(os.path.dirname(__file__), "inputs")
loader = self._makeOne([here], ".pt")
result = self._load(loader, 'hello_world')
self.assertEqual(
result.filename,
os.path.join(here, 'hello_world.pt'))

def test_consecutive_loads(self):
import os
here = os.path.join(os.path.dirname(__file__), "inputs")
Expand Down Expand Up @@ -140,6 +149,15 @@ def _load(self, loader, spec):
return loader.load(spec, template.PageTemplateFile)


class ZPTLoadPageTests(unittest.TestCase, LoadTests):
def _getTargetClass(self):
from chameleon.zpt.loader import TemplateLoader
return TemplateLoader

def _load(self, loader, spec):
return loader.load(spec)


class ModuleLoadTests(unittest.TestCase):
def _makeOne(self, *args, **kwargs):
from chameleon.loader import ModuleLoader
Expand Down
3 changes: 2 additions & 1 deletion src/chameleon/zpt/loader.py
Original file line number Diff line number Diff line change
Expand Up @@ -28,6 +28,7 @@ class TemplateLoader(BaseLoader):
def __init__(
self,
search_path: Sequence[str] | str | None = None,
default_extension: str | None = None,
*,
formats: _FormatsMapping | None = None,
**kwargs: Any
Expand All @@ -36,7 +37,7 @@ def __init__(
if formats is not None:
self.formats = formats

super().__init__(search_path, **kwargs)
super().__init__(search_path, default_extension, **kwargs)

@overload # type: ignore[override]
def load(
Expand Down
Loading