[Zope-Coders] If 'import Zope' is bad then...
Evan Simpson
evan@zope.com
Wed, 23 Jan 2002 11:37:12 -0500
Shane Hathaway wrote:
> Well, it's becoming apparent that unit tests for a lot of Zope products
> really need to use "import Zope". The CMF tests need to be cleaned up,
> but you may find that not all dependencies on the Zope package and
> products can be removed without major surgery. :-(
I strongly believe that 'import Zope' or equivalent should be usable
from unit tests. The environmental changes it makes (for example,
Products.__path__ surgery, Products initialization, and HOME setup)
should be shared code. Packages that are separable from Zope, such as
ZPT, would be able to use 'sys.modules.has_key' to detect when they are
imported in a Zope context.
We could refactor the various tasks in 'Zope/__init__.py' into another
package or module named 'ZopeInit', and change 'Zope/__init__.py' to
import 'ZopeInit' and call 'ZopeInit.full_start'.
Then test code would be able to import 'ZopeInit', call
'ZopeInit.set_environment', fiddle with the database settings (e.g. set
up a DemoStorage), call 'ZopeInit.init_database', and perform tests.
Once done, it could call 'ZopeInit.reset_environment' to clean up after
itself.
Separable code could switch AccessControl and other Zope-specific calls
on or off depending on 'sys.modules.has_key("ZopeInit")'.
You can get some of the "same" effects now by cutting and pasting code
from 'Zope/__init__.py', but that's fragile and guruish.
Cheers,
Evan