mirror of
https://github.com/psycopg/psycopg2.git
synced 2024-11-23 01:16:34 +03:00
3265dd172d
the Connection and Cursor "closed" attributes. * psycopg/cursor_type.c (psyco_curs_get_closed): add a "closed" attribute to cursors. It will be True if either the cursor or its associated connection are closed. This fixes bug #164.
35 lines
817 B
Python
35 lines
817 B
Python
#!/usr/bin/env python
|
|
import unittest
|
|
|
|
import psycopg2
|
|
import tests
|
|
|
|
|
|
class ConnectionTests(unittest.TestCase):
|
|
|
|
def connect(self):
|
|
return psycopg2.connect("dbname=%s" % tests.dbname)
|
|
|
|
def test_closed_attribute(self):
|
|
conn = self.connect()
|
|
self.assertEqual(conn.closed, False)
|
|
conn.close()
|
|
self.assertEqual(conn.closed, True)
|
|
|
|
def test_cursor_closed_attribute(self):
|
|
conn = self.connect()
|
|
curs = conn.cursor()
|
|
self.assertEqual(curs.closed, False)
|
|
curs.close()
|
|
self.assertEqual(curs.closed, True)
|
|
|
|
# Closing the connection closes the cursor:
|
|
curs = conn.cursor()
|
|
conn.close()
|
|
self.assertEqual(curs.closed, True)
|
|
|
|
|
|
def test_suite():
|
|
return unittest.TestLoader().loadTestsFromName(__name__)
|
|
|