Hi Gustavo, thanks for looking at this, and James too.
I've added a test now, and refactored the definition of has_zope and
its companions into the tests.zope package rather than in
tests.zope.zstorm.
If this isn't really what you're looking for, let's have a chat on IRC
before I head off into the wild again.
Incremental diff:
=== modified file 'test'
--- test 2009-02-05 10:16:40 +0000
+++ test 2009-03-05 21:50:46 +0000
@@ -66,7 +66,7 @@
elif relpath == os.path.join("tests", "zope", "README.txt"):
# Special case the inclusion of the Zope-dependent
# ZStorm doctest.
- from tests.zope.zstorm import has_zope
+ from tests.zope import has_zope
if has_zope:
doctests.append(relpath)
elif filename.endswith(".txt"):
=== modified file 'tests/zope/__init__.py'
--- tests/zope/__init__.py 2007-08-05 21:59:54 +0000
+++ tests/zope/__init__.py 2009-03-05 21:50:34 +0000
@@ -17,3 +17,25 @@
# You should have received a copy of the GNU Lesser General Public License
# along with this program. If not, see .
#
+
+__all__ = [
+ 'has_transaction',
+ 'has_zope',
+ 'has_zope_component',
+ ]
+
+try:
+ import transaction
+except ImportError:
+ has_transaction = False
+else:
+ has_transaction = True
+
+try:
+ import zope.component
+except ImportError:
+ has_zope_component = False
+else:
+ has_zope_component = True
+
+has_zope = has_transaction and has_zope_component
=== added file 'tests/zope/adapters.py'
--- tests/zope/adapters.py 1970-01-01 00:00:00 +0000
+++ tests/zope/adapters.py 2009-03-05 21:49:47 +0000
@@ -0,0 +1,57 @@
+#
+# Copyright (c) 2006, 2007 Canonical
+#
+# Written by Gustavo Niemeyer
+#
+# This file is part of Storm Object Relational Mapper.
+#
+# Storm is free software; you can redistribute it and/or modify
+# it under the terms of the GNU Lesser General Public License as
+# published by the Free Software Foundation; either version 2.1 of
+# the License, or (at your option) any later version.
+#
+# Storm is distributed in the hope that it will be useful,
+# but WITHOUT ANY WARRANTY; without even the implied warranty of
+# MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
+# GNU Lesser General Public License for more details.
+#
+# You should have received a copy of the GNU Lesser General Public License
+# along with this program. If not, see .
+#
+from tests.helper import TestHelper
+from tests.zope import has_zope_component
+
+
+if has_zope_component:
+ from zope.interface import implements
+ from zope.component import getGlobalSiteManager
+
+ from storm.store import EmptyResultSet
+ from storm.zope.adapters import sqlobject_result_set_to_storm_result_set
+ from storm.zope.interfaces import IResultSet, ISQLObjectResultSet
+
+ class TestSQLObjectResultSet(object):
+ implements(ISQLObjectResultSet)
+ _result_set = EmptyResultSet()
+
+
+class AdaptersTest(TestHelper):
+
+ def is_supported(self):
+ return has_zope_component
+
+ def setUp(self):
+ getGlobalSiteManager().registerAdapter(
+ sqlobject_result_set_to_storm_result_set)
+
+ def tearDown(self):
+ getGlobalSiteManager().unregisterAdapter(
+ sqlobject_result_set_to_storm_result_set)
+
+ def test_adapt_sqlobject_to_storm(self):
+ so_result_set = TestSQLObjectResultSet()
+ self.assertTrue(
+ ISQLObjectResultSet.providedBy(so_result_set))
+ result_set = IResultSet(so_result_set)
+ self.assertTrue(
+ IResultSet.providedBy(result_set))
=== modified file 'tests/zope/zstorm.py'
--- tests/zope/zstorm.py 2008-10-21 09:19:47 +0000
+++ tests/zope/zstorm.py 2009-03-05 21:51:16 +0000
@@ -21,25 +21,15 @@
import thread, weakref, gc
from tests.helper import TestHelper
+from tests.zope import has_transaction, has_zope_component
-try:
+if has_transaction:
import transaction
-except ImportError:
- has_transaction = False
-else:
- has_transaction = True
from storm.zope.interfaces import IZStorm, ZStormError
from storm.zope.zstorm import ZStorm, StoreDataManager
-try:
+if has_zope_component:
from zope.component import provideUtility, getUtility
-except ImportError:
- has_zope_component = False
-else:
- has_zope_component = True
-
-has_zope = has_transaction and has_zope_component
-
from storm.exceptions import OperationalError
from storm.locals import Store