Skip to content

Commit f428593

Browse files
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. baztian/dbapi-compliance#5 Part of #250
1 parent 1e89471 commit f428593

File tree

1 file changed

+40
-0
lines changed

1 file changed

+40
-0
lines changed

Diff for: test/suites/test_dbapi.py

+40
Original file line numberDiff line numberDiff line change
@@ -127,3 +127,43 @@ def test_setoutputsize(self): # Do nothing
127127
@unittest.skip('Not implemented')
128128
def test_description(self):
129129
pass
130+
131+
def test_ExceptionsAsConnectionAttributes(self):
132+
# Workaround for https://github.com/baztian/dbapi-compliance/issues/5
133+
134+
# OPTIONAL EXTENSION
135+
# Test for the optional DB API 2.0 extension, where the exceptions
136+
# are exposed as attributes on the Connection object
137+
# I figure this optional extension will be implemented by any
138+
# driver author who is using this test suite, so it is enabled
139+
# by default.
140+
drv = self.driver
141+
con = self._connect()
142+
try:
143+
dbapi20._failUnless(self,con.Warning is drv.Warning)
144+
dbapi20._failUnless(self,con.Error is drv.Error)
145+
dbapi20._failUnless(self,con.InterfaceError is drv.InterfaceError)
146+
dbapi20._failUnless(self,con.DatabaseError is drv.DatabaseError)
147+
dbapi20._failUnless(self,con.OperationalError is drv.OperationalError)
148+
dbapi20._failUnless(self,con.IntegrityError is drv.IntegrityError)
149+
dbapi20._failUnless(self,con.InternalError is drv.InternalError)
150+
dbapi20._failUnless(self,con.ProgrammingError is drv.ProgrammingError)
151+
dbapi20. _failUnless(self,con.NotSupportedError is drv.NotSupportedError)
152+
finally:
153+
con.close()
154+
155+
156+
def test_rollback(self):
157+
# Workaround for https://github.com/baztian/dbapi-compliance/issues/5
158+
159+
con = self._connect()
160+
try:
161+
# If rollback is defined, it should either work or throw
162+
# the documented exception
163+
if hasattr(con,'rollback'):
164+
try:
165+
con.rollback()
166+
except self.driver.NotSupportedError:
167+
pass
168+
finally:
169+
con.close()

0 commit comments

Comments
 (0)