Submitted by : Simon Michael at: 2007-04-07T17:55:22+00:00 (10 years ago)
Name :
Category : Severity : Status :
Optional subject :  
Optional comment :

(new) can't commit in zwiki unit tests --Simon Michael, Sat, 07 Apr 2007 17:55:26 +0000 reply

ZopeTestCase? supports committing a zodb savepoint, which would set up _p_jar and allow us to test page history. In Zwiki unit tests though, it complains; maybe this is something we can fix ?

(Pdb) transaction.savepoint(1)
*** TypeError: can't pickle file objects
(Pdb) transaction.commit(1)
/zope1/Products/ZWiki/Diff_tests.py:1: DeprecationWarning: This will be removed in ZODB 3.7:
subtransactions are deprecated; use transaction.savepoint() instead of transaction.commit(1)
  from testsupport import *
*** TransactionFailedError: An operation previously failed, with traceback:

 File "/zope-2.10/bin/test.py", line 117, in ?
   sys.exit(testrunner.run(defaults))
 File "/zope-2.10/lib/python/zope/testing/testrunner.py", line 271, in run
   failed = not run_with_options(options)
 File "/zope-2.10/lib/python/zope/testing/testrunner.py", line 410, in run_with_options
   ran += run_tests(options, tests, 'unit', failures, errors)
 File "/zope-2.10/lib/python/zope/testing/testrunner.py", line 540, in run_tests
   test(result)
 File "/zope-2.10/lib/python/Testing/ZopeTestCase/profiler.py", line 98, in __call__
   testMethod()
 File "/zope1/Products/ZWiki/Diff_tests.py", line 79, in test_revertEditsEverywhereBy
   p.revertEditsEverywhereBy('joe')
 File "bdb.py", line 48, in trace_dispatch
   return self.dispatch_line(frame)
 File "bdb.py", line 66, in dispatch_line
   self.user_line(frame)
 File "pdb.py", line 135, in user_line
   self.interaction(frame, None)
 File "pdb.py", line 158, in interaction
   self.cmdloop()
 File "cmd.py", line 142, in cmdloop
   stop = self.onecmd(line)
 File "cmd.py", line 218, in onecmd
   return self.default(line)
 File "pdb.py", line 167, in default
   exec code in globals, locals
 File "<stdin>", line 1, in ?
 File "/zope-2.10/lib/python/transaction/_manager.py", line 110, in savepoint
   return self.get().savepoint(optimistic)
 File "/zope-2.10/lib/python/transaction/_transaction.py", line 312, in savepoint
   self._saveAndRaiseCommitishError() # reraises!
 File "/zope-2.10/lib/python/transaction/_transaction.py", line 422, in _saveAndRaiseCommitishError
   t, v, tb = self._saveAndGetCommitishError()
 File "/zope-2.10/lib/python/transaction/_transaction.py", line 309, in savepoint
   savepoint = Savepoint(self, optimistic, *self._resources)
 File "/zope-2.10/lib/python/transaction/_transaction.py", line 737, in __init__
   savepoint = savepoint()
 File "/zope-2.10/lib/python/ZODB/Connection.py", line 1034, in savepoint
   self._commit(None)
 File "/zope-2.10/lib/python/ZODB/Connection.py", line 543, in _commit
   self._store_objects(ObjectWriter(obj), transaction)
 File "/zope-2.10/lib/python/ZODB/Connection.py", line 570, in _store_objects
   p = writer.serialize(obj)  # This calls __getstate__ of obj
 File "/zope-2.10/lib/python/ZODB/serialize.py", line 407, in serialize
   return self._dump(meta, obj.__getstate__())
 File "/zope-2.10/lib/python/ZODB/serialize.py", line 416, in _dump
   self._p.dump(state)
 File "copy_reg.py", line 69, in _reduce_ex
   raise TypeError, "can't pickle %s objects" % base.__name__
TypeError: can't pickle file objects

... --simon, Sat, 07 Apr 2007 18:09:44 +0000 reply

Category: => general Severity: normal => wishlist Status: => open

News: It's probably DemoStorage? at fault --betabug, Sun, 15 Apr 2007 15:24:17 +0000 reply

Interesting comment in OFS/tests/testHistory.py:

# set up a zodb
# we can't use DemoStorage here 'cos it doesn't support History

I think we've got the same problem in Zwiki's tests wherever we hit on zodb history when testing. In fact there are two problems:

First we replace ZTC's REQUEST with our own mock request:

# our mock request seems a bit more useful than ZTC's
#self.request = self.app.REQUEST
self.request = self.page.REQUEST = MockRequest()

When I commented this out in a (new) test file I made, I was able to commit transactions withouth the above error.

Second, after I got transactions to work, I tried to test the /diff method, but ran into trouble, because our history() method (which basically calls Zope's manage_change_history) returns () - an empty tupble. This happens in manage_change_history (OFS/History.py), where we hit on the following lines:

r=self._p_jar.db().history(self._p_oid, None, last)
if r is None:
    # storage doesn't support history
    return ()

I guess to properly test our own history behaviour we will have to make extra tests along the line of OFS/tests/testHistory.py.

fixed in darcs --simon, Sat, 28 Apr 2007 01:58:59 +0000 reply

Status: open => closed

Fixed by recent commits, I believe (ZWikiPage.__getstate__ omits the REQUEST from pickling).