[Zope-Checkins] CVS: Zope3/src/ZODB/tests - testConnection.py:1.15
Tim Peters
tim.one at comcast.net
Fri Apr 16 15:07:05 EDT 2004
Update of /cvs-repository/Zope3/src/ZODB/tests
In directory cvs.zope.org:/tmp/cvs-serv16416/src/ZODB/tests
Modified Files:
testConnection.py
Log Message:
Introduced new exception ConnectionStateError, as a subclass of POSError,
raised when an operation on a Connection can't be performed because the
Connection is in "a wrong state".
Connection.close() now raises this exception if the connection is
currently joined to a transaction (most obviously, if the transaction
the connection is joined to has modified objects waiting for commit
or abort).
Also changed other appropriate instances of RuntimeError to raise
ConnectionStateError instead (e.g., trying to load an object from a
closed connection).
=== Zope3/src/ZODB/tests/testConnection.py 1.14 => 1.15 ===
--- Zope3/src/ZODB/tests/testConnection.py:1.14 Fri Apr 16 12:36:42 2004
+++ Zope3/src/ZODB/tests/testConnection.py Fri Apr 16 15:07:04 2004
@@ -236,12 +236,48 @@
>>> cn.get(p64(0))
Traceback (most recent call last):
...
- RuntimeError: The database connection is closed
+ ConnectionStateError: The database connection is closed
>>> p = Persistent()
>>> cn.add(p)
Traceback (most recent call last):
...
- RuntimeError: The database connection is closed
+ ConnectionStateError: The database connection is closed
+ """
+
+ def test_close_with_pending_changes(self):
+ r"""doctest to ensure close() w/ pending changes complains
+
+ >>> import transaction
+
+ Just opening and closing is fine.
+ >>> db = databaseFromString("<zodb>\n<mappingstorage/>\n</zodb>")
+ >>> cn = db.open()
+ >>> cn.close()
+
+ Opening, making a change, committing, and closing is fine.
+ >>> cn = db.open()
+ >>> cn.root()['a'] = 1
+ >>> transaction.commit()
+ >>> cn.close()
+
+ Opening, making a change, committing, and aborting is fine.
+ >>> cn = db.open()
+ >>> cn.root()['a'] = 1
+ >>> transaction.abort()
+ >>> cn.close()
+
+ But trying to close with a change pending complains.
+ >>> cn = db.open()
+ >>> cn.root()['a'] = 1
+ >>> cn.close()
+ Traceback (most recent call last):
+ ...
+ ConnectionStateError: Cannot close a connection joined to a transaction
+
+ This leaves the connection as it was, so we can still commit
+ the change.
+ >>> transaction.commit()
+ >>> cn.close()
"""
def test_onCloseCallbacks(self):
@@ -298,7 +334,7 @@
>>> cn.isReadOnly()
Traceback (most recent call last):
...
- RuntimeError: The database connection is closed
+ ConnectionStateError: The database connection is closed
An expedient way to create a read-only storage:
More information about the Zope-Checkins
mailing list