[Grok-dev] ComponentLookupError: (<InterfaceClass
zope.app.catalog.interfaces.ICatalog>, '') on doctests
Dirceu Pereira Tiegs
dirceutiegs at gmail.com
Sat Aug 4 14:04:59 EDT 2007
Hello,
I have a class called Shelf wich uses "getUtility(ICatalog)" to
obtain and use a catalog to perform searches. It works well on a live
site, but when I run the doctests I got a ComponentLookupError.
The Shelf class code is here:
import grok
from article import Article
from zope.app.catalog.interfaces import ICatalog
from zope.component import getUtility
class Shelf(grok.Container):
"""
A shelf is a container for books and articles, used for
containment and searching.
First, some setup code:
>>> import grok
>>> grok.grok('bookshelf')
>>> from datetime import datetime
And create a sample shelf with an article:
>>> shelf = Shelf()
>>> title = "Grok Sprint Zwei: the Ascent of Man"
>>> article = Article(title=title, issued=datetime(2007,1,9))
>>> name = INameChooser(shelf).chooseName(title, article)
>>> shelf[name] = article
>>> name in shelf
True
Now let's see if searching works:
>>> results = shelf.search('Sprint')
>>> len(results)
1
>>> results = shelf.search('Foo')
>>> len(results)
0
"""
def search(self, query=None):
if not query:
results = self.values()
else:
catalog = getUtility(ICatalog)
results = catalog.searchResults(title=query)
results = list(results)
return sorted(results, key=attrgetter('title'))
The complete traceback is here:
- http://pastebin.ca/645496
Do I need to use some kind of setup code to make this work?
Thanks,
--
Dirceu Pereira Tiegs - http://dirceu.info/
Weimar Consultoria
Hospedagem Plone, Zope e Python
http://www.pytown.com
More information about the Grok-dev
mailing list