Skip to content

Commit

Permalink
Merge branch 'master' of github.com:Pylons/pyramid
Browse files Browse the repository at this point in the history
  • Loading branch information
mcdonc committed May 12, 2014
2 parents 50d2b85 + 8b8b05f commit a978083
Show file tree
Hide file tree
Showing 8 changed files with 36 additions and 7 deletions.
8 changes: 8 additions & 0 deletions CHANGES.txt
Expand Up @@ -12,6 +12,11 @@ Bug Fixes
add_route_predicate for example can not take a string and turn it into the
actual callable function.

- Fix ``pyramid.testing.setUp`` to return a ``Configurator`` with a proper
package. Previously it was not possible to do package-relative includes
using the returned ``Configurator`` during testing. There is now a
``package`` argument that can override this behavior as well.

Docs
----

Expand All @@ -30,6 +35,9 @@ Scaffolds
templates to have links to correctly versioned documentation and reflect
which pyramid was used to generate the scaffold.

- Removed non-ascii copyright symbol from templates, as this was
causing the scaffolds to fail for project generation.

1.5 (2014-04-08)
================

Expand Down
2 changes: 2 additions & 0 deletions CONTRIBUTORS.txt
Expand Up @@ -230,3 +230,5 @@ Contributors
- Antti Haapala, 2013/11/15

- Amit Mane, 2014/01/23

- Fenton Travers, 2014/05/06
2 changes: 1 addition & 1 deletion docs/narr/MyProject/myproject/templates/mytemplate.pt
Expand Up @@ -50,7 +50,7 @@
</div>
<div class="row">
<div class="copyright">
Copyright © Pylons Project
Copyright &copy; Pylons Project
</div>
</div>
</div>
Expand Down
Expand Up @@ -50,7 +50,7 @@
</div>
<div class="row">
<div class="copyright">
Copyright © Pylons Project
Copyright &copy; Pylons Project
</div>
</div>
</div>
Expand Down
Expand Up @@ -50,7 +50,7 @@
</div>
<div class="row">
<div class="copyright">
Copyright © Pylons Project
Copyright &copy; Pylons Project
</div>
</div>
</div>
Expand Down
Expand Up @@ -50,7 +50,7 @@
</div>
<div class="row">
<div class="copyright">
Copyright © Pylons Project
Copyright &copy; Pylons Project
</div>
</div>
</div>
Expand Down
20 changes: 17 additions & 3 deletions pyramid/testing.py
Expand Up @@ -21,6 +21,7 @@

from pyramid.config import Configurator
from pyramid.decorator import reify
from pyramid.path import caller_package
from pyramid.response import Response
from pyramid.registry import Registry

Expand Down Expand Up @@ -388,7 +389,7 @@ def response(self):
have_zca = True

def setUp(registry=None, request=None, hook_zca=True, autocommit=True,
settings=None):
settings=None, package=None):
"""
Set :app:`Pyramid` registry and request thread locals for the
duration of a single unit test.
Expand Down Expand Up @@ -432,9 +433,15 @@ def setUp(registry=None, request=None, hook_zca=True, autocommit=True,
:mod:`zope.component` package cannot be imported, or if
``hook_zca`` is ``False``, the hook will not be set.
If ``settings`` is not None, it must be a dictionary representing the
If ``settings`` is not ``None``, it must be a dictionary representing the
values passed to a Configurator as its ``settings=`` argument.
If ``package`` is ``None`` it will be set to the caller's package. The
``package`` setting in the :class:`pyramid.config.Configurator` will
affect any relative imports made via
:meth:`pyramid.config.Configurator.include` or
:meth:`pyramid.config.Configurator.maybe_dotted`.
This function returns an instance of the
:class:`pyramid.config.Configurator` class, which can be
used for further configuration to set up an environment suitable
Expand All @@ -447,7 +454,10 @@ def setUp(registry=None, request=None, hook_zca=True, autocommit=True,
manager.clear()
if registry is None:
registry = Registry('testing')
config = Configurator(registry=registry, autocommit=autocommit)
if package is None:
package = caller_package()
config = Configurator(registry=registry, autocommit=autocommit,
package=package)
if settings is None:
settings = {}
if getattr(registry, 'settings', None) is None:
Expand Down Expand Up @@ -505,6 +515,10 @@ def tearDown(unhook_zca=True):

def cleanUp(*arg, **kw):
""" An alias for :func:`pyramid.testing.setUp`. """
package = kw.get('package', None)
if package is None:
package = caller_package()
kw['package'] = package
return setUp(*arg, **kw)

class DummyRendererFactory(object):
Expand Down
5 changes: 5 additions & 0 deletions pyramid/tests/test_testing.py
Expand Up @@ -347,6 +347,7 @@ def test_it_defaults(self):
self.assertEqual(config.registry, current['registry'])
self.assertEqual(current['registry'].__class__, Registry)
self.assertEqual(current['request'], None)
self.assertEqual(config.package.__name__, 'pyramid.tests')
self._assertSMHook(get_current_registry)

def test_it_with_registry(self):
Expand All @@ -364,6 +365,10 @@ def test_it_with_request(self):
current = manager.get()
self.assertEqual(current['request'], request)

def test_it_with_package(self):
config = self._callFUT(package='pyramid')
self.assertEqual(config.package.__name__, 'pyramid')

def test_it_with_hook_zca_false(self):
from pyramid.registry import Registry
registry = Registry()
Expand Down

0 comments on commit a978083

Please sign in to comment.