[Zope-Coders] Testing from an INSTANCE_HOME
Richard Jones
richard@commonground.com.au
Sun, 8 Jun 2003 09:14:27 +1000
-----BEGIN PGP SIGNED MESSAGE-----
Hash: SHA1
On Sunday, June 8, 2003, at 12:37 AM, Chris Withers wrote:
> Shane Hathaway wrote:
>> What if we just decided that unit tests should not use Zope.app() to
>> open a database, but rather a new function called Testing.app()?
>> Testing.app() would return a clean database that unit tests are free
>> to change. If all unit tests that use Zope.app() start using
>> Testing.app() instead, we won't need the custom_zodb.py hack and the
>> Testing package can leave INSTANCE_HOME alone.
>
> I think this is a fantastic idea :-)
>
> Test that want to be INSTANCE_HOME testable can use Testing.app(),
> those that don't care or want to maintain backward compatability can
> do what they're doing now...
We do something like this right now. I'm not completely up to speed
with the way that our test harness works. I don't know where Stuart got
the code (he may have written it himself - the comments in the file
indicate he may have).
We use the following scheme:
# in test file
import testhelpers.zope
app = testhelpers.zope.createDatabase()
# now use app just like Zope.app()
# testhelpers/zope.py
import ZODB,OFS.Application
from ZODB.DemoStorage import DemoStorage
from ZODB.DB import DB
def createDatabase():
''' Create a dummy ZODB and install products. Returns a
OFS.Application '''
OFS.Application.import_products()
db = DB(DemoStorage())
con = db.open()
root = con.root()
app = OFS.Application.Application()
root['Application'] = app
get_transaction().commit()
OFS.Application.install_products(app)
return app
# end testhelpers/zope.py
-----BEGIN PGP SIGNATURE-----
Version: GnuPG v1.2.1 (Darwin)
iD8DBQE+4nHUrGisBEHG6TARAhdOAJ0Vvkp/1qOGFifhxDYarMOYlpDiSACeNHCs
NUuQzqhL/mWLA3b+lXmkT38=
=h+mA
-----END PGP SIGNATURE-----