doctest + shelve question

  • Thread starter Sebastian Bartos
  • Start date

S

Sebastian Bartos

Hello list,

I have a question. I'm writing a simple object serialization module
using shelve to write arbitrary objects to a file (M.py). Now I have the
problem, that if I create a simple object in the doctest documentation
file M.txt like this:
... def __init__(self, name):
... self.name = name
and then run it with my module M:

which calls:

class serialize(object):
def __init__(self, path, key, data):
db = shelve.open(path)
db[key.encode('utf-8')] = data
db.close()

then I get the following problem:

Failed example:
foo = M.serialize('/tmp/foo', tinst)
Exception raised:
Traceback (most recent call last):
File "/usr/lib/python2.5/doctest.py", line 1228, in __run
compileflags, 1) in test.globs
....
File "/usr/lib/python2.5/shelve.py", line 123, in __setitem__
p.dump(value)
PicklingError: Can't pickle <class 'tdata'>: attribute lookup
__builtin__.tdata failed


If I do the same in the interactive interpreter, then it works fine.

Now, as I want to test an arbitrary data class, the doctest file is the
place to put the simple tdata class, but as far as I traced the problem,
it uses it's own namespace or something, and so does not work.

I'd like to keep a consistent doctest documentation here and not spawn
my project with additional test modules or similar.

Any idea on how I can make it work like as if it would be called from
the interactive interpreter? The documentation and Google were not too
helpful.

ps. Sys: Linux, Python: 2.5.2

thanks

--
Sebastian Bartos, <[email protected]>
keyserevr: pgp.mit.edu

-----BEGIN PGP SIGNATURE-----
Version: GnuPG v1.4.9 (GNU/Linux)

iEYEABECAAYFAkmxm+sACgkQcjqH4/stm185TQCdH69NOU66hSz2Jm+Ka4BluMZy
N9AAoKOXOjHZhMWSipByU9q+MyHLr8ez
=xvlL
-----END PGP SIGNATURE-----
 
Ad

Advertisements


Ask a Question

Want to reply to this thread or ask your own question?

You'll need to choose a username for the site, which only take a couple of moments. After that, you can post your question and our members will help you out.

Ask a Question

Top