o ,WX@sddlZddlmZmZzddlmZWn ey!ddZYnwddlmZddl m Z ddl m Z m Z Gd d d eZGd d d eZGd ddeZdS)N) xmlconfigconfigcleanUpcCdSNrrr:/usr/lib/python3/dist-packages/zope/component/testlayer.pyrr)provideHandler)setHooks)events clearEventsc@s>eZdZdZdZdddZddZdd Zd d Zd d Z dS) LayerBaseaSane layer base class. zope.testing implements an advanced mechanism so that layer setUp, tearDown, testSetUp and testTearDown code gets called in the right order. These methods are supposed to be @classmethods and should not use super() as the test runner is supposed to take care of that. In practice, this mechanism turns out not to be useful and overcomplicated. It becomes difficult to pass information into layers (such as a ZCML file to load), because the only way to pass in information is to subclass, and subclassing these layers leads to a range of interactions that is hard to reason about. We'd rather just use Python and the super mechanism, as we know how to reason about that. This base class is a hack to make this possible. The hack requires us to set __bases__, __module__ and __name__. This fools zope.testing into thinking that this layer instance is a class it can work with. It'd be better if zope.testing just called a minimal API and didn't try to be fancy. Fancy layer inheritance mechanisms can then be implemented elsewhere if people want to. But unfortunately it does implement a fancy mechanism and we need to fool it. rNcCs(|dur|jj}||_|j|_||_dSr) __class____name__ __module__package)selfrnamerrr __init__;s  zLayerBase.__init__cCrrrrrrr setUpBr zLayerBase.setUpcCrrrrrrr tearDownEr zLayerBase.tearDowncCrrrrrrr testSetUpHr zLayerBase.testSetUpcCrrrrrrr testTearDownKr zLayerBase.testTearDownr) rr __qualname____doc__ __bases__rrrrrrrrr rs  rcsBeZdZdZd fdd ZddZddZd d Zd d ZZ S) ZCMLLayerBasez%Base class to load up some ZCML. Ncs tt||||p g|_dSr)superrrfeatures)rrrr!rrr rQszZCMLLayerBase.__init__cCsJtt}t||jD]}||q|||_t t j ddS)Nr) r rConfigurationMachinerregisterCommonDirectivesr!provideFeature _load_zcmlcontextr r append)rr'featurerrr rUs    zZCMLLayerBase.setUpcC tdSr)rrrrr r^ zZCMLLayerBase.testTearDowncCr*rrrrrr rar+zZCMLLayerBase.tearDowncCstr)NotImplementedErrorrr'rrr r&dr zZCMLLayerBase._load_zcml)NN) rrrrrrrrr& __classcell__rrr"r rNs rcs.eZdZdZ  dfdd ZddZZS) ZCMLFileLayera8This layer can be used to run tests with a ZCML file loaded. The ZCML file is assumed to include sufficient (meta)configuration so that it can be interpreted itself. I.e. to create a ZCMLLayer based on another ZCMLLayer's ZCML, just use a ZCML include statement in your own ZCML to load it. ftesting.zcmlNcs2tt||||tjtj|j||_dSr) r r/rospathjoindirname__file__ zcml_file)rrr6rr!r"rr ros zZCMLFileLayer.__init__cCstj|j|j|ddS)NT)rr'execute)rfiler6rr-rrr r&uszZCMLFileLayer._load_zcml)r0NN)rrrrrr&r.rrr"r r/gs r/)r1zope.configurationrrzope.testing.cleanupr ImportErrorzope.componentr zope.component.hooksr zope.component.eventtestingr robjectrrr/rrrr s    1