Skip to content

Commit

Permalink
Merge 10615d4 into 95c42ef
Browse files Browse the repository at this point in the history
  • Loading branch information
Michael Howitz committed Dec 8, 2018
2 parents 95c42ef + 10615d4 commit 32e1f1e
Show file tree
Hide file tree
Showing 18 changed files with 118 additions and 141 deletions.
17 changes: 14 additions & 3 deletions .travis.yml
@@ -1,13 +1,24 @@
language: python
python:
- 2.7
- 3.3
- 3.4
- 3.5
- 3.6
- pypy
- pypy3
matrix:
include:
- python: "3.7"
dist: xenial
before_install:
- pip install -U pip setuptools
- pip install -U coverage coveralls
install:
- pip install tox-travis
- pip install -U -e .[test]
script:
- tox
- coverage run -m zope.testrunner --test-path=src
after_success:
- coveralls
notifications:
email: false
cache: pip
4 changes: 3 additions & 1 deletion CHANGES.txt
Expand Up @@ -4,7 +4,9 @@ Changelog
4.1.0 (unreleased)
------------------

- Nothing changed yet.
- Add support for Python 3.6, 3.7 and PyPy3.

- Drop support for Python 3.3.


4.0.0 (2016-08-08)
Expand Down
6 changes: 4 additions & 2 deletions setup.py
Expand Up @@ -26,6 +26,7 @@ def read(*rnames):
with open(os.path.join(os.path.dirname(__file__), *rnames)) as f:
return f.read()


setup(
name='zope.app.appsetup',
version='4.1.0.dev0',
Expand Down Expand Up @@ -55,17 +56,18 @@ def read(*rnames):
'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 :: 3.7',
'Programming Language :: Python :: Implementation',
'Programming Language :: Python :: Implementation :: CPython',
'Programming Language :: Python :: Implementation :: PyPy',
'Natural Language :: English',
'Operating System :: OS Independent',
'Topic :: Internet :: WWW/HTTP',
'Framework :: Zope :: 3'],
url='http://pypi.python.org/pypi/zope.app.appsetup',
url='https://github.com/zopefoundation/zope.app.appsetup',
packages=find_packages('src'),
package_dir={'': 'src'},
namespace_packages=['zope', 'zope.app'],
Expand Down
9 changes: 1 addition & 8 deletions src/zope/__init__.py
@@ -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
@@ -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
15 changes: 5 additions & 10 deletions src/zope/app/appsetup/__init__.py
Expand Up @@ -11,14 +11,9 @@
# FOR A PARTICULAR PURPOSE.
#
##############################################################################
"""Zope Application Server setup package
"""Zope Application Server setup package."""
from zope.app.appsetup.appsetup import config, database # noqa: F401

$Id$
"""
__docformat__ = 'restructuredtext'

from zope.app.appsetup.appsetup import config, database

#BBB
from zope.app.appsetup.interfaces import IDatabaseOpenedEvent, DatabaseOpened
from zope.app.appsetup.interfaces import IProcessStartingEvent, ProcessStarting
# BBB
from zope.app.appsetup.interfaces import IDatabaseOpenedEvent, DatabaseOpened # noqa: F401,E501
from zope.app.appsetup.interfaces import IProcessStartingEvent, ProcessStarting # noqa: F401,E501
17 changes: 11 additions & 6 deletions src/zope/app/appsetup/appsetup.py
Expand Up @@ -11,12 +11,7 @@
# FOR A PARTICULAR PURPOSE.
#
##############################################################################
"""Code to initialize the application server
$Id$
"""
__docformat__ = 'restructuredtext'

"""Code to initialize the application server."""
import ZODB.ActivityMonitor
import ZODB.interfaces
import zope.interface
Expand All @@ -26,6 +21,7 @@
from zope.security.management import system_user
import zope.processlifetime


@zope.interface.implementer(IParticipation)
class SystemConfigurationParticipation(object):

Expand All @@ -34,6 +30,8 @@ class SystemConfigurationParticipation(object):


_configured = False


