3
,WX @ s d dl Z d dlmZmZ yd dlmZ W n ek
rD dd ZY nX d dlmZ d dl m
Z
d dlmZm
Z
G d d
d
eZG dd deZG d
d deZdS ) N) xmlconfigconfig)cleanUpc C s d S )N r r r /usr/lib/python3.6/testlayer.pyr s r )provideHandler)setHooks)eventsclearEventsc @ s> e Zd ZdZf Zd
ddZdd Zdd Zd d
Zdd Z dS ) LayerBasea Sane 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.
Nc C s( |d kr| j j}|| _|j| _|| _d S )N) __class____name__
__module__package)selfr namer r r __init__; s
zLayerBase.__init__c C s d S )Nr )r r r r setUpB s zLayerBase.setUpc C s d S )Nr )r r r r tearDownE s zLayerBase.tearDownc C s d S )Nr )r r r r testSetUpH s zLayerBase.testSetUpc C s d S )Nr )r r r r testTearDownK s zLayerBase.testTearDown)N)
r
r __qualname____doc__ __bases__r r r r r r r r r r s
r c sB e Zd ZdZd
fdd Zdd Zdd Zd d
Zdd Z Z S )
ZCMLLayerBasez%Base class to load up some ZCML.
Nc s t t| j|| |pg | _d S )N)superr r features)r r r r )r r r r Q s zZCMLLayerBase.__init__c C sN t tj }tj| x| jD ]}|j| q W | j|| _t t
jd d S )N)N)r r ZConfigurationMachiner ZregisterCommonDirectivesr ZprovideFeature
_load_zcmlcontextr r append)r r Zfeaturer r r r U s
zZCMLLayerBase.setUpc C s
t d S )N)r
)r r r r r ^ s zZCMLLayerBase.testTearDownc C s
t d S )N)r )r r r r r a s zZCMLLayerBase.tearDownc C s t d S )N)NotImplementedError)r r r r r r d s zZCMLLayerBase._load_zcml)NN)
r
r r r r r r r r
__classcell__r r )r r r N s r c s* e Zd ZdZd fdd Zdd Z ZS )
ZCMLFileLayera8 This 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.zcmlNc s2 t t| j||| tjjtjj|j|| _d S )N) r r" r ospathjoindirname__file__ zcml_file)r r r) r r )r r r r o s zZCMLFileLayer.__init__c C s t j| j| j|ddS )NT)r r Zexecute)r filer) r )r r r r r r u s zZCMLFileLayer._load_zcml)r# NN)r
r r r r r r! r r )r r r" g s r" )r$ Zzope.configurationr r Zzope.testing.cleanupr ImportErrorZzope.componentr Zzope.component.hooksr Zzope.component.eventtestingr r
objectr r r" r r r r