Skip to content

Commit

Permalink
Python 3 and PyPy support.
Browse files Browse the repository at this point in the history
Modernize project:
- Remove zope.app.zcmlfiles and zope.app.testing deps, among others.
- tox.ini
- .travis.yml uses pip, zope.testrunner and supports caching and
coverage
- Rename .txt -> .rst
  • Loading branch information
jamadden committed Apr 30, 2017
1 parent 9eb6b92 commit c8295a0
Show file tree
Hide file tree
Showing 18 changed files with 248 additions and 95 deletions.
7 changes: 7 additions & 0 deletions .coveragerc
Original file line number Diff line number Diff line change
@@ -0,0 +1,7 @@
[run]
source = src

[report]
exclude_lines =
pragma: no cover
if __name__ == '__main__':
2 changes: 2 additions & 0 deletions .gitignore
Original file line number Diff line number Diff line change
Expand Up @@ -9,3 +9,5 @@ build/
dist/
*.egg-info/
.tox/
htmlcov/
.coverage
27 changes: 22 additions & 5 deletions .travis.yml
Original file line number Diff line number Diff line change
@@ -1,9 +1,26 @@
language: python
sudo: false
python:
- 2.7
install:
- pip install .
- 2.7
- 3.4
- 3.5
- 3.6
- pypy-5.4.1
script:
- python setup.py test -q
- coverage run -m zope.testrunner --test-path=src --auto-color --auto-progress

after_success:
- coveralls
notifications:
email: false
email: false

install:
- pip install -U pip setuptools
- pip install -U coveralls coverage
- pip install -U -e ".[test]"


cache: pip

before_cache:
- rm -f $HOME/.cache/pip/log/debug.log
6 changes: 4 additions & 2 deletions CHANGES.txt → CHANGES.rst
Original file line number Diff line number Diff line change
@@ -1,11 +1,13 @@
CHANGES
=======

3.6.4 (unreleased)
4.0.0 (unreleased)
------------------

- Nothing changed yet.
- Add support for PyPy, and Python 3.4, 3.5 and 3.6.

- Remove test dependency on ``zope.app.testing``,
``zope.app.zcmlfiles`` and many others.

3.6.3 (2011-05-23)
------------------
Expand Down
7 changes: 6 additions & 1 deletion MANIFEST.in
Original file line number Diff line number Diff line change
@@ -1,6 +1,11 @@
include *.py
include *.txt
include *.rst
include buildout.cfg
include tox.ini
include .travis.yml
include .coveragerc

recursive-include src *.pt
recursive-include src *.txt
recursive-include src *.rst
recursive-include src *.zcml
File renamed without changes.
86 changes: 58 additions & 28 deletions setup.py
Original file line number Diff line number Diff line change
Expand Up @@ -22,56 +22,86 @@
from setuptools import setup, find_packages

def read(*rnames):
return open(os.path.join(os.path.dirname(__file__), *rnames)).read()
with open(os.path.join(os.path.dirname(__file__), *rnames)) as f:
return f.read()

version = '3.6.4dev'
version = '4.0.0.dev0'

tests_require = [
'webtest',

'zope.app.appsetup',
'zope.app.basicskin >= 4.0',
'zope.app.pagetemplate',
'zope.app.publication',
'zope.app.wsgi',

'zope.browsermenu',
'zope.browserresource',
'zope.container',
'zope.login',
'zope.password',
'zope.principalregistry',
'zope.publisher',
'zope.securitypolicy',
'zope.site',
'zope.testrunner',
]

setup(name='zope.app.exception',
version=version,
author='Zope Corporation and Contributors',
author_email='zope-dev@zope.org',
description='Zope 3 exception views',
long_description=(
read('README.txt')
read('README.rst')
+ '\n\n' +
'.. contents::'
+ '\n\n' +
read('src', 'zope', 'app', 'exception', 'browser', 'systemerror.txt')
read('src', 'zope', 'app', 'exception', 'browser', 'systemerror.rst')
+ '\n\n' +
read('CHANGES.txt')
read('CHANGES.rst')
),
keywords = "zope3 exception view",
classifiers = [
keywords="zope3 exception view",
classifiers=[
'Development Status :: 5 - Production/Stable',
'Environment :: Web Environment',
'Intended Audience :: Developers',
'License :: OSI Approved :: Zope Public License',
'Programming Language :: Python',
'Programming Language :: Python :: 2',
'Programming Language :: Python :: 2.7',
'Programming Language :: Python :: 3',
'Programming Language :: Python :: 3.3',
'Programming Language :: Python :: 3.4',
'Programming Language :: Python :: 3.5',
'Programming Language :: Python :: 3.6',
'Programming Language :: Python :: Implementation :: CPython',
'Programming Language :: Python :: Implementation :: PyPy',
'Natural Language :: English',
'Operating System :: OS Independent',
'Topic :: Internet :: WWW/HTTP',
'Framework :: Zope3'],
'Framework :: Zope3',
],
url='http://pypi.python.org/pypi/zope.app.exception',
license='ZPL 2.1',
packages=find_packages('src'),
package_dir = {'': 'src'},
package_dir={'': 'src'},
namespace_packages=['zope', 'zope.app'],
extras_require=dict(test=[
'zope.app.testing',
'zope.app.zcmlfiles',
'zope.login',
'zope.password',
'zope.securitypolicy',
]),
install_requires=['setuptools',
'zope.interface',
'zope.publisher >= 3.12',
'zope.authentication',
'zope.browser>=1.2',
'zope.browserpage>=3.11.0',
'zope.component',
'zope.security',
],
include_package_data = True,
zip_safe = False,
)
extras_require={
'test': tests_require,
},
tests_require=tests_require,
install_requires=[
'setuptools',
'zope.interface',
'zope.publisher >= 3.12',
'zope.authentication',
'zope.browser>=1.2',
'zope.browserpage>=3.11.0',
'zope.component',
'zope.security',
],
include_package_data=True,
zip_safe=False,
)
9 changes: 1 addition & 8 deletions src/zope/__init__.py
Original file line number Diff line number Diff line change
@@ -1,8 +1 @@
# this is a namespace package
try:
import pkg_resources
pkg_resources.declare_namespace(__name__)
except ImportError:
import pkgutil
__path__ = pkgutil.extend_path(__path__, __name__)