def config(file, features=(), execute=True):
r"""Execute the ZCML configuration file.
Expand Down Expand Up @@ -225,13 +223,19 @@ def multi_database(database_factories):


__config_context = None


def getConfigContext():
return __config_context


__config_source = None


def getConfigSource():
return __config_source


def reset():
global _configured
_configured = False
Expand All @@ -242,6 +246,7 @@ def reset():
global __config_context
__config_context = None


try:
import zope.testing.cleanup
except ImportError:
Expand Down
20 changes: 9 additions & 11 deletions src/zope/app/appsetup/bootstrap.py
Expand Up @@ -34,10 +34,10 @@

_marker = object()


def ensureObject(root_folder, object_name, object_type, object_factory,
asObject=_marker):
"""Check that there's a basic object in the site
manager. If not, add one.
"""Check that there's a basic object in the site manager. If not, add one.
Return the name abdded, if we added an object, otherwise None.
"""
Expand All @@ -46,9 +46,9 @@ def ensureObject(root_folder, object_name, object_type, object_factory,
"removed in Zope 3.6", DeprecationWarning, 2)

package = getSiteManagerDefault(root_folder)
valid_objects = [ name
for name in package
if object_type.providedBy(package[name]) ]
valid_objects = [name
for name in package
if object_type.providedBy(package[name])]
if valid_objects:
return None
name = object_name
Expand All @@ -73,8 +73,7 @@ def ensureUtility(root_folder, interface, utility_type,
if len(utils) == 0:
return addConfigureUtility(
root_folder, interface, utility_type, utility_factory,
name, asObject, **kw
)
name, asObject, **kw)
else:
return None

Expand All @@ -94,7 +93,7 @@ def addConfigureUtility(

def addUtility(root_folder, utility_type, utility_factory,
asObject=_marker, **kw):
""" Add a Utility to the root folder's site manager.
"""Add a Utility to the root folder's site manager.
The utility is added to the default package and activated.
"""
Expand Down Expand Up @@ -125,7 +124,7 @@ def getSiteManagerDefault(root_folder):


def getInformationFromEvent(event):
""" Extracts information from the event
"""Extract information from the event
Return a tuple containing
Expand All @@ -151,7 +150,6 @@ def bootStrapSubscriber(event):
root folder exists and has a site manager. If it exists, nothing else
is changed. If no root folder exists, one is added.
"""

db, connection, root, root_folder = getInformationFromEvent(event)

if root_folder is None:
Expand Down Expand Up @@ -180,7 +178,7 @@ def checkSecurityPolicy(event):
was refactored and now it needs to be included from site.zcml.
"""
if getSecurityPolicy() is ParanoidSecurityPolicy:
logging.getLogger('zope.app.appsetup').warn(
logging.getLogger('zope.app.appsetup').warning(
'Security policy is not configured.\n'
'Please make sure that securitypolicy.zcml is included'
' in site.zcml immediately\n'
Expand Down
4 changes: 2 additions & 2 deletions src/zope/app/appsetup/bootstrap.txt
Expand Up @@ -10,8 +10,8 @@ object. It subscribes to DatabaseOpened events:
>>> from zope.app.appsetup import bootstrap
>>> import zope.processlifetime

>>> from ZODB.tests import util
>>> db = util.DB()
>>> from ZODB.MappingStorage import DB
>>> db = DB()
>>> bootstrap.bootStrapSubscriber(zope.processlifetime.DatabaseOpened(db))

The subscriber makes sure that there is a root folder:
Expand Down
3 changes: 2 additions & 1 deletion src/zope/app/appsetup/debug.py
Expand Up @@ -60,7 +60,8 @@ def main(args=None):
db = loadApplication(args)
if "PYTHONSTARTUP" in os.environ:
startup = os.environ["PYTHONSTARTUP"]
exec(compile(open(startup).read(), startup, 'exec'))
with open(startup) as s:
exec(compile(s.read(), startup, 'exec'))
sys.modules['__main__'].root = db.open().root()[ZopePublication.root_name]
print('The application root is known as `root`.')
os.environ["PYTHONINSPECT"] = "true"
Expand Down
7 changes: 2 additions & 5 deletions src/zope/app/appsetup/errorlog.py
Expand Up @@ -11,10 +11,7 @@
# FOR A PARTICULAR PURPOSE.
#
##############################################################################
"""Bootstrap code for error reporting utility.
$Id: bootstrap.py 70794 2006-10-19 04:29:42Z baijum $
"""
"""Bootstrap code for error reporting utility."""

import transaction

Expand All @@ -23,12 +20,12 @@

from zope.app.appsetup.bootstrap import ensureUtility, getInformationFromEvent


def bootStrapSubscriber(event):
"""Subscriber to the IDataBaseOpenedEvent
Create utility at that time if not yet present
"""

db, connection, root, root_folder = getInformationFromEvent(event)

ensureUtility(root_folder, IErrorReportingUtility, '',
Expand Down
6 changes: 3 additions & 3 deletions src/zope/app/appsetup/interfaces.py
Expand Up @@ -17,11 +17,11 @@
"""
# BBB imports
from zope.processlifetime import IDatabaseOpened
from zope.processlifetime import DatabaseOpened
from zope.processlifetime import DatabaseOpened # noqa: F401
from zope.processlifetime import IDatabaseOpenedWithRoot
from zope.processlifetime import DatabaseOpenedWithRoot
from zope.processlifetime import DatabaseOpenedWithRoot # noqa: F401
from zope.processlifetime import IProcessStarting
from zope.processlifetime import ProcessStarting
from zope.processlifetime import ProcessStarting # noqa: F401

# BBB aliases
IDatabaseOpenedEvent = IDatabaseOpened
Expand Down
7 changes: 1 addition & 6 deletions src/zope/app/appsetup/product.py
@@ -1,8 +1,4 @@
"""Access to product-specific configuration.
"""
__docformat__ = "reStructuredText"

"""Access to product-specific configuration."""
import ZConfig
import os.path

Expand All @@ -15,7 +11,6 @@
pass
else:
zope.testing.cleanup.addCleanUp(_configs.clear)



def getProductConfiguration(name):
Expand Down
13 changes: 4 additions & 9 deletions src/zope/app/appsetup/session.py
Expand Up @@ -11,10 +11,7 @@
# FOR A PARTICULAR PURPOSE.
#
##############################################################################
"""Bootstrap code for sessions.
$Id$
"""
"""Bootstrap code for sessions."""

import transaction

Expand All @@ -24,24 +21,22 @@
from zope.session.http import CookieClientIdManager
from zope.session.session import PersistentSessionDataContainer


def bootStrapSubscriber(event):
"""Subscriber to the IDataBaseOpenedEvent
Create utility at that time if not yet present
"""

db, connection, root, root_folder = getInformationFromEvent(event)

ensureUtility(
root_folder,
IClientIdManager, 'CookieClientIdManager',
CookieClientIdManager,
)
CookieClientIdManager)
ensureUtility(
root_folder,
ISessionDataContainer, 'PersistentSessionDataContainer',
PersistentSessionDataContainer,
)
PersistentSessionDataContainer)

