[z3-five] Re: Some design questions

Philipp von Weitershausen philipp at weitershausen.de
Tue Apr 19 14:39:20 MEST 2005


Andreas Jung wrote:
> 
> 
> --On Montag, 18. April 2005 22:38 Uhr +0200 Philipp von Weitershausen 
> <philipp at weitershausen.de> wrote:
> 
>>> --On Montag, 18. April 2005 19:58 Uhr +0200 Philipp von Weitershausen
>>> <philipp at weitershausen.de> wrote:
>>>
>>>>    german_stopwords = zapi.getUtility(IStopWords, 'de')
>>>>
>>>> So, in short, all stop-word objects are utilities that provide
>>>> IStopWords and their registration name is the country/language code.
>>>> The same thing would most probably make sense for converters (utility
>>>> name would be the mime type) and the parsers (name would be the
>>>> country/language code again).
>>>
>>>
>>> Utilities are available in Five?
>>
>>
>> Yup. They work just like in Zope 3, simply use the <utility /> directive
>> in ZCML.
> 
> 
> How do you deal with testing such things in Five? Currently I have
> only pure Python code (using only Zope2 BTrees). Since utitlites need
> to be configured using ZCML, how should I setup my tests for testing
> utilitiy functionalies? I've seen that the Five tests use a subclass
> of ZopeTestCase...maybe I don't want to use ZopeTestCase at the
> current stage and stick with Python or core Zope 3 functionalities at
> the moment...any chance to do this?

Yes. I'm actually in the middle of refactoring Five tests to be more 
Pythonic. Because of the whole Products-is-not-a-real-Python-package 
issue, we can't really get rid of ZopeTestCase entirely for Five, but if 
you're using a regular Python top-level package, you should be able to.

As for setting up components that are normally setup through ZCML, you 
can use the ``ztapi`` module which provides convenient functions::

   >>> from zope.app.tests import ztapi
   >>> ztapi.provideUtility(...)
   >>> ztapi.provideAdapter(...)
   >>> ztapi.browserView(...)

The ``ztapi`` API is documented on the last page of the ZAPI reference 
in my book (page 388).

Philipp


More information about the z3-five mailing list