]> git.ipfire.org Git - thirdparty/sqlalchemy/sqlalchemy.git/commitdiff
- repair laziness about setting time zone here, which is leaking
authorMike Bayer <mike_mp@zzzcomputing.com>
Sun, 11 Oct 2015 16:00:39 +0000 (12:00 -0400)
committerMike Bayer <mike_mp@zzzcomputing.com>
Sun, 11 Oct 2015 16:00:39 +0000 (12:00 -0400)
out depending on connection pool state

test/dialect/postgresql/test_query.py

index 6c10d78cc3b7e1f8e7bc2fa5085364a03def33af..b71cdedebd68be01b9f7e0bfcb799c1033d681f6 100644 (file)
@@ -841,6 +841,19 @@ class ExtractTest(fixtures.TablesTest):
     run_inserts = 'once'
     run_deletes = None
 
+    @classmethod
+    def setup_bind(cls):
+        from sqlalchemy import event
+        eng = engines.testing_engine()
+
+        @event.listens_for(eng, "connect")
+        def connect(dbapi_conn, rec):
+            cursor = dbapi_conn.cursor()
+            cursor.execute("SET SESSION TIME ZONE 0")
+            cursor.close()
+
+        return eng
+
     @classmethod
     def define_tables(cls, metadata):
         Table('t', metadata,
@@ -861,12 +874,7 @@ class ExtractTest(fixtures.TablesTest):
             def utcoffset(self, dt):
                 return datetime.timedelta(hours=4)
 
-        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.bind.execute(
                 cls.tables.t.insert(),
                 {
                     'dtme': datetime.datetime(2012, 5, 10, 12, 15, 25),
@@ -903,7 +911,7 @@ class ExtractTest(fixtures.TablesTest):
             fields.update(overrides)
 
         for field in fields:
-            result = testing.db.scalar(
+            result = self.bind.scalar(
                 select([extract(field, expr)]).select_from(t))
             eq_(result, fields[field])
 
@@ -919,7 +927,7 @@ class ExtractTest(fixtures.TablesTest):
     def test_three(self):
         t = self.tables.t
 
-        actual_ts = testing.db.scalar(func.current_timestamp()) - \
+        actual_ts = self.bind.scalar(func.current_timestamp()) - \
             datetime.timedelta(days=5)
         self._test(func.current_timestamp() - datetime.timedelta(days=5),
                    {"hour": actual_ts.hour, "year": actual_ts.year,
@@ -968,7 +976,7 @@ class ExtractTest(fixtures.TablesTest):
 
     def test_twelve(self):
         t = self.tables.t
-        actual_ts = testing.db.scalar(
+        actual_ts = self.bind.scalar(
             func.current_timestamp()).replace(tzinfo=None) - \
             datetime.datetime(2012, 5, 10, 12, 15, 25)