From 94ef03575326f9bb4e5064f1f6132ac2593f014f Mon Sep 17 00:00:00 2001 From: Georgy Moiseev Date: Mon, 24 Oct 2022 11:54:16 +0300 Subject: [PATCH] test: fix dbapi test connection resource warnings DBAPI2 compliance tests are not implemented here but inherited from external module [1]. Two tests from this module open a connection and forget to close it. The issue had been filed together with patch PR to module repository [2], but the last update was 7 years ago so it is possibly that it would never be merged. This patch adds this PR change with method overwrite. 1. https://pypi.org/project/dbapi-compliance/ 2. https://github.com/baztian/dbapi-compliance/issues/5 Part of #250 --- test/suites/test_dbapi.py | 40 +++++++++++++++++++++++++++++++++++++++ 1 file changed, 40 insertions(+) diff --git a/test/suites/test_dbapi.py b/test/suites/test_dbapi.py index 3873fa84..0df06337 100644 --- a/test/suites/test_dbapi.py +++ b/test/suites/test_dbapi.py @@ -127,3 +127,43 @@ def test_setoutputsize(self): # Do nothing @unittest.skip('Not implemented') def test_description(self): pass + + def test_ExceptionsAsConnectionAttributes(self): + # Workaround for https://github.com/baztian/dbapi-compliance/issues/5 + + # OPTIONAL EXTENSION + # Test for the optional DB API 2.0 extension, where the exceptions + # are exposed as attributes on the Connection object + # I figure this optional extension will be implemented by any + # driver author who is using this test suite, so it is enabled + # by default. + drv = self.driver + con = self._connect() + try: + dbapi20._failUnless(self,con.Warning is drv.Warning) + dbapi20._failUnless(self,con.Error is drv.Error) + dbapi20._failUnless(self,con.InterfaceError is drv.InterfaceError) + dbapi20._failUnless(self,con.DatabaseError is drv.DatabaseError) + dbapi20._failUnless(self,con.OperationalError is drv.OperationalError) + dbapi20._failUnless(self,con.IntegrityError is drv.IntegrityError) + dbapi20._failUnless(self,con.InternalError is drv.InternalError) + dbapi20._failUnless(self,con.ProgrammingError is drv.ProgrammingError) + dbapi20. _failUnless(self,con.NotSupportedError is drv.NotSupportedError) + finally: + con.close() + + + def test_rollback(self): + # Workaround for https://github.com/baztian/dbapi-compliance/issues/5 + + con = self._connect() + try: + # If rollback is defined, it should either work or throw + # the documented exception + if hasattr(con,'rollback'): + try: + con.rollback() + except self.driver.NotSupportedError: + pass + finally: + con.close()