]> git.ipfire.org Git - thirdparty/sqlalchemy/sqlalchemy.git/commitdiff
- additional test adjustments for pypy / psycopg2cffi. This
authorMike Bayer <mike_mp@zzzcomputing.com>
Mon, 26 Jan 2015 23:02:46 +0000 (18:02 -0500)
committerMike Bayer <mike_mp@zzzcomputing.com>
Mon, 26 Jan 2015 23:43:19 +0000 (18:43 -0500)
consists mainly of adjusting fixtures to ensure connections are closed
explicitly.  psycopg2cffi also handles unicode bind parameter
names differently than psycopg2, and seems to possibly have a little less
control over floating point values at least in one test which is
marked as a "fail", though will see if it runs differently on linux
than osx..
- changelog for psycopg2cffi, fixes #3052

doc/build/changelog/changelog_10.rst
doc/build/changelog/migration_10.rst
doc/build/dialects/postgresql.rst
lib/sqlalchemy/dialects/postgresql/psycopg2cffi.py
lib/sqlalchemy/testing/util.py
setup.cfg
test/dialect/postgresql/test_query.py
test/dialect/postgresql/test_types.py
test/engine/test_execute.py
test/requirements.py

index 18043c4567fe68e0f455f17c7e84965567d3b74e..2c3e26f2e4c63852886e0b965eafeff149529680 100644 (file)
     series as well.  For changes that are specific to 1.0 with an emphasis
     on compatibility concerns, see :doc:`/changelog/migration_10`.
 
+    .. change::
+        :tags: feature, postgresql, pypy
+        :tickets: 3052
+        :pullreq: bitbucket:34
+
+        Added support for the psycopg2cffi DBAPI on pypy.   Pull request
+        courtesy shauns.
+
+        .. seealso::
+
+            :mod:`sqlalchemy.dialects.postgresql.psycopg2cffi`
+
     .. change::
         :tags: feature, orm
         :tickets: 3262
index c0369d8b868b202dfb4d136bd9f7d09f7029ccfb..23ee6f46694e7b4a68ce4ec4eace6f2b722cd6d1 100644 (file)
@@ -1769,6 +1769,14 @@ by Postgresql as of 9.4.  SQLAlchemy allows this using
 
     :class:`.FunctionFilter`
 
+Support for psycopg2cffi Dialect on Pypy
+----------------------------------------
+
+Support for the pypy psycopg2cffi dialect is added.
+
+.. seealso::
+
+    :mod:`sqlalchemy.dialects.postgresql.psycopg2cffi`
 
 Dialect Improvements and Changes - MySQL
 =============================================
index 11bbe2cf91f62bb249028282ab9902786ceafa77..e5d8d51bc9d7d07c70e80893a6ba605362075d9e 100644 (file)
@@ -188,22 +188,24 @@ psycopg2
 
 .. automodule:: sqlalchemy.dialects.postgresql.psycopg2
 
+pg8000
+--------------
+
+.. automodule:: sqlalchemy.dialects.postgresql.pg8000
+
+psycopg2cffi
+--------------
+
+.. automodule:: sqlalchemy.dialects.postgresql.psycopg2cffi
+
 py-postgresql
 --------------------
 
 .. automodule:: sqlalchemy.dialects.postgresql.pypostgresql
 
-pg8000
---------------
-
-.. automodule:: sqlalchemy.dialects.postgresql.pg8000
 
 zxjdbc
 --------------
 
 .. automodule:: sqlalchemy.dialects.postgresql.zxjdbc
 
-psycopg2cffi
---------------
-
-.. automodule:: sqlalchemy.dialects.postgresql.psycopg2cffi
index 5217c5561318b5c6bbe790fe9da85fc79d9546cf..f5c475d90e29832b06b51a13225cbd8d90b82443 100644 (file)
@@ -1,5 +1,5 @@
 # testing/engines.py
-# Copyright (C) 2005-2014 the SQLAlchemy authors and contributors
+# Copyright (C) 2005-2015 the SQLAlchemy authors and contributors
 # <see AUTHORS file>
 #
 # This module is part of SQLAlchemy and is released under
@@ -13,9 +13,11 @@ postgresql+psycopg2cffi://user:password@host:port/dbname\
 [?key=value&key=value...]
     :url: http://pypi.python.org/pypi/psycopg2cffi/
 
