Added test to verify _psycopg can be imported

This commit is contained in:
Daniele Varrazzo 2014-08-26 03:42:34 +01:00
parent 54d904138d
commit ea54aa77ed
2 changed files with 28 additions and 1 deletions

2
NEWS
View File

@ -24,6 +24,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

View File

@ -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__)