[Zope3-Users] Persistent subclasses in tests

2006-07-23 Thread Darryl Cousins
Hi,

I've have a problem with the following and I hope someone can shed some
light for me, I can't figure out what I am missing::

 from ZODB.tests.util import DB
 import transaction
 db = DB()
 conn = db.open()
 root = conn.root()

 from persistent import Persistent
 p = Persistent()
 root['p'] = p

Thats fine, but::

 class TestItem(Persistent):
... pass

 item = TestItem()
 root['item'] = item

 transaction.commit()
Traceback (most recent call last):
  File /opt/zope/zope3/src/zope/testing/doctest.py, line 1361, in __run
compileflags, 1) in test.globs
  File doctest README.txt[28], line 1, in ?
transaction.commit()
  File /opt/zope/zope3/src/transaction/_manager.py, line 96, in commit
return self.get().commit(sub, deprecation_wng=False)
  File /opt/zope/zope3/src/transaction/_transaction.py, line 395, in 
commit
self._commitResources()
  File /opt/zope/zope3/src/transaction/_transaction.py, line 495, in 
_commitResources
rm.commit(self)
  File /opt/zope/zope3/src/ZODB/Connection.py, line 484, in commit
self._commit(transaction)
  File /opt/zope/zope3/src/ZODB/Connection.py, line 526, in _commit
self._store_objects(ObjectWriter(obj), transaction)
  File /opt/zope/zope3/src/ZODB/Connection.py, line 553, in _store_objects
p = writer.serialize(obj)  # This calls __getstate__ of obj
  File /opt/zope/zope3/src/ZODB/serialize.py, line 407, in serialize
return self._dump(meta, obj.__getstate__())
  File /opt/zope/zope3/src/ZODB/serialize.py, line 416, in _dump
self._p.dump(state)
PicklingError: Can't pickle class 'TestItem': attribute lookup 
__builtin__.TestItem failed
 

___
Zope3-users mailing list
Zope3-users@zope.org
http://mail.zope.org/mailman/listinfo/zope3-users


Re: [Zope3-Users] Persistent subclasses in tests

2006-07-23 Thread Gary Poster


On Jul 23, 2006, at 6:59 PM, Darryl Cousins wrote:


Hi,

I've have a problem with the following and I hope someone can shed  
some

light for me

...

Yup, you need to handle a case like that specially.

See zope.testing.module

Gary
___
Zope3-users mailing list
Zope3-users@zope.org
http://mail.zope.org/mailman/listinfo/zope3-users


Re: [Zope3-Users] Persistent subclasses in tests

2006-07-23 Thread Darryl Cousins
Hi Gary,

Thanks for that. For those who follow

tests.py::

  import unittest

  from zope.testing import doctest
  from zope.testing import module

  name = 'tfws.cart.README'

  def setUp(test):
  module.setUp(test, name)

  def tearDown(test):
  module.tearDown(test, name)

  def test_suite():
  return unittest.TestSuite((
doctest.DocFileSuite('README.txt',
setUp=setUp, tearDown=tearDown,
optionflags=doctest.ELLIPSIS
),
))

if __name__ == '__main__':
unittest.main(defaultTest='test_suite')

On Sun, 2006-07-23 at 20:59 -0400, Gary Poster wrote:
 On Jul 23, 2006, at 6:59 PM, Darryl Cousins wrote:
 
  Hi,
 
  I've have a problem with the following and I hope someone can shed  
  some
  light for me
 ...
 
 Yup, you need to handle a case like that specially.
 
 See zope.testing.module
 
 Gary

___
Zope3-users mailing list
Zope3-users@zope.org
http://mail.zope.org/mailman/listinfo/zope3-users