Skip to content

Commit

Permalink
- Support an onerror keyword argument to
Browse files Browse the repository at this point in the history
  ``pyramid.config.Configurator.scan()``.  This onerror keyword argument is
  passed to ``venusian.Scanner.scan()`` to influence error behavior when
  an exception is raised during scanning.

- Pyramid now requires Venusian 1.0a1 or better to support the ``onerror``
  keyword argument to ``pyramid.config.Configurator.scan``.

- Move test fixtures around so test_config tests are not looking "up"
  for fixtures.
  • Loading branch information
mcdonc committed Aug 31, 2011
1 parent c0e6e69 commit 1aeae35
Show file tree
Hide file tree
Showing 28 changed files with 242 additions and 130 deletions.
17 changes: 17 additions & 0 deletions CHANGES.txt
Original file line number Diff line number Diff line change
@@ -1,3 +1,20 @@
Next release
============

Features
--------

- Support an ``onerror`` keyword argument to
``pyramid.config.Configurator.scan()``. This onerror keyword argument is
passed to ``venusian.Scanner.scan()`` to influence error behavior when
an exception is raised during scanning.

Dependencies
------------

- Pyramid now requires Venusian 1.0a1 or better to support the ``onerror``
keyword argument to ``pyramid.config.Configurator.scan``.

1.2a3 (2011-08-29)
==================

Expand Down
2 changes: 0 additions & 2 deletions TODO.txt
Original file line number Diff line number Diff line change
Expand Up @@ -13,8 +13,6 @@ Should-Have
Nice-to-Have
------------

- Expose ``onerror`` callback to venusian scan (requires venusian >=1.0a1).

- Add a default-view-config-params decorator that can be applied to a class
which names defaults for method-based view_config decorator options.

Expand Down
7 changes: 7 additions & 0 deletions docs/whatsnew-1.2.rst
Original file line number Diff line number Diff line change
Expand Up @@ -149,6 +149,11 @@ Minor Feature Additions
when the ``request.matchdict`` has a value inside it named ``action`` with
a value of ``edit``.

- Support an ``onerror`` keyword argument to
:meth:`pyramid.config.Configurator.scan``. This argument is passed to
:meth:`venusian.Scanner.scan` to influence error behavior when an exception
is raised during scanning.

Deprecations
------------

Expand Down Expand Up @@ -254,3 +259,5 @@ Dependency Changes
- Pyramid now relies on PasteScript >= 1.7.4. This version contains a
feature important for allowing flexible logging configuration.

- Pyramid now requires Venusian 1.0a1 or better to support the ``onerror``
keyword argument to :meth:`pyramid.config.Configurator.scan`.
17 changes: 12 additions & 5 deletions pyramid/config/__init__.py
Original file line number Diff line number Diff line change
Expand Up @@ -716,7 +716,7 @@ def end(self):
return self.manager.pop()

# this is *not* an action method (uses caller_package)
def scan(self, package=None, categories=None, **kw):
def scan(self, package=None, categories=None, onerror=None, **kw):
"""Scan a Python package and any of its subpackages for objects
marked with :term:`configuration decoration` such as
:class:`pyramid.view.view_config`. Any decorated object found will
Expand All @@ -737,6 +737,13 @@ def scan(self, package=None, categories=None, **kw):
documentation for more information about limiting a scan by using an
explicit set of categories.
The ``onerror`` argument, if provided, should be a Venusian
``onerror`` callback function. The onerror function is passed to
:meth:`venusian.Scanner.scan` to influence error behavior when an
exception is raised during the scanning process. See the
:term:`Venusian` documentation for more information about ``onerror``
callbacks.
To perform a ``scan``, Pyramid creates a Venusian ``Scanner`` object.
The ``kw`` argument represents a set of keyword arguments to pass to
the Venusian ``Scanner`` object's constructor. See the
Expand All @@ -754,11 +761,11 @@ def scan(self, package=None, categories=None, **kw):
if package is None: # pragma: no cover
package = caller_package()

scankw = {'config':self}
scankw.update(kw)
ctorkw = {'config':self}
ctorkw.update(kw)

scanner = self.venusian.Scanner(**scankw)
scanner.scan(package, categories=categories)
scanner = self.venusian.Scanner(**ctorkw)
scanner.scan(package, categories=categories, onerror=onerror)

def make_wsgi_app(self):
""" Commits any pending configuration statements, sends a
Expand Down
3 changes: 3 additions & 0 deletions pyramid/tests/test_config/files/minimal.pt
Original file line number Diff line number Diff line change
@@ -0,0 +1,3 @@
<div xmlns="http://www.w3.org/1999/xhtml"
xmlns:tal="http://xml.zope.org/namespaces/tal">
</div>
3 changes: 3 additions & 0 deletions pyramid/tests/test_config/path/scanerror/__init__.py
Original file line number Diff line number Diff line change
@@ -0,0 +1,3 @@
# scan error package


Original file line number Diff line number Diff line change
@@ -0,0 +1 @@
import wont.exist
2 changes: 2 additions & 0 deletions pyramid/tests/test_config/pkgs/__init__.py
Original file line number Diff line number Diff line change
@@ -0,0 +1,2 @@
# package

12 changes: 12 additions & 0 deletions pyramid/tests/test_config/pkgs/asset/__init__.py
Original file line number Diff line number Diff line change
@@ -0,0 +1,12 @@
def includeme(config):
config.add_view('.views.fixture_view')
config.add_view('.views.exception_view', context=RuntimeError)
config.add_view('.views.protected_view', name='protected.html')
config.add_view('.views.erroneous_view', name='error.html')
config.add_view('.views.fixture_view', name='dummyskin.html',
request_type='.views.IDummy')
from models import fixture, IFixture
config.registry.registerUtility(fixture, IFixture)
config.add_view('.views.fixture_view', name='another.html')


8 changes: 8 additions & 0 deletions pyramid/tests/test_config/pkgs/asset/models.py
Original file line number Diff line number Diff line change
@@ -0,0 +1,8 @@
from zope.interface import Interface

class IFixture(Interface):
pass

def fixture():
""" """

Original file line number Diff line number Diff line change
@@ -0,0 +1 @@
#package
Original file line number Diff line number Diff line change
@@ -0,0 +1,2 @@
<html>
</html>
6 changes: 6 additions & 0 deletions pyramid/tests/test_config/pkgs/asset/templates/fixture.pt
Original file line number Diff line number Diff line change
@@ -0,0 +1,6 @@
<html xmlns="http://www.w3.org/1999/xhtml"
xmlns:tal="http://xml.zope.org/namespaces/tal">
<head></head>
<body>
</body>
</html>
22 changes: 22 additions & 0 deletions pyramid/tests/test_config/pkgs/asset/views.py
Original file line number Diff line number Diff line change
@@ -0,0 +1,22 @@
from zope.interface import Interface
from webob import Response
from pyramid.httpexceptions import HTTPForbidden

def fixture_view(context, request):
""" """
return Response('fixture')

def erroneous_view(context, request):
""" """
raise RuntimeError()

def exception_view(context, request):
""" """
return Response('supressed')

def protected_view(context, request):
""" """
raise HTTPForbidden()

class IDummy(Interface):
pass
File renamed without changes.
File renamed without changes.
File renamed without changes.
File renamed without changes.
File renamed without changes.
File renamed without changes.
16 changes: 8 additions & 8 deletions pyramid/tests/test_config/test_assets.py
Original file line number Diff line number Diff line change
Expand Up @@ -61,7 +61,7 @@ def test_has_resource_no_overrides(self):

def test_resource_isdir_no_overrides(self):
file_resource_name = 'test_assets.py'
directory_resource_name = 'fixtures'
directory_resource_name = 'files'
import pyramid.tests.test_config
provider = self._makeOne(pyramid.tests.test_config)
result = provider.resource_isdir(file_resource_name)
Expand All @@ -70,7 +70,7 @@ def test_resource_isdir_no_overrides(self):
self.assertEqual(result, True)

def test_resource_listdir_no_overrides(self):
resource_name = 'fixtures'
resource_name = 'files'
import pyramid.tests.test_config
provider = self._makeOne(pyramid.tests.test_config)
result = provider.resource_listdir(resource_name)
Expand Down Expand Up @@ -124,7 +124,7 @@ def test_has_resource_override_returns_None(self):
def test_resource_isdir_override_returns_None(self):
overrides = DummyOverrides(None)
self._registerOverrides(overrides)
resource_name = 'fixtures'
resource_name = 'files'
import pyramid.tests.test_config
provider = self._makeOne(pyramid.tests.test_config)
result = provider.resource_isdir(resource_name)
Expand All @@ -133,7 +133,7 @@ def test_resource_isdir_override_returns_None(self):
def test_resource_listdir_override_returns_None(self):
overrides = DummyOverrides(None)
self._registerOverrides(overrides)
resource_name = 'fixtures'
resource_name = 'files'
import pyramid.tests.test_config
provider = self._makeOne(pyramid.tests.test_config)
result = provider.resource_listdir(resource_name)
Expand Down Expand Up @@ -176,15 +176,15 @@ def test_resource_isdir_override_returns_False(self):
import pyramid.tests.test_config
self._registerOverrides(overrides)
provider = self._makeOne(pyramid.tests.test_config)
result = provider.resource_isdir('fixtures')
result = provider.resource_isdir('files')
self.assertEqual(result, False)

def test_resource_listdir_override_returns_values(self):
overrides = DummyOverrides(['a'])
import pyramid.tests.test_config
self._registerOverrides(overrides)
provider = self._makeOne(pyramid.tests.test_config)
result = provider.resource_listdir('fixtures')
result = provider.resource_listdir('files')
self.assertEqual(result, ['a'])

class TestPackageOverrides(unittest.TestCase):
Expand Down Expand Up @@ -351,7 +351,7 @@ def test_isdir_false(self):

def test_isdir_true(self):
overrides = [ DummyOverride(
('pyramid.tests.test_config', 'fixtures'))]
('pyramid.tests.test_config', 'files'))]
package = DummyPackage('package')
po = self._makeOne(package)
po.overrides= overrides
Expand All @@ -367,7 +367,7 @@ def test_isdir_doesnt_exist(self):

def test_listdir(self):
overrides = [ DummyOverride(
('pyramid.tests.test_config', 'fixtures'))]
('pyramid.tests.test_config', 'files'))]
package = DummyPackage('package')
po = self._makeOne(package)
po.overrides= overrides
Expand Down
Loading

0 comments on commit 1aeae35

Please sign in to comment.