From 8888a57341531bd1e50bd306bdff7a35c25c46da Mon Sep 17 00:00:00 2001 From: Chris McDonough Date: Mon, 26 Apr 2010 05:33:35 +0000 Subject: Be kind to KARL: don't assume "debug_templates" will be in the settings dict. --- repoze/bfg/chameleon_text.py | 9 +++++++-- repoze/bfg/chameleon_zpt.py | 9 +++++++-- repoze/bfg/tests/test_chameleon_text.py | 10 ++++++++++ repoze/bfg/tests/test_chameleon_zpt.py | 10 ++++++++++ 4 files changed, 34 insertions(+), 4 deletions(-) diff --git a/repoze/bfg/chameleon_text.py b/repoze/bfg/chameleon_text.py index 73457a128..7aca29529 100644 --- a/repoze/bfg/chameleon_text.py +++ b/repoze/bfg/chameleon_text.py @@ -50,8 +50,13 @@ class TextTemplateRenderer(object): @reify # avoid looking up reload_templates before manager pushed def template(self): settings = get_settings() - auto_reload = settings and settings['reload_templates'] - debug = settings and settings['debug_templates'] + debug = False + auto_reload = False + if settings: + # using .get here is a strategy to be kind to old *tests* rather + # than being kind to any existing production system + auto_reload = settings.get('reload_templates') + debug = settings.get('debug_templates') reg = get_current_registry() translate = None if reg is not None: diff --git a/repoze/bfg/chameleon_zpt.py b/repoze/bfg/chameleon_zpt.py index bacb102bb..ba4c9863f 100644 --- a/repoze/bfg/chameleon_zpt.py +++ b/repoze/bfg/chameleon_zpt.py @@ -33,8 +33,13 @@ class ZPTTemplateRenderer(object): @reify # avoid looking up reload_templates before manager pushed def template(self): settings = get_settings() - auto_reload = settings and settings['reload_templates'] - debug = settings and settings['debug_templates'] + debug = False + auto_reload = False + if settings: + # using .get here is a strategy to be kind to old *tests* rather + # than being kind to any existing production system + auto_reload = settings.get('reload_templates') + debug = settings.get('debug_templates') reg = get_current_registry() translate = None if reg is not None: diff --git a/repoze/bfg/tests/test_chameleon_text.py b/repoze/bfg/tests/test_chameleon_text.py index 38bbc060c..cb30f489a 100644 --- a/repoze/bfg/tests/test_chameleon_text.py +++ b/repoze/bfg/tests/test_chameleon_text.py @@ -90,6 +90,16 @@ class TextTemplateRendererTests(Base, unittest.TestCase): template = instance.template self.assertEqual(template.auto_reload, True) + def test_template_with_emptydict(self): + from repoze.bfg.interfaces import ISettings + self.config.registry.registerUtility({}, ISettings) + minimal = self._getTemplatePath('minimal.txt') + instance = self._makeOne(minimal) + self.failIf('template' in instance.__dict__) + template = instance.template + self.assertEqual(template.auto_reload, False) + self.assertEqual(template.debug, False) + def test_call(self): minimal = self._getTemplatePath('minimal.txt') instance = self._makeOne(minimal) diff --git a/repoze/bfg/tests/test_chameleon_zpt.py b/repoze/bfg/tests/test_chameleon_zpt.py index b24a0430c..4ea5fc281 100644 --- a/repoze/bfg/tests/test_chameleon_zpt.py +++ b/repoze/bfg/tests/test_chameleon_zpt.py @@ -91,6 +91,16 @@ class ZPTTemplateRendererTests(Base, unittest.TestCase): template = instance.template self.assertEqual(template.auto_reload, True) + def test_template_with_emptydict(self): + from repoze.bfg.interfaces import ISettings + self.config.registry.registerUtility({}, ISettings) + minimal = self._getTemplatePath('minimal.pt') + instance = self._makeOne(minimal) + self.failIf('template' in instance.__dict__) + template = instance.template + self.assertEqual(template.auto_reload, False) + self.assertEqual(template.debug, False) + def test_call_with_nondict_value(self): minimal = self._getTemplatePath('minimal.pt') instance = self._makeOne(minimal) -- cgit v1.2.3