[Zope] Overriding DateTime

Tim Knapp duffyd at kokorice.org
Thu Mar 26 05:25:32 EDT 2009


On Thu, 2009-03-26 at 09:16 +0000, Maurits van Rees wrote:
> Tim Knapp, on 2009-03-26:
> > On Wed, 2009-03-25 at 21:20 +0100, Dieter Maurer wrote:
> >> Tim Knapp wrote at 2009-3-23 18:21 +1300:
> >> >I would like to override the DateTime.DateTime class within my
> >> >functional tests. I have tried mocking (via mocker) and injecting the
> >> >subclassed DateTime class into sys.modules (results in a
> >> >TraversalError). The fartherest I've gotten is to set DateTime.DateTime
> >> >= MySubclassedDateTime in my tests.py, which does work for the code
> >> >'within' the package(s) I'm testing but all the Zope core code (i.e. the
> >> >instance created within PloneTestCase) is still referencing the global
> >> >DateTime module. Has anyone successfully done this?
> >> 
> >> "import DateTime; DateTime=<myDateTimeClass>" should be able
> >> to replace the "DateTime" class -- sometimes.
> >> 
> >> 
> >> Be aware, however, that this replacing takes effect only after
> >> your assignment. Modules that already have imported the "DateTime"
> >> class will not be affected.
> >
> > Thanks, yeah that was what I thought. I tried to do it in the _setup
> > method of PloneTestCase, which theoretically gets called before the
> > instance is runup but maybe not. Didn't seem to affect the Zope instance
> > itself anyway.
> 
> A few years ago at Zest Software we needed a patch (for Archetypes I
> think) and hit the same problem that our product was too late in the
> startup process to have enough influence.  So we put the patch in a
> product called (Products.)AAAPatch; affectionately called triple A
> patch. :-) Due to the three A-s at the beginning it was virtually
> guaranteed to be the first product to load.

Awesome, I'll give it a go and report back.

Thanks,
Tim

> 



More information about the Zope mailing list