1############################################################################## 2# 3# Copyright (c) 2001, 2002 Zope Foundation and Contributors. 4# All Rights Reserved. 5# 6# This software is subject to the provisions of the Zope Public License, 7# Version 2.1 (ZPL). A copy of the ZPL should accompany this distribution. 8# THIS SOFTWARE IS PROVIDED "AS IS" AND ANY AND ALL EXPRESS OR IMPLIED 9# WARRANTIES ARE DISCLAIMED, INCLUDING, BUT NOT LIMITED TO, THE IMPLIED 10# WARRANTIES OF TITLE, MERCHANTABILITY, AGAINST INFRINGEMENT, AND FITNESS 11# FOR A PARTICULAR PURPOSE. 12# 13############################################################################## 14"""Placeless Test Setup 15""" 16from zope.component import provideHandler 17from zope.component.event import objectEventNotify 18from zope.component.registry import dispatchUtilityRegistrationEvent 19from zope.component.registry import dispatchAdapterRegistrationEvent 20from zope.component.registry import ( 21 dispatchSubscriptionAdapterRegistrationEvent) 22from zope.component.registry import dispatchHandlerRegistrationEvent 23try: 24 from zope.testing.cleanup import addCleanUp 25except ImportError: #pragma NO COVER 26 def addCleanUp(x): 27 pass 28 29events = [] 30def getEvents(event_type=None, filter=None): #pragma NO COVER going aaway 31 r = [] 32 for event in events: 33 if event_type is not None and not event_type.providedBy(event): 34 continue 35 if filter is not None and not filter(event): 36 continue 37 r.append(event) 38 39 return r 40 41def clearEvents(): #pragma NO COVER going aaway 42 del events[:] 43addCleanUp(clearEvents) 44 45class PlacelessSetup: #pragma NO COVER going aaway 46 47 def setUp(self): 48 provideHandler(objectEventNotify) 49 provideHandler(dispatchUtilityRegistrationEvent) 50 provideHandler(dispatchAdapterRegistrationEvent) 51 provideHandler(dispatchSubscriptionAdapterRegistrationEvent) 52 provideHandler(dispatchHandlerRegistrationEvent) 53 provideHandler(events.append, (None,)) 54 55def setUp(test=None): #pragma NO COVER going aaway 56 PlacelessSetup().setUp() 57