Re: [ZODB-Dev] DemoStorage stacking in zope.testing layers

2010-04-05 Thread Marius Gedminas
On Mon, Apr 05, 2010 at 10:36:49PM +0800, Martin Aspeli wrote:
> I'm trying to do something like the following:
> 
>   - A test layer "EmptyZODB" sets up an empty ZODB using DemoStorage and 
> exposes the DB object to other layers and tests.
> 
>   - A test layer "Foo" has "EmptyZODB" as a base. It opens a connection 
> during layer setup, makes some changes, commits those, and closes the 
> connection.
> 
>   - A test layer "Bar" has "Foo" as a base. It pushes a new DemoStorage 
> on top of the one that was modified by "Foo", opens a new connection, 
> makes changes, commits those, and closes the connection.
> 
>   - On layer tear-down, "Bar" pops the demo storage, leaving the 
> pristine fixture from "Foo".

I did this for SchoolTool once (poorly, because there were no layers
yet).  Note that when you stack multiple DemoStorages, ZODB gets
very noticeably slow.

As Hanno mentioned, zope.app.testing.functional also does this (with
just one level of DemoStorage, substituting a new one for every test).

You may want to looking up older versions of functional.py, since those
were much simpler (because they didn't have support for multiple
simultaneous databases).

> The problem with this scenario is that the database that was created by 
> "EmptyZODB" and then modified by "Foo" is by necessity already "active" 
> (even if it has no open connections). From my reading of the 
> docs/interfaces, it's not possible to "swap out" a storage of a DB 
> object, i.e. the storage is only settable in the constructor.
> 
> What is the correct way to use DemoStorage stacking in test layers? 

Close and discard the old database object, create a new demo storage
wrapping the old storage, create a new DB for it.

> Should "Bar" create a new DB object of its own and expose that to the 
> tests that need it? Or is there some way to keep the same "DB" object 
> (which would make the tests easier to write in this case) and simply 
> tell it to use the top of the stack at all times?

IMHO it's easier to find a way to pass the current database to the tests
than to make the database switch storages on the fly.

Marius Gedminas
-- 
Never trust a smiling Gates.


signature.asc
Description: Digital signature
___
For more information about ZODB, see the ZODB Wiki:
http://www.zope.org/Wikis/ZODB/

ZODB-Dev mailing list  -  ZODB-Dev@zope.org
https://mail.zope.org/mailman/listinfo/zodb-dev


Re: [ZODB-Dev] DemoStorage stacking in zope.testing layers

2010-04-05 Thread Hanno Schlichting
Hi.

On Mon, Apr 5, 2010 at 4:36 PM, Martin Aspeli  wrote:
> What is the correct way to use DemoStorage stacking in test layers?

Not sure if this helps, but zope.app.testing's functional.py [1] did
something similar here (stacking DemoStorages). Maybe the
FunctionalTestSetup class including the way it uses shared state to
keep track of the DB's might be helpful.

Hanno

[1] 
http://svn.zope.org/zope.app.testing/trunk/src/zope/app/testing/functional.py?view=markup
___
For more information about ZODB, see the ZODB Wiki:
http://www.zope.org/Wikis/ZODB/

ZODB-Dev mailing list  -  ZODB-Dev@zope.org
https://mail.zope.org/mailman/listinfo/zodb-dev


[ZODB-Dev] DemoStorage stacking in zope.testing layers

2010-04-05 Thread Martin Aspeli
Hi,

I'm trying to do something like the following:

  - A test layer "EmptyZODB" sets up an empty ZODB using DemoStorage and 
exposes the DB object to other layers and tests.

  - A test layer "Foo" has "EmptyZODB" as a base. It opens a connection 
during layer setup, makes some changes, commits those, and closes the 
connection.

  - A test layer "Bar" has "Foo" as a base. It pushes a new DemoStorage 
on top of the one that was modified by "Foo", opens a new connection, 
makes changes, commits those, and closes the connection.

  - On layer tear-down, "Bar" pops the demo storage, leaving the 
pristine fixture from "Foo".

The problem with this scenario is that the database that was created by 
"EmptyZODB" and then modified by "Foo" is by necessity already "active" 
(even if it has no open connections). From my reading of the 
docs/interfaces, it's not possible to "swap out" a storage of a DB 
object, i.e. the storage is only settable in the constructor.

What is the correct way to use DemoStorage stacking in test layers? 
Should "Bar" create a new DB object of its own and expose that to the 
tests that need it? Or is there some way to keep the same "DB" object 
(which would make the tests easier to write in this case) and simply 
tell it to use the top of the stack at all times?

Martin

___
For more information about ZODB, see the ZODB Wiki:
http://www.zope.org/Wikis/ZODB/

ZODB-Dev mailing list  -  ZODB-Dev@zope.org
https://mail.zope.org/mailman/listinfo/zodb-dev