From 3dad8344c03c66842e3f7630d554200c4d316708 Mon Sep 17 00:00:00 2001 From: Daniele Varrazzo Date: Tue, 26 Aug 2014 03:42:34 +0100 Subject: [PATCH] Added test to verify _psycopg can be imported --- NEWS | 2 ++ tests/test_module.py | 27 ++++++++++++++++++++++++++- 2 files changed, 28 insertions(+), 1 deletion(-) diff --git a/NEWS b/NEWS index 2f71a374..4240045e 100644 --- a/NEWS +++ b/NEWS @@ -15,6 +15,8 @@ What's new in psycopg 2.5.4 - Don't ignore silently the `cursor.callproc` argument without a length. - Added a few errors missing from `~psycopg2.errorcodes`, defined by PostgreSQL but not documented. +- Make sure the internal `_psycopg.so` module can be imported stand-alone + (to allow modules juggling such as the one described in :ticket:`#201`). What's new in psycopg 2.5.3 diff --git a/tests/test_module.py b/tests/test_module.py index b2f5279d..608f703d 100755 --- a/tests/test_module.py +++ b/tests/test_module.py @@ -22,8 +22,12 @@ # FITNESS FOR A PARTICULAR PURPOSE. See the GNU Lesser General Public # License for more details. +import os +import sys +from subprocess import Popen + from testutils import unittest, skip_before_python, skip_before_postgres -from testutils import ConnectingTestCase, skip_copy_if_green +from testutils import ConnectingTestCase, skip_copy_if_green, script_to_py3 import psycopg2 @@ -295,6 +299,27 @@ class ExceptionsTestCase(ConnectingTestCase): self.assert_(e1.cursor is None) +class TestExtensionModule(unittest.TestCase): + def test_import_internal(self): + # check that the internal package can be imported "naked" + # we may break this property if there is a compelling reason to do so, + # however having it allows for some import juggling such as the one + # required in ticket #201. + pkgdir = os.path.dirname(psycopg2.__file__) + pardir = os.path.dirname(pkgdir) + self.assert_(pardir in sys.path) + script = (""" +import sys +sys.path.remove(%r) +sys.path.insert(0, %r) +import _psycopg +""" % (pardir, pkgdir)) + + proc = Popen([sys.executable, '-c', script_to_py3(script)]) + proc.communicate() + self.assertEqual(0, proc.returncode) + + def test_suite(): return unittest.TestLoader().loadTestsFromName(__name__)