From 5f4b80e5a1508116271ae8a6087834fff8ee3825 Mon Sep 17 00:00:00 2001 From: Chris McDonough Date: Mon, 29 Jun 2009 10:18:10 +0000 Subject: - Use ``caller_package`` function instead of ``caller_module`` function within ``templating`` to avoid needing to name the caller module in resource overrides (actually match docs). - Make it possible to override templates stored directly in a module with templates in a subdirectory of the same module, stored directly within another module, or stored in a subdirectory of another module (actually match docs). --- repoze/bfg/tests/test_path.py | 27 +++++++++++++++++++++++++++ repoze/bfg/tests/test_templating.py | 5 ++--- repoze/bfg/tests/test_zcml.py | 36 ++++++++++++++++++++++++++++++++++++ 3 files changed, 65 insertions(+), 3 deletions(-) (limited to 'repoze/bfg/tests') diff --git a/repoze/bfg/tests/test_path.py b/repoze/bfg/tests/test_path.py index e8068e52d..636481fde 100644 --- a/repoze/bfg/tests/test_path.py +++ b/repoze/bfg/tests/test_path.py @@ -55,6 +55,33 @@ class TestCallerModule(unittest.TestCase): import unittest result = self._callFUT(3) self.assertEqual(result, unittest) + +class TestCallerPackage(unittest.TestCase): + def _callFUT(self, *arg, **kw): + from repoze.bfg.path import caller_package + return caller_package(*arg, **kw) + + def test_it_level_1(self): + from repoze.bfg import tests + result = self._callFUT(1) + self.assertEqual(result, tests) + + def test_it_level_2(self): + from repoze.bfg import tests + result = self._callFUT(2) + self.assertEqual(result, tests) + + def test_it_level_3(self): + import unittest + result = self._callFUT(3) + self.assertEqual(result, unittest) + + def test_it_package(self): + import repoze.bfg.tests + def dummy_caller_module(*arg): + return repoze.bfg.tests + result = self._callFUT(1, caller_module=dummy_caller_module) + self.assertEqual(result, repoze.bfg.tests) class TestPackagePath(unittest.TestCase): def _callFUT(self, package): diff --git a/repoze/bfg/tests/test_templating.py b/repoze/bfg/tests/test_templating.py index 3ae0483d9..d413acc2e 100644 --- a/repoze/bfg/tests/test_templating.py +++ b/repoze/bfg/tests/test_templating.py @@ -54,8 +54,8 @@ class TestRendererFromCache(unittest.TestCase): def test_relpath_alreadyregistered(self): from repoze.bfg.interfaces import ITemplateRenderer - from repoze.bfg.tests import test_templating - module_name = test_templating.__name__ + from repoze.bfg import tests + module_name = tests.__name__ relpath = 'test_templating.py' spec = '%s\t%s' % (module_name, relpath) renderer = {} @@ -64,7 +64,6 @@ class TestRendererFromCache(unittest.TestCase): self.failUnless(result is renderer) def test_relpath_notyetregistered(self): - from repoze.bfg import resource import os from repoze.bfg.tests import test_templating module_name = test_templating.__name__ diff --git a/repoze/bfg/tests/test_zcml.py b/repoze/bfg/tests/test_zcml.py index a8eec3d48..cba460a0a 100644 --- a/repoze/bfg/tests/test_zcml.py +++ b/repoze/bfg/tests/test_zcml.py @@ -897,6 +897,42 @@ class TestResourceDirective(unittest.TestCase): self.assertEqual(action['args'], ('IDummy', 'foo.pt', 'IDummy', 'foo.pt')) + def test_override_module_with_directory(self): + from repoze.bfg.zcml import _override + context = DummyContext() + self._callFUT(context, 'a', 'b:foo/') + actions = context.actions + self.assertEqual(len(actions), 1) + action = actions[0] + self.assertEqual(action['callable'], _override) + self.assertEqual(action['discriminator'], None) + self.assertEqual(action['args'], + ('IDummy', '', 'IDummy', 'foo/')) + + def test_override_directory_with_module(self): + from repoze.bfg.zcml import _override + context = DummyContext() + self._callFUT(context, 'a:foo/', 'b') + actions = context.actions + self.assertEqual(len(actions), 1) + action = actions[0] + self.assertEqual(action['callable'], _override) + self.assertEqual(action['discriminator'], None) + self.assertEqual(action['args'], + ('IDummy', 'foo/', 'IDummy', '')) + + def test_override_module_with_module(self): + from repoze.bfg.zcml import _override + context = DummyContext() + self._callFUT(context, 'a', 'b') + actions = context.actions + self.assertEqual(len(actions), 1) + action = actions[0] + self.assertEqual(action['callable'], _override) + self.assertEqual(action['discriminator'], None) + self.assertEqual(action['args'], + ('IDummy', '', 'IDummy', '')) + class Test_OverrideFunction(unittest.TestCase): def setUp(self): cleanUp() -- cgit v1.2.3