Commit a3f43529 authored by Jason Madden's avatar Jason Madden Committed by GitHub

Merge pull request #170 from zopefoundation/issue78

HistoricalStorageAdapter forwards release() to its instance
parents 5056d49e c2f9eb70
...@@ -9,6 +9,8 @@ ...@@ -9,6 +9,8 @@
- Drop support for Python 3.3. - Drop support for Python 3.3.
- Ensure that the ``HistoricalStorageAdapter`` forwards the ``release`` method to
its base instance. See `issue 78 <https://github.com/zopefoundation/ZODB/issues/788>`_.
5.2.4 (2017-05-17) 5.2.4 (2017-05-17)
================== ==================
......
...@@ -27,7 +27,6 @@ class Base(object): ...@@ -27,7 +27,6 @@ class Base(object):
def __getattr__(self, name): def __getattr__(self, name):
if name in self._copy_methods: if name in self._copy_methods:
if hasattr(self._storage, name):
m = getattr(self._storage, name) m = getattr(self._storage, name)
setattr(self, name, m) setattr(self, name, m)
return m return m
...@@ -204,7 +203,12 @@ class HistoricalStorageAdapter(Base): ...@@ -204,7 +203,12 @@ class HistoricalStorageAdapter(Base):
return False return False
def release(self): def release(self):
try:
release = self._storage.release
except AttributeError:
pass pass
else:
release()
close = release close = release
......
##############################################################################
#
# Copyright (c) 2017 Zope Foundation and Contributors.
# All Rights Reserved.
#
# This software is subject to the provisions of the Zope Public License,
# Version 2.1 (ZPL). A copy of the ZPL should accompany this distribution.
# THIS SOFTWARE IS PROVIDED "AS IS" AND ANY AND ALL EXPRESS OR IMPLIED
# WARRANTIES ARE DISCLAIMED, INCLUDING, BUT NOT LIMITED TO, THE IMPLIED
# WARRANTIES OF TITLE, MERCHANTABILITY, AGAINST INFRINGEMENT, AND FITNESS
# FOR A PARTICULAR PURPOSE.
#
##############################################################################
import unittest
from ZODB import mvccadapter
class TestBase(unittest.TestCase):
def test_getattr_does_not_hide_exceptions(self):
class TheException(Exception):
pass
class RaisesOnAccess(object):
@property
def thing(self):
raise TheException()
base = mvccadapter.Base(RaisesOnAccess())
base._copy_methods = ('thing',)
with self.assertRaises(TheException):
getattr(base, 'thing')
def test_getattr_raises_if_missing(self):
base = mvccadapter.Base(self)
base._copy_methods = ('thing',)
with self.assertRaises(AttributeError):
getattr(base, 'thing')
class TestHistoricalStorageAdapter(unittest.TestCase):
def test_forwards_release(self):
class Base(object):
released = False
def release(self):
self.released = True
base = Base()
adapter = mvccadapter.HistoricalStorageAdapter(base, None)
adapter.release()
self.assertTrue(base.released)
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