-`psycopg2cffi` is an adaptation of `psycopg2`, using CFFI for the C
+``psycopg2cffi`` is an adaptation of ``psycopg2``, using CFFI for the C
 layer. This makes it suitable for use in e.g. PyPy. Documentation
-is as per `psycopg2`.
+is as per ``psycopg2``.
+
+.. versionadded:: 1.0.0
 
 .. seealso::
 
@@ -27,6 +29,7 @@ from .psycopg2 import PGDialect_psycopg2
 
 class PGDialect_psycopg2cffi(PGDialect_psycopg2):
     driver = 'psycopg2cffi'
+    supports_unicode_statements = True
 
     @classmethod
     def dbapi(cls):
index eea39b1f70370e88a2abd720fd17b9c8b25d189c..8230f923aa1f9a5593b35aac80b428e1ead32591 100644 (file)
@@ -147,6 +147,10 @@ def run_as_contextmanager(ctx, fn, *arg, **kw):
     simulating the behavior of 'with' to support older
     Python versions.
 
+    This is not necessary anymore as we have placed 2.6
+    as minimum Python version, however some tests are still using
+    this structure.
+
     """
 
     obj = ctx.__enter__()
index 5eb35469f923ec80983f65f7409b785c7735167b..dc10877f7ce73cb12a250a0e2e0618ad12aaed1b 100644 (file)
--- a/setup.cfg
+++ b/setup.cfg
@@ -42,7 +42,7 @@ postgresql=postgresql://scott:tiger@127.0.0.1:5432/test
 pg8000=postgresql+pg8000://scott:tiger@127.0.0.1:5432/test
 postgres=postgresql://scott:tiger@127.0.0.1:5432/test
 postgresql_jython=postgresql+zxjdbc://scott:tiger@127.0.0.1:5432/test
-postgresql_psycopg2cffi=postgresql+psycopg2cffi://127.0.0.1:5432/test
+postgresql_psycopg2cffi=postgresql+psycopg2cffi://scott:tiger@127.0.0.1:5432/test
 mysql=mysql://scott:tiger@127.0.0.1:3306/test
 mysqlconnector=mysql+mysqlconnector://scott:tiger@127.0.0.1:3306/test
 mssql=mssql+pyodbc://scott:tiger@ms_2008
index 73319438d25e2cb3f5fa773ef3be822833fa988a..27cb958fdc8cb9c085a8e76eedb5aa551a985472 100644 (file)
@@ -856,21 +856,23 @@ class ExtractTest(fixtures.TablesTest):
             def utcoffset(self, dt):
                 return datetime.timedelta(hours=4)
 
-        conn = testing.db.connect()
-
-        # we aren't resetting this at the moment but we don't have
-        # any other tests that are TZ specific
-        conn.execute("SET SESSION TIME ZONE 0")
-        conn.execute(
-            cls.tables.t.insert(),
-            {
-                'dtme': datetime.datetime(2012, 5, 10, 12, 15, 25),
-                'dt': datetime.date(2012, 5, 10),
-                'tm': datetime.time(12, 15, 25),
-                'intv': datetime.timedelta(seconds=570),
-                'dttz': datetime.datetime(2012, 5, 10, 12, 15, 25, tzinfo=TZ())
-            },
-        )
+        with testing.db.connect() as conn:
+
+            # we aren't resetting this at the moment but we don't have
+            # any other tests that are TZ specific
+            conn.execute("SET SESSION TIME ZONE 0")
+            conn.execute(
+                cls.tables.t.insert(),
+                {
+                    'dtme': datetime.datetime(2012, 5, 10, 12, 15, 25),
+                    'dt': datetime.date(2012, 5, 10),
+                    'tm': datetime.time(12, 15, 25),
+                    'intv': datetime.timedelta(seconds=570),
+                    'dttz':
+                            datetime.datetime(2012, 5, 10, 12, 15, 25,
+                            tzinfo=TZ())
+                },
+            )
 
     def _test(self, expr, field="all", overrides=None):
         t = self.tables.t
index 95c034f11ddac73a4cd90cba712807d4e4a88279..1f572c9a1e17469581ba0d35eb303313d086d120 100644 (file)
@@ -1399,7 +1399,7 @@ class HStoreRoundTripTest(fixtures.TablesTest):
                     use_native_hstore=False))
         else:
             engine = testing.db
-        engine.connect()
+        engine.connect().close()
         return engine
 
     def test_reflect(self):
@@ -2031,7 +2031,7 @@ class JSONRoundTripTest(fixtures.TablesTest):
             engine = engines.testing_engine(options=options)
         else:
             engine = testing.db
-        engine.connect()
+        engine.connect().close()
         return engine
 
     def test_reflect(self):
index b5b414af2417ae50fc0932b6c92cc5e2558e3cd1..730ef4446a81b1268b5f72f6e9eff33b47714154 100644 (file)
@@ -639,21 +639,21 @@ class ConvenienceExecuteTest(fixtures.TablesTest):
 
     def test_transaction_connection_ctx_commit(self):
         fn = self._trans_fn(True)
-        conn = testing.db.connect()
-        ctx = conn.begin()
-        testing.run_as_contextmanager(ctx, fn, 5, value=8)
-        self._assert_fn(5, value=8)
+        with testing.db.connect() as conn:
+            ctx = conn.begin()
+            testing.run_as_contextmanager(ctx, fn, 5, value=8)
+            self._assert_fn(5, value=8)
 
     def test_transaction_connection_ctx_rollback(self):
         fn = self._trans_rollback_fn(True)
-        conn = testing.db.connect()
-        ctx = conn.begin()
-        assert_raises_message(
-            Exception,
-            "breakage",
-            testing.run_as_contextmanager, ctx, fn, 5, value=8
-        )
-        self._assert_no_data()
+        with testing.db.connect() as conn:
+            ctx = conn.begin()
+            assert_raises_message(
+                Exception,
+                "breakage",
+                testing.run_as_contextmanager, ctx, fn, 5, value=8
+            )
+            self._assert_no_data()
 
     def test_connection_as_ctx(self):
         fn = self._trans_fn()
@@ -666,10 +666,12 @@ class ConvenienceExecuteTest(fixtures.TablesTest):
     def test_connect_as_ctx_noautocommit(self):
         fn = self._trans_fn()
         self._assert_no_data()
-        ctx = testing.db.connect().execution_options(autocommit=False)
-        testing.run_as_contextmanager(ctx, fn, 5, value=8)
-        # autocommit is off
-        self._assert_no_data()
+
+        with testing.db.connect() as conn:
+            ctx = conn.execution_options(autocommit=False)
+            testing.run_as_contextmanager(ctx, fn, 5, value=8)
+            # autocommit is off
+            self._assert_no_data()
 
     def test_transaction_engine_fn_commit(self):
         fn = self._trans_fn()
@@ -687,17 +689,17 @@ class ConvenienceExecuteTest(fixtures.TablesTest):
 
     def test_transaction_connection_fn_commit(self):
         fn = self._trans_fn()
-        conn = testing.db.connect()
-        conn.transaction(fn, 5, value=8)
-        self._assert_fn(5, value=8)
+        with testing.db.connect() as conn:
+            conn.transaction(fn, 5, value=8)
+            self._assert_fn(5, value=8)
 
     def test_transaction_connection_fn_rollback(self):
         fn = self._trans_rollback_fn()
-        conn = testing.db.connect()
-        assert_raises(
-            Exception,
-            conn.transaction, fn, 5, value=8
-        )
+        with testing.db.connect() as conn:
+            assert_raises(
+                Exception,
+                conn.transaction, fn, 5, value=8
+            )
         self._assert_no_data()
 
 
index 6b8ba504c93e38f6950fb3dd90954791ed3b9722..89fc108b9611a74117761b712783ba7f719f4ab1 100644 (file)
@@ -656,6 +656,10 @@ class DefaultRequirements(SuiteRequirements):
                         'postgresql+pg8000', None, None,
                         'postgresql+pg8000 has FP inaccuracy even with '
                         'only four decimal places '),
+                    (
+                        'postgresql+psycopg2cffi', None, None,
+                        'postgresql+psycopg2cffi has FP inaccuracy even with '
+                        'only four decimal places '),
                 ])
 
     @property