From a56564945ae07da87e5ccbca9c137095c250ced3 Mon Sep 17 00:00:00 2001 From: Chris McDonough Date: Mon, 13 Dec 2010 23:28:59 -0500 Subject: - When creating a Configurator from within a ``paster pshell`` session, you were required to pass a ``package`` argument although ``package`` is not actually required. If you didn't pass ``package``, you would receive an error something like ``KeyError: '__name__'`` emanating from the ``pyramid.path.caller_module`` function. This has now been fixed. --- CHANGES.txt | 6 ++++++ pyramid/path.py | 4 ++-- pyramid/tests/test_path.py | 16 ++++++++++++++-- 3 files changed, 22 insertions(+), 4 deletions(-) diff --git a/CHANGES.txt b/CHANGES.txt index dfa7bf7fc..be2bd2b5f 100644 --- a/CHANGES.txt +++ b/CHANGES.txt @@ -48,6 +48,12 @@ Dependencies Bug Fixes --------- +- When creating a Configurator from within a ``paster pshell`` session, you + were required to pass a ``package`` argument although ``package`` is not + actually required. If you didn't pass ``package``, you would receive an + error something like ``KeyError: '__name__'`` emanating from the + ``pyramid.path.caller_module`` function. This has now been fixed. + - The ``pyramid_routesalchemy`` paster template's unit tests failed (``AssertionError: 'SomeProject' != 'someproject'``). This is fixed. diff --git a/pyramid/path.py b/pyramid/path.py index 10647c073..9c7be4c57 100644 --- a/pyramid/path.py +++ b/pyramid/path.py @@ -14,9 +14,9 @@ def caller_path(path, level=2): path = os.path.join(prefix, path) return path -def caller_module(level=2): +def caller_module(level=2, sys=sys): module_globals = sys._getframe(level).f_globals - module_name = module_globals['__name__'] + module_name = module_globals.get('__name__') or '__main__' module = sys.modules[module_name] return module diff --git a/pyramid/tests/test_path.py b/pyramid/tests/test_path.py index c097615af..5619aafa1 100644 --- a/pyramid/tests/test_path.py +++ b/pyramid/tests/test_path.py @@ -36,9 +36,9 @@ class TestCallerPath(unittest.TestCase): self.assertEqual(test_path.__abspath__, here) class TestCallerModule(unittest.TestCase): - def _callFUT(self, level=2): + def _callFUT(self, *arg, **kw): from pyramid.path import caller_module - return caller_module(level) + return caller_module(*arg, **kw) def test_it_level_1(self): from pyramid.tests import test_path @@ -55,6 +55,18 @@ class TestCallerModule(unittest.TestCase): result = self._callFUT(3) self.failIfEqual(result, test_path) + def test_it_no___name__(self): + class DummyFrame(object): + f_globals = {} + class DummySys(object): + def _getframe(self, level): + return DummyFrame() + modules = {'__main__':'main'} + dummy_sys = DummySys() + result = self._callFUT(3, sys=dummy_sys) + self.assertEqual(result, 'main') + + class TestCallerPackage(unittest.TestCase): def _callFUT(self, *arg, **kw): from pyramid.path import caller_package -- cgit v1.2.3