summaryrefslogtreecommitdiff
diff options
context:
space:
mode:
authorChris McDonough <chrism@plope.com>2010-12-13 23:28:59 -0500
committerChris McDonough <chrism@plope.com>2010-12-13 23:28:59 -0500
commita56564945ae07da87e5ccbca9c137095c250ced3 (patch)
tree5093c61d901beb5e448e7304a167a454fdd721b3
parentfee38663daccc0130d0c34dbc5a14e67bef2e183 (diff)
downloadpyramid-a56564945ae07da87e5ccbca9c137095c250ced3.tar.gz
pyramid-a56564945ae07da87e5ccbca9c137095c250ced3.tar.bz2
pyramid-a56564945ae07da87e5ccbca9c137095c250ced3.zip
- 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.
-rw-r--r--CHANGES.txt6
-rw-r--r--pyramid/path.py4
-rw-r--r--pyramid/tests/test_path.py16
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