[Grok-dev] Testing a container which uses a custom NameChooser

Luciano Ramalho luciano at ramalho.org
Tue Jul 31 07:57:59 EDT 2007

On 7/31/07, Darryl Cousins <darryl at darrylcousins.net.nz> wrote:
> import grok
> grok.grok('kirbi')

Thanks a lot, Darryl!

I saw those calls in the grok tests themselves, but I wasn't sure they
were needed when testing grok apps (as opposed to testing grok

I'll contribute a testing mini-tutorial...

Now I have two further questions concerning the same test (further along):

1) Should I convert *all* strings into unicode for use with Zope 3 or
does it still use or prefer plain strings for some purposes? I noticed
the __name__ of the contained objects was converted by Zope to

2) In the pac.py module [1] there is a subscriber declared like this:

@grok.subscribe(Book, grok.IObjectAddedEvent)
def bookAdded(book, event):
    if not book.title:
        pac = book.__parent__

[1] http://svn.zope.org/Sandbox/luciano/kirbi/src/kirbi/pac.py?rev=78499&view=markup
(or http://tinyurl.com/3ybsed)

The last line of the doctest reproduced below aims to test that event,
but it's failing. However, when I try the live app, it works. Do I
need some additional registration to make the test pass?




Pac: The Public Access Catalog container class

A Pac is designed to store book records. Let's create one and put a few
books in it::

  >>> import grok
  >>> grok.grok('kirbi')
  >>> from kirbi.pac import Pac
  >>> from kirbi.book import Book
  >>> pac = Pac()
  >>> pac.addBook(Book(u'Zero'))
  >>> pac.addBook(Book(isbn13='978-0670030583'))
  >>> pac.addBook(Book(u'A Tale of Two Cities', isbn13='978-0141439600'))
  >>> sorted(pac)
  [u'9780141439600', u'9780670030583', u'k0001']

One of the books has ISBN but no Title, so it's put in the fetch queue::

  >>> pac.pending_isbns


More information about the Grok-dev mailing list