diff options
author | Daniele Varrazzo <daniele.varrazzo@gmail.com> | 2012-01-14 17:34:09 +0000 |
---|---|---|
committer | Daniele Varrazzo <daniele.varrazzo@gmail.com> | 2012-01-14 17:34:09 +0000 |
commit | 43daba38e7563ffc0369ed07211464aff597e21c (patch) | |
tree | 32145bbc5dd83f5651fc3ee36b6b8412122f06ad /tests/test_module.py | |
parent | 28f1013c2ae8c7c12f8da508c449b35c56d4b77e (diff) | |
download | psycopg2-43daba38e7563ffc0369ed07211464aff597e21c.tar.gz |
Make Error and subclasses picklable
Useful for multiprocessing interaction.
Closes ticket #90.
Diffstat (limited to 'tests/test_module.py')
-rwxr-xr-x | tests/test_module.py | 35 |
1 files changed, 34 insertions, 1 deletions
diff --git a/tests/test_module.py b/tests/test_module.py index 9c130f3..4988969 100755 --- a/tests/test_module.py +++ b/tests/test_module.py @@ -22,7 +22,8 @@ # FITNESS FOR A PARTICULAR PURPOSE. See the GNU Lesser General Public # License for more details. -from testutils import unittest +from testutils import unittest, skip_before_python +from testconfig import dsn import psycopg2 @@ -127,6 +128,38 @@ class ConnectTestCase(unittest.TestCase): self.assertEqual(self.args[0], r"dbname='\\every thing\''") +class ExceptionsTestCase(unittest.TestCase): + def setUp(self): + self.conn = psycopg2.connect(dsn) + + def tearDown(self): + self.conn.close() + + def test_attributes(self): + cur = self.conn.cursor() + try: cur.execute("select * from nonexist") + except psycopg2.Error, e: pass + + self.assertEqual(e.pgcode, '42P01') + self.assert_(e.pgerror) + self.assert_(e.cursor is cur) + + @skip_before_python(2, 5) + def test_pickle(self): + import pickle + cur = self.conn.cursor() + try: + cur.execute("select * from nonexist") + except psycopg2.Error, e: + pass + + e1 = pickle.loads(pickle.dumps(e)) + + self.assertEqual(e.pgerror, e1.pgerror) + self.assertEqual(e.pgcode, e1.pgcode) + self.assert_(e1.cursor is None) + + def test_suite(): return unittest.TestLoader().loadTestsFromName(__name__) |