Skip to content

Commit

Permalink
test: fix dbapi test connection resource warnings
Browse files Browse the repository at this point in the history
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. baztian/dbapi-compliance#5

Part of #250
  • Loading branch information
DifferentialOrange committed Oct 24, 2022
1 parent 1e89471 commit f428593
Showing 1 changed file with 40 additions and 0 deletions.
40 changes: 40 additions & 0 deletions test/suites/test_dbapi.py
Original file line number Diff line number Diff line change
Expand Up @@ -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()

0 comments on commit f428593

Please sign in to comment.