Commit 69b34b13 authored by Stefan H. Holek's avatar Stefan H. Holek

Collector #1798, issue 1: ZopeTestCase no longer tries to

install products that were installed by Zope during startup.

Interestingly, I never saw a checkin message for the merge of
Lennart's branch...
parent 1a87da63
...@@ -31,7 +31,7 @@ Zope Changes ...@@ -31,7 +31,7 @@ Zope Changes
- Collector #1803: Fixed InitializeClass for some corner case. - Collector #1803: Fixed InitializeClass for some corner case.
- Collector #1798, issue 1: ZopeTestCase no longer tries to - Collector #1798, issue 1: ZopeTestCase no longer tries to
install products that was installed by Zope during startup. install products that were installed by Zope during startup.
- Collector #1799: Avoid lying about parent's refcount when - Collector #1799: Avoid lying about parent's refcount when
calling back into Python code. calling back into Python code.
......
...@@ -38,9 +38,6 @@ import Folder ...@@ -38,9 +38,6 @@ import Folder
import ZDOM import ZDOM
from FindSupport import FindSupport from FindSupport import FindSupport
# Dictionary of installed products, mainly used by ZopeTestCase.
_installedProducts = {}
class Application(Globals.ApplicationDefaultPermissions, class Application(Globals.ApplicationDefaultPermissions,
ZDOM.Root, Folder.Folder, ZDOM.Root, Folder.Folder,
App.ProductRegistry.ProductRegistry, FindSupport): App.ProductRegistry.ProductRegistry, FindSupport):
...@@ -624,13 +621,7 @@ def install_products(app): ...@@ -624,13 +621,7 @@ def install_products(app):
# together and do a default initialization. # together and do a default initialization.
if done.has_key(product_name): if done.has_key(product_name):
continue continue
# We need to separately track what has been installed now, and
# what has been installed at a whole. This is because install_products
# should always install everything, but only once every time it's
# called. The _installedProducts dictionary is later used by
# ZopeTestCase to not install products twice.
done[product_name]=1 done[product_name]=1
_installedProducts[product_name]=1
install_product(app, product_dir, product_name, meta_types, install_product(app, product_dir, product_name, meta_types,
folder_permissions, raise_exc=debug_mode) folder_permissions, raise_exc=debug_mode)
......
...@@ -99,6 +99,8 @@ import OFS.Application ...@@ -99,6 +99,8 @@ import OFS.Application
import App.ProductContext import App.ProductContext
_write('.') _write('.')
_patched = False
def _apply_patches(): def _apply_patches():
# Avoid expensive product import # Avoid expensive product import
def null_import_products(): pass def null_import_products(): pass
...@@ -116,18 +118,22 @@ def _apply_patches(): ...@@ -116,18 +118,22 @@ def _apply_patches():
def null_register_help(self,directory='',clear=1,title_re=None): pass def null_register_help(self,directory='',clear=1,title_re=None): pass
App.ProductContext.ProductContext.registerHelp = null_register_help App.ProductContext.ProductContext.registerHelp = null_register_help
# Note that we applied the monkey patches
global _patched
_patched = True
# Do not patch a running Zope # Do not patch a running Zope
if not Zope2._began_startup: if not Zope2._began_startup:
_apply_patches() _apply_patches()
# Allow test authors to install Zope products into the test environment. Note # Allow test authors to install Zope products into the test environment. Note
# that installProduct() must be called at module level -- never from tests. # that installProduct() must be called at module level -- never from tests.
from OFS.Application import get_folder_permissions, get_products, \ from OFS.Application import get_folder_permissions, get_products, install_product
install_product, _installedProducts
from OFS.Folder import Folder from OFS.Folder import Folder
import Products import Products
_theApp = Zope2.app() _theApp = Zope2.app()
_installedProducts = {}
def hasProduct(name): def hasProduct(name):
'''Checks if a product can be found along Products.__path__''' '''Checks if a product can be found along Products.__path__'''
...@@ -137,7 +143,7 @@ def installProduct(name, quiet=0): ...@@ -137,7 +143,7 @@ def installProduct(name, quiet=0):
'''Installs a Zope product.''' '''Installs a Zope product.'''
start = time.time() start = time.time()
meta_types = [] meta_types = []
if not _installedProducts.has_key(name): if _patched and not _installedProducts.has_key(name):
for priority, product_name, index, product_dir in get_products(): for priority, product_name, index, product_dir in get_products():
if product_name == name: if product_name == name:
if not quiet: _print('Installing %s ... ' % product_name) if not quiet: _print('Installing %s ... ' % product_name)
......
Unreleased Unreleased
- Functional.publish() would hang if it got a request_method argument other - Functional.publish() would hang if it got a request_method argument other
than GET or HEAD while omitting the stdin argument. than GET or HEAD while omitting the stdin argument.
- installProduct() now becomes a noop if ZopeTestCase did not apply its
patches.
0.9.8 (Zope 2.8 edition) 0.9.8 (Zope 2.8 edition)
- Renamed 'doctest' package to 'zopedoctest' because of name-shadowing - Renamed 'doctest' package to 'zopedoctest' because of name-shadowing
......
...@@ -97,7 +97,8 @@ def setupSiteErrorLog(app=None): ...@@ -97,7 +97,8 @@ def setupSiteErrorLog(app=None):
def importObjectFromFile(container, filename, quiet=0): def importObjectFromFile(container, filename, quiet=0):
'''Imports an object from a (.zexp) file into the given container.''' '''Imports an object from a (.zexp) file into the given container.'''
from ZopeLite import _print from ZopeLite import _print, _patched
quiet = quiet or not _patched
start = time.time() start = time.time()
if not quiet: _print("Importing %s ... " % os.path.basename(filename)) if not quiet: _print("Importing %s ... " % os.path.basename(filename))
container._importObjectFromFile(filename, verify=0) container._importObjectFromFile(filename, verify=0)
......
...@@ -114,7 +114,7 @@ Test Server Error ...@@ -114,7 +114,7 @@ Test Server Error
... GET /test_folder_1_/script?a=2 HTTP/1.1 ... GET /test_folder_1_/script?a=2 HTTP/1.1
... """, handle_errors=False) ... """, handle_errors=False)
HTTP/1.1 500 Internal Server Error HTTP/1.1 500 Internal Server Error
...Content-Type: text/html...exceptions.TypeError... ...Content-Type: text/html...TypeError...
Test Unauthorized Test Unauthorized
......
Markdown is supported
0%
or
You are about to add 0 people to the discussion. Proceed with caution.
Finish editing this message first!
Please register or to comment