From 63c6a6c0867a791cfe3d7e722f2ba27958781710 Mon Sep 17 00:00:00 2001 From: Malthe Borch Date: Sun, 28 Jan 2024 09:31:44 +0100 Subject: [PATCH] Fix regression where 'default_extension' no longer accepted as positional argument --- CHANGES.rst | 4 +++- src/chameleon/tests/test_loader.py | 22 ++++++++++++++++++++-- src/chameleon/zpt/loader.py | 3 ++- 3 files changed, 25 insertions(+), 4 deletions(-) diff --git a/CHANGES.rst b/CHANGES.rst index d5ce22f4..fc53d86d 100644 --- a/CHANGES.rst +++ b/CHANGES.rst @@ -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 `_) 4.5.0 (2024-01-18) ------------------ diff --git a/src/chameleon/tests/test_loader.py b/src/chameleon/tests/test_loader.py index 8a23fc0c..a3bfa4fc 100644 --- a/src/chameleon/tests/test_loader.py +++ b/src/chameleon/tests/test_loader.py @@ -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 @@ -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") @@ -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 diff --git a/src/chameleon/zpt/loader.py b/src/chameleon/zpt/loader.py index a07e4ea0..01825354 100644 --- a/src/chameleon/zpt/loader.py +++ b/src/chameleon/zpt/loader.py @@ -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 @@ -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(