Permalink
Browse files

Adding an is_clsoed method to the db to check conn state

  • Loading branch information...
1 parent 269b566 commit 53473bae4990a29752469510e505097a011dc7e5 @coleifer committed Aug 13, 2012
Showing with 13 additions and 0 deletions.
  1. +3 −0 peewee.py
  2. +10 −0 tests.py
View
@@ -321,6 +321,9 @@ def get_conn(self):
self.connect()
return self.__local.conn
+ def is_closed(self):
+ return getattr(self.__local, 'closed', True)
+
def get_cursor(self):
return self.get_conn().cursor()
View
@@ -3652,6 +3652,16 @@ def do_will_succeed2():
self.assertEqual(Entry.select().count(), 2)
+class ConnectionStateTestCase(BasePeeweeTestCase):
+ def test_connection_state(self):
+ conn = test_db.get_conn()
+ self.assertFalse(test_db.is_closed())
+ test_db.close()
+ self.assertTrue(test_db.is_closed())
+ conn = test_db.get_conn()
+ self.assertFalse(test_db.is_closed())
+
+
if test_db.adapter.for_update_support:
class ForUpdateTestCase(BaseModelTestCase):
def tearDown(self):

0 comments on commit 53473ba

Please sign in to comment.