Commit bc184f63 authored by Tres Seaver's avatar Tres Seaver

Add coverage for 'ZEO.connection' convenience function.

Closes #102.
parent 39db61ba
...@@ -40,7 +40,7 @@ def connection(*args, **kw): ...@@ -40,7 +40,7 @@ def connection(*args, **kw):
return db.open_then_close_db_when_connection_closes() return db.open_then_close_db_when_connection_closes()
except Exception: except Exception:
db.close() db.close()
ra raise
def server(path=None, blob_dir=None, storage_conf=None, zeo_conf=None, def server(path=None, blob_dir=None, storage_conf=None, zeo_conf=None,
port=0, threaded=True, **kw): port=0, threaded=True, **kw):
......
...@@ -124,6 +124,44 @@ class Test_convenience_functions(unittest.TestCase): ...@@ -124,6 +124,44 @@ class Test_convenience_functions(unittest.TestCase):
client.assert_called_once_with(dummy) client.assert_called_once_with(dummy)
client_mock.close.assert_called_once() client_mock.close.assert_called_once()
def test_ZEO_connection_convenience_ok(self):
import mock
import ZEO
ret = object()
DB_mock = mock.Mock(spec=[
'close', 'open_then_close_db_when_connection_closes'])
DB_mock.open_then_close_db_when_connection_closes.return_value = ret
DB_patch = mock.patch('ZEO.DB', return_value=DB_mock)
dummy = object()
with DB_patch as patched:
conn = ZEO.connection(dummy)
self.assertIs(conn, ret)
patched.assert_called_once_with(dummy)
DB_mock.close.assert_not_called()
def test_ZEO_connection_convenience_value(self):
import mock
import ZEO
DB_mock = mock.Mock(spec=[
'close', 'open_then_close_db_when_connection_closes'])
otc = DB_mock.open_then_close_db_when_connection_closes
otc.side_effect = ValueError
DB_patch = mock.patch('ZEO.DB', return_value=DB_mock)
dummy = object()
with DB_patch as patched:
with self.assertRaises(ValueError):
ZEO.connection(dummy)
patched.assert_called_once_with(dummy)
DB_mock.close.assert_called_once()
class MiscZEOTests(object): class MiscZEOTests(object):
"""ZEO tests that don't fit in elsewhere.""" """ZEO tests that don't fit in elsewhere."""
......
Markdown is supported
0%
or
You are about to add 0 people to the discussion. Proceed with caution.
Finish editing this message first!
Please register or to comment