[Zope-CMF] [dev] failing tests and other unit test issues

Florent Guillaume fg at nuxeo.com
Mon Apr 4 12:12:28 EDT 2005


yuppie  <y.2005- at wcm-solutions.de> wrote:
> 3.) Zope 2.8 warnings
> 
> 'Zope2' is not available in Zope 2.7 and 'Zope' is deprecated in Zope 
> 2.8. Same with 'transaction' and 'get_transaction'.
> 
> Has anybody a better idea to resolve it than this way:
> 
> http://cvs.zope.org/Products/CMFCore/tests/base/testcase.py.diff?r1=1.11&r2=1.12
> 
> If not, I'll use that pattern for other files and the 1.5 branch as well.

Instead of:

+try:
+    import transaction
+    has_transaction = True
+except ImportError:
+    # BBB: for Zope 2.7
+    has_transaction = False

-        get_transaction().begin()
+        if has_transaction:
+            transaction.begin()
+        else:
+            # BBB: for Zope 2.7
+            get_transaction().begin()

I was thinking of:

try:
    import transaction
except ImportError:
    # BBB: for Zope 2.7
    class BBBTransaction:
        def begin(self): get_transaction().begin()
        def commit(sub=False): get_transaction().commit(sub)
        def abort(sub=False): get_transaction().abort(sub)
    transaction = BBBTransaction()

And just use transaction.begin() everywhere in the code.

Florent

-- 
Florent Guillaume, Nuxeo (Paris, France)   CTO, Director of R&D
+33 1 40 33 71 59   http://nuxeo.com   fg at nuxeo.com


More information about the Zope-CMF mailing list