Ignore:
Timestamp:
Mar 19, 2014, 11:31:01 PM (11 years ago)
Author:
dmik
Message:

python: Merge vendor 2.7.6 to trunk.

Location:
python/trunk
Files:
2 edited

Legend:

Unmodified
Added
Removed
  • python/trunk

  • python/trunk/Lib/sqlite3/test/regression.py

    r2 r391  
    1 #-*- coding: ISO-8859-1 -*-
     1#-*- coding: iso-8859-1 -*-
    22# pysqlite2/test/regression.py: pysqlite regression tests
    33#
     
    6666        cur = self.con.cursor()
    6767        cur.execute('select 1 as "foo bar [datetime]"')
    68         self.failUnlessEqual(cur.description[0][0], "foo bar")
     68        self.assertEqual(cur.description[0][0], "foo bar")
    6969
    7070        cur.execute('select 1 as "foo baz"')
    71         self.failUnlessEqual(cur.description[0][0], "foo baz")
    72 
    73     def CheckStatementAvailable(self):
    74         # pysqlite up to 2.3.2 crashed on this, because the active statement handle was not checked
    75         # before trying to fetch data from it. close() destroys the active statement ...
    76         con = sqlite.connect(":memory:", detect_types=sqlite.PARSE_DECLTYPES)
    77         cur = con.cursor()
    78         cur.execute("select 4 union select 5")
    79         cur.close()
    80         cur.fetchone()
    81         cur.fetchone()
     71        self.assertEqual(cur.description[0][0], "foo baz")
    8272
    8373    def CheckStatementFinalizationOnCloseDb(self):
     
    168158                          "isolation_level", u"\xe9")
    169159
     160    def CheckCursorConstructorCallCheck(self):
     161        """
     162        Verifies that cursor methods check whether base class __init__ was
     163        called.
     164        """
     165        class Cursor(sqlite.Cursor):
     166            def __init__(self, con):
     167                pass
     168
     169        con = sqlite.connect(":memory:")
     170        cur = Cursor(con)
     171        try:
     172            cur.execute("select 4+5").fetchall()
     173            self.fail("should have raised ProgrammingError")
     174        except sqlite.ProgrammingError:
     175            pass
     176        except:
     177            self.fail("should have raised ProgrammingError")
     178
     179    def CheckConnectionConstructorCallCheck(self):
     180        """
     181        Verifies that connection methods check whether base class __init__ was
     182        called.
     183        """
     184        class Connection(sqlite.Connection):
     185            def __init__(self, name):
     186                pass
     187
     188        con = Connection(":memory:")
     189        try:
     190            cur = con.cursor()
     191            self.fail("should have raised ProgrammingError")
     192        except sqlite.ProgrammingError:
     193            pass
     194        except:
     195            self.fail("should have raised ProgrammingError")
     196
     197    def CheckCursorRegistration(self):
     198        """
     199        Verifies that subclassed cursor classes are correctly registered with
     200        the connection object, too.  (fetch-across-rollback problem)
     201        """
     202        class Connection(sqlite.Connection):
     203            def cursor(self):
     204                return Cursor(self)
     205
     206        class Cursor(sqlite.Cursor):
     207            def __init__(self, con):
     208                sqlite.Cursor.__init__(self, con)
     209
     210        con = Connection(":memory:")
     211        cur = con.cursor()
     212        cur.execute("create table foo(x)")
     213        cur.executemany("insert into foo(x) values (?)", [(3,), (4,), (5,)])
     214        cur.execute("select x from foo")
     215        con.rollback()
     216        try:
     217            cur.fetchall()
     218            self.fail("should have raised InterfaceError")
     219        except sqlite.InterfaceError:
     220            pass
     221        except:
     222            self.fail("should have raised InterfaceError")
     223
     224    def CheckAutoCommit(self):
     225        """
     226        Verifies that creating a connection in autocommit mode works.
     227        2.5.3 introduced a regression so that these could no longer
     228        be created.
     229        """
     230        con = sqlite.connect(":memory:", isolation_level=None)
     231
     232    def CheckPragmaAutocommit(self):
     233        """
     234        Verifies that running a PRAGMA statement that does an autocommit does
     235        work. This did not work in 2.5.3/2.5.4.
     236        """
     237        cur = self.con.cursor()
     238        cur.execute("create table foo(bar)")
     239        cur.execute("insert into foo(bar) values (5)")
     240
     241        cur.execute("pragma page_size")
     242        row = cur.fetchone()
     243
     244    def CheckSetDict(self):
     245        """
     246        See http://bugs.python.org/issue7478
     247
     248        It was possible to successfully register callbacks that could not be
     249        hashed. Return codes of PyDict_SetItem were not checked properly.
     250        """
     251        class NotHashable:
     252            def __call__(self, *args, **kw):
     253                pass
     254            def __hash__(self):
     255                raise TypeError()
     256        var = NotHashable()
     257        self.assertRaises(TypeError, self.con.create_function, var)
     258        self.assertRaises(TypeError, self.con.create_aggregate, var)
     259        self.assertRaises(TypeError, self.con.set_authorizer, var)
     260        self.assertRaises(TypeError, self.con.set_progress_handler, var)
     261
     262    def CheckConnectionCall(self):
     263        """
     264        Call a connection with a non-string SQL request: check error handling
     265        of the statement constructor.
     266        """
     267        self.assertRaises(sqlite.Warning, self.con, 1)
     268
     269    def CheckRecursiveCursorUse(self):
     270        """
     271        http://bugs.python.org/issue10811
     272
     273        Recursively using a cursor, such as when reusing it from a generator led to segfaults.
     274        Now we catch recursive cursor usage and raise a ProgrammingError.
     275        """
     276        con = sqlite.connect(":memory:")
     277
     278        cur = con.cursor()
     279        cur.execute("create table a (bar)")
     280        cur.execute("create table b (baz)")
     281
     282        def foo():
     283            cur.execute("insert into a (bar) values (?)", (1,))
     284            yield 1
     285
     286        with self.assertRaises(sqlite.ProgrammingError):
     287            cur.executemany("insert into b (baz) values (?)",
     288                            ((i,) for i in foo()))
     289
     290    def CheckConvertTimestampMicrosecondPadding(self):
     291        """
     292        http://bugs.python.org/issue14720
     293
     294        The microsecond parsing of convert_timestamp() should pad with zeros,
     295        since the microsecond string "456" actually represents "456000".
     296        """
     297
     298        con = sqlite.connect(":memory:", detect_types=sqlite.PARSE_DECLTYPES)
     299        cur = con.cursor()
     300        cur.execute("CREATE TABLE t (x TIMESTAMP)")
     301
     302        # Microseconds should be 456000
     303        cur.execute("INSERT INTO t (x) VALUES ('2012-04-04 15:06:00.456')")
     304
     305        # Microseconds should be truncated to 123456
     306        cur.execute("INSERT INTO t (x) VALUES ('2012-04-04 15:06:00.123456789')")
     307
     308        cur.execute("SELECT * FROM t")
     309        values = [x[0] for x in cur.fetchall()]
     310
     311        self.assertEqual(values, [
     312            datetime.datetime(2012, 4, 4, 15, 6, 0, 456000),
     313            datetime.datetime(2012, 4, 4, 15, 6, 0, 123456),
     314        ])
     315
    170316
    171317def suite():
Note: See TracChangeset for help on using the changeset viewer.