transaction.commit()
connection.close()
12 changes: 6 additions & 6 deletions src/zope/app/appsetup/testlayer.txt
Expand Up @@ -32,18 +32,18 @@ working database::
... root = self.layer.getRootFolder()
... root['object'] = testobject.TestObject()
... transaction.commit()
... self.failUnless('object' in root)
... self.assertIn('object', root)
... def testNoMoreObjectInDB(self):
... root = self.layer.getRootFolder()
... self.failIf('object' in root)
... self.assertNotIn('object', root)
... def testApplicationInDB(self):
... root = self.layer.getRootFolder()
... self.assertEquals(
... self.assertEqual(
... repr(root.__class__), "<class 'zope.site.folder.Folder'>")
... def testDBRegistered(self):
... root = self.layer.getRootFolder()
... db = component.getUtility(IDatabase, name='main')
... self.assertEquals(db, root._p_jar.db())
... self.assertEqual(db, root._p_jar.db())

We define a suite with our test:

Expand Down Expand Up @@ -89,12 +89,12 @@ database but is still isolated from other tests' changes:
... layer = layer
... def test_test1(self):
... root = self.layer.getRootFolder()
... self.assertEquals(1, len(root))
... self.assertEqual(1, len(root))
... root['bar'] = 1
... transaction.commit()
... def test_test2(self):
... root = self.layer.getRootFolder()
... self.assertEquals(1, len(root))
... self.assertEqual(1, len(root))
... root['baz'] = 1
... transaction.commit()

Expand Down

0 comments on commit 32e1f1e

Please sign in to comment.