Skip to content

Commit

Permalink
Lint the code.
Browse files Browse the repository at this point in the history
Add support for Python 3.8 and 3.9.
Make tests compatible with ``zope.component >= 5``.
  • Loading branch information
Michael Howitz committed Apr 7, 2021
1 parent 72dd577 commit befbc12
Show file tree
Hide file tree
Showing 10 changed files with 59 additions and 44 deletions.
4 changes: 3 additions & 1 deletion CHANGES.rst
Original file line number Diff line number Diff line change
Expand Up @@ -5,7 +5,9 @@
2.2.1 (unreleased)
==================

- Add support for Python 3.8.
- Add support for Python 3.8 and 3.9.

- Make tests compatible with ``zope.component >= 5``.

- Drop support for Python 3.4.

Expand Down
5 changes: 4 additions & 1 deletion setup.py
Original file line number Diff line number Diff line change
Expand Up @@ -16,10 +16,12 @@
import os
from setuptools import setup, find_packages


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


tests_require = [
'zope.app.appsetup',
'zope.app.authentication',
Expand Down Expand Up @@ -64,7 +66,7 @@ def read(*rnames):
read('src', 'z3c', 'baseregistry', 'README.rst')
+ '\n\n' +
read('CHANGES.rst')
),
),
license="ZPL 2.1",
keywords="zope3 z3c component global registry baseregistry",
classifiers=[
Expand All @@ -80,6 +82,7 @@ def read(*rnames):
'Programming Language :: Python :: 3.6',
'Programming Language :: Python :: 3.7',
'Programming Language :: Python :: 3.8',
'Programming Language :: Python :: 3.9',
'Programming Language :: Python :: Implementation :: CPython',
'Programming Language :: Python :: Implementation :: PyPy',
'Natural Language :: English',
Expand Down
2 changes: 1 addition & 1 deletion src/z3c/__init__.py
Original file line number Diff line number Diff line change
@@ -1 +1 @@
__import__('pkg_resources').declare_namespace(__name__) # pragma: no cover
__import__('pkg_resources').declare_namespace(__name__) # pragma: no cover
2 changes: 2 additions & 0 deletions src/z3c/baseregistry/baseregistry.py
Original file line number Diff line number Diff line change
Expand Up @@ -18,9 +18,11 @@
from zope.component import globalregistry
from zope.interface.interfaces import IComponents


def BC(components, name):
return components.getUtility(IComponents, name)


class BaseComponents(globalregistry.BaseGlobalComponents):
"""An ``IComponents`` implementation that serves as base for other
components."""
Expand Down
1 change: 1 addition & 0 deletions src/z3c/baseregistry/browser/base.py
Original file line number Diff line number Diff line change
Expand Up @@ -59,6 +59,7 @@ def __init__(self, context):

super(BaseComponentsVocabulary, self).__init__(terms)


class IComponentsBases(zope.interface.Interface):
"""An interface describing the bases API of the IComponents object."""

Expand Down
2 changes: 1 addition & 1 deletion src/z3c/baseregistry/browser/ftesting.zcml
Original file line number Diff line number Diff line change
Expand Up @@ -189,7 +189,7 @@

<utility
component=".tests.custom"
provides="zope.component.interfaces.IComponents"
provides="zope.interface.interfaces.IComponents"
name="custom" />

<utility component=".tests.example1" />
Expand Down
15 changes: 12 additions & 3 deletions src/z3c/baseregistry/browser/tests.py
Original file line number Diff line number Diff line change
Expand Up @@ -41,13 +41,16 @@
class IExample(zope.interface.Interface):
name = zope.interface.Attribute('Name of Example')


@zope.interface.implementer(IExample)
class Example(object):

def __init__(self, name):
self.name = name

def __repr__(self):
return '<%s %r>' %(self.__class__.__name__, self.name)
return '<%s %r>' % (self.__class__.__name__, self.name)


example1 = Example('example1')
example2 = Example('example2')
Expand All @@ -61,7 +64,7 @@ def addBasesSelection(browser, bases):
from zope.testbrowser.browser import ListControl

form = browser.getForm('zc.page.browser_form')
webtest_form = form._form # XXX: Private API
webtest_form = form._form # XXX: Private API

# Create the select tag
webtest_select = MultipleSelect(webtest_form, None,
Expand All @@ -83,6 +86,7 @@ def addBasesSelection(browser, bases):
select = ListControl(webtest_select, form, 'select', browser)
form.controls.append(select)


@implementer(IBrowserPublisher)
class ManagementViewSelector(BrowserView):
"""View that selects the first available management view.
Expand All @@ -103,20 +107,24 @@ def __call__(self):
if not redirect_url.lower().startswith(('../', 'javascript:', '++')):
self.request.response.redirect(redirect_url)
return u''
raise AssertionError("Should not get here") # pragma: no cover
raise AssertionError("Should not get here") # pragma: no cover


class LoginLogout(object):
# Dummy implementation of zope.app.security.browser.auth.LoginLogout

def __call__(self):
return None


class _Z3CRegistryLayer(TestBrowserLayer,
BrowserLayer):
pass


Z3CRegistryLayer = _Z3CRegistryLayer(z3c_browser)


def test_suite():

readme = doctest.DocFileSuite(
Expand All @@ -135,5 +143,6 @@ def test_suite():
suite = unittest.TestSuite((readme,))
return suite


if __name__ == '__main__':
unittest.main(defaultTest='test_suite')
35 changes: 18 additions & 17 deletions src/z3c/baseregistry/tests/test_zcml.py
Original file line number Diff line number Diff line change
Expand Up @@ -16,44 +16,45 @@

from z3c.baseregistry import zcml


class TestActionsProxy(unittest.TestCase):

def _makeOne(self, l=None):
l = l or []
return l, zcml.ActionsProxy(l, self)
def _makeOne(self, list_=None):
list_ = list_ or []
return list_, zcml.ActionsProxy(list_, self)

def test_set_decorates(self):
l, proxy = self._makeOne(['abc'])
list_, proxy = self._makeOne(['abc'])
proxy[0] = {'discriminator': 'foo'}
self.assertEqual([{'discriminator': (self, 'foo')}], l)
self.assertEqual([{'discriminator': (self, 'foo')}], list_)

def test_slice_decorates(self):
l, proxy = self._makeOne(['abc'])
list_, proxy = self._makeOne(['abc'])
proxy[:] = [{'discriminator': 'foo'}]
self.assertEqual([{'discriminator': (self, 'foo')}], l)
self.assertEqual([{'discriminator': (self, 'foo')}], list_)

def test_iadd_decorates(self):
l, proxy = self._makeOne()
list_, proxy = self._makeOne()
proxy += [{'discriminator': 'foo'}]
self.assertEqual([{'discriminator': (self, 'foo')}], l)
self.assertEqual([{'discriminator': (self, 'foo')}], list_)

def test_insert_decorates(self):
l, proxy = self._makeOne(['abc'])
list_, proxy = self._makeOne(['abc'])
proxy.insert(0, {'discriminator': 'foo'})
self.assertEqual([{'discriminator': (self, 'foo')}, 'abc'], l)
self.assertEqual([{'discriminator': (self, 'foo')}, 'abc'], list_)

def test_extend_decotares(self):
l, proxy = self._makeOne(['abc'])
list_, proxy = self._makeOne(['abc'])
proxy.extend(({'discriminator': 'foo'},))
self.assertEqual(['abc', {'discriminator': (self, 'foo')}], l)
self.assertEqual(['abc', {'discriminator': (self, 'foo')}], list_)

def test_proxy(self):
l, proxy = self._makeOne()
self.assertEqual(l.index, proxy.index)
list_, proxy = self._makeOne()
self.assertEqual(list_.index, proxy.index)

def test_len(self):
l, proxy = self._makeOne(['abc'])
self.assertEqual(len(l), len(proxy))
list_, proxy = self._makeOne(['abc'])
self.assertEqual(len(list_), len(proxy))
self.assertEqual(1, len(proxy))


Expand Down
29 changes: 12 additions & 17 deletions src/z3c/baseregistry/tests/testdoc.py
Original file line number Diff line number Diff line change
Expand Up @@ -11,37 +11,32 @@
# FOR A PARTICULAR PURPOSE.
#
##############################################################################
"""Base Components test setup
"""

__docformat__ = "reStructuredText"
"""Base Components test setup."""
import doctest
import unittest
from zope.testing import renormalizing
from zope.testing.cleanup import CleanUp
from zope.component.testing import tearDown
from zope.testing import module


def setUp(test):
CleanUp().setUp()
module.setUp(test, name='README')


def tearDown(test):
module.tearDown(test, name='README')
CleanUp().tearDown()


def test_suite():
return unittest.TestSuite((
doctest.DocFileSuite(
'../README.rst',
setUp=setUp, tearDown=tearDown,
optionflags=(doctest.NORMALIZE_WHITESPACE
| doctest.ELLIPSIS
| renormalizing.IGNORE_EXCEPTION_MODULE_IN_PYTHON2),
checker=renormalizing.RENormalizing(),
),
doctest.DocFileSuite(
'../README.rst',
setUp=setUp, tearDown=tearDown,
optionflags=(doctest.NORMALIZE_WHITESPACE
| doctest.ELLIPSIS
| renormalizing.IGNORE_EXCEPTION_MODULE_IN_PYTHON2),
checker=renormalizing.RENormalizing(),
),
))

if __name__ == '__main__':
unittest.main(defaultTest='test_suite')
8 changes: 5 additions & 3 deletions src/z3c/baseregistry/zcml.py
Original file line number Diff line number Diff line change
Expand Up @@ -98,19 +98,21 @@ def __init__(self, sm):
def getSiteManager(self):
return self.sm


def setActiveRegistry(context, registry):
context.original = zope.component.hooks.getSite()
fakeSite = FakeBaseRegistrySite(registry)
zope.component.hooks.setSite(fakeSite)


def resetOriginalRegistry(context):
zope.component.hooks.setSite(context.original)


class RegisterIn(zope.configuration.config.GroupingContextDecorator):

# Marker that this directive has been used in the path
registryChanged=True
registryChanged = True

# Storage for the original site
original = None
Expand All @@ -129,11 +131,11 @@ def before(self):
discriminator=None,
callable=setActiveRegistry,
args=(self, self.registry)
)
)

def after(self):
self.context.action(
discriminator=None,
callable=resetOriginalRegistry,
args=(self,)
)
)

0 comments on commit befbc12

Please sign in to comment.