1############################################################################## 2# 3# Copyright (c) 2017 Zope Foundation and Contributors. 4# All Rights Reserved. 5# 6# This software is subject to the provisions of the Zope Public License, 7# Version 2.1 (ZPL). A copy of the ZPL should accompany this distribution. 8# THIS SOFTWARE IS PROVIDED "AS IS" AND ANY AND ALL EXPRESS OR IMPLIED 9# WARRANTIES ARE DISCLAIMED, INCLUDING, BUT NOT LIMITED TO, THE IMPLIED 10# WARRANTIES OF TITLE, MERCHANTABILITY, AGAINST INFRINGEMENT, AND FITNESS 11# FOR A PARTICULAR PURPOSE. 12# 13############################################################################## 14 15import unittest 16 17from ZODB import mvccadapter 18 19 20class TestBase(unittest.TestCase): 21 22 def test_getattr_does_not_hide_exceptions(self): 23 class TheException(Exception): 24 pass 25 26 class RaisesOnAccess(object): 27 28 @property 29 def thing(self): 30 raise TheException() 31 32 base = mvccadapter.Base(RaisesOnAccess()) 33 base._copy_methods = ('thing',) 34 35 with self.assertRaises(TheException): 36 getattr(base, 'thing') 37 38 def test_getattr_raises_if_missing(self): 39 base = mvccadapter.Base(self) 40 base._copy_methods = ('thing',) 41 42 with self.assertRaises(AttributeError): 43 getattr(base, 'thing') 44 45 46class TestHistoricalStorageAdapter(unittest.TestCase): 47 48 def test_forwards_release(self): 49 class Base(object): 50 released = False 51 52 def release(self): 53 self.released = True 54 55 base = Base() 56 adapter = mvccadapter.HistoricalStorageAdapter(base, None) 57 58 adapter.release() 59 60 self.assertTrue(base.released) 61