__import__('pkg_resources').declare_namespace(__name__) # pragma: no cover
9 changes: 1 addition & 8 deletions src/zope/app/__init__.py
Original file line number Diff line number Diff line change
@@ -1,8 +1 @@
# this is a namespace package
try:
import pkg_resources
pkg_resources.declare_namespace(__name__)
except ImportError:
import pkgutil
__path__ = pkgutil.extend_path(__path__, __name__)

__import__('pkg_resources').declare_namespace(__name__) # pragma: no cover
Original file line number Diff line number Diff line change
Expand Up @@ -12,10 +12,10 @@ terse message and that sets the response status.
There is a simple view registered in ``ftesting.zcml`` which raises
``Exception()``:

>>> print http(r"""
>>> print(http(r"""
... GET /error.html HTTP/1.1
... """)
HTTP/1.1 500 Internal Server Error
... """))
HTTP/1.0 500 Internal Server Error
...
A system error occurred.
...
Expand All @@ -26,10 +26,10 @@ view in ``ftesting.zcml``, too, that will raise a component lookup
error. So if we call ``componentlookuperror.html``, we should get the
error message:

>>> print http(r"""
>>> print(http(r"""
... GET /componentlookuperror.html HTTP/1.1
... """)
HTTP/1.1 500 Internal Server Error
... """))
HTTP/1.0 500 Internal Server Error
...
A system error occurred.
...
23 changes: 22 additions & 1 deletion src/zope/app/exception/browser/tests/__init__.py
Original file line number Diff line number Diff line change
@@ -1 +1,22 @@
# empty __init__.py file to make this directory into a package

import unittest

from webtest import TestApp



class BrowserTestCase(unittest.TestCase):

layer = None

def setUp(self):
super(BrowserTestCase, self).setUp()
self._testapp = TestApp(self.layer.make_wsgi_app())

def publish(self, path, basic=None, headers=None, handle_errors=False):
assert basic
self._testapp.authorization = ('Basic', tuple(basic.split(':')))
env = {'wsgi.handleErrors': handle_errors}
response = self._testapp.get(path, extra_environ=env, headers=headers,
expect_errors=handle_errors)
return response
49 changes: 40 additions & 9 deletions src/zope/app/exception/browser/tests/test_error.py
Original file line number Diff line number Diff line change
Expand Up @@ -13,10 +13,12 @@
##############################################################################
"""Functional tests for NotFoundError
"""
import doctest
import unittest
from zope.app.testing import functional
from zope.component.interfaces import ComponentLookupError
from zope.app.exception.testing import AppExceptionLayer
from zope.app.exception.browser.tests import BrowserTestCase
from zope.app.wsgi.testlayer import http

class RaiseError(object):

Expand All @@ -30,22 +32,51 @@ def __call__(self):
raise ComponentLookupError()


class TestComponentLookupError(functional.BrowserTestCase):
class TestComponentLookupError(BrowserTestCase):

layer = AppExceptionLayer

def testComponentLookupError(self):
response = self.publish('/foobar', basic='mgr:mgrpw',
handle_errors=True)
self.assertEqual(response.getStatus(), 404)
body = response.getBody()
self.assert_(
'The page that you are trying to access is not available' in body)
self.assertEqual(response.status_int, 404)
body = response.unicode_normal_body
self.assertIn(
'The page that you are trying to access is not available', body)

class TestMisc(unittest.TestCase):

def test_user(self):
from zope.app.exception.browser import user
view = user.UserErrorView()
view.context = self
self.assertEqual(view.title(), self.__class__.__name__)

def test_interfaces(self):
from zope.app.exception import interfaces
from zope.browser.interfaces import ISystemErrorView
self.assertEqual(interfaces.ISystemErrorView, ISystemErrorView)

def test_suite():
TestComponentLookupError.layer = AppExceptionLayer
systemerror = functional.FunctionalDocFileSuite('../systemerror.txt')

def _http(query_str, *args, **kwargs):
wsgi_app = AppExceptionLayer.make_wsgi_app()
# Strip leading \n
query_str = query_str.lstrip()
kwargs.setdefault('handle_errors', True)
if not isinstance(query_str, bytes):
query_str = query_str.encode("utf-8")
return http(wsgi_app, query_str, *args, **kwargs)


systemerror = doctest.DocFileSuite(
'../systemerror.rst',
optionflags=doctest.ELLIPSIS,
globs={'http': _http})

systemerror.layer = AppExceptionLayer
return unittest.TestSuite((
unittest.makeSuite(TestComponentLookupError),
unittest.defaultTestLoader.loadTestsFromName(__name__),
systemerror,
))
))
Loading

0 comments on commit c8295a0

Please sign in to comment.