diff Lib/sqlite3/test/types.py @ 46178:e06e08e8fdce

Bring sqlite3 module up-to-date with what's now in 2.6. Almost. I intentionally left out the stuff about creating a connection object from a APSW connection.
author Gerhard Häring <gh@ghaering.de>
date Sat, 29 Mar 2008 00:45:29 +0000
parents eee1b76a94e0
children 031dfe455585
line wrap: on
line diff
--- a/Lib/sqlite3/test/types.py	Sat Mar 29 00:41:18 2008 +0000
+++ b/Lib/sqlite3/test/types.py	Sat Mar 29 00:45:29 2008 +0000
@@ -21,7 +21,7 @@
 #    misrepresented as being the original software.
 # 3. This notice may not be removed or altered from any source distribution.
 
-import bz2, datetime
+import zlib, datetime
 import unittest
 import sqlite3 as sqlite
 
@@ -221,11 +221,13 @@
         self.cur = self.con.cursor()
         self.cur.execute("create table test(x foo)")
 
-        sqlite.converters["BAR"] = lambda x: b"<" + x + b">"
+        sqlite.converters["FOO"] = lambda x: "[%s]" % x.decode("ascii")
+        sqlite.converters["BAR"] = lambda x: "<%s>" % x.decode("ascii")
         sqlite.converters["EXC"] = lambda x: 5/0
         sqlite.converters["B1B1"] = lambda x: "MARKER"
 
     def tearDown(self):
+        del sqlite.converters["FOO"]
         del sqlite.converters["BAR"]
         del sqlite.converters["EXC"]
         del sqlite.converters["B1B1"]
@@ -252,7 +254,7 @@
         self.cur.execute("insert into test(x) values (?)", ("xxx",))
         self.cur.execute('select x as "x [bar]" from test')
         val = self.cur.fetchone()[0]
-        self.failUnlessEqual(val, b"<xxx>")
+        self.failUnlessEqual(val, "<xxx>")
 
         # Check if the stripping of colnames works. Everything after the first
         # whitespace should be stripped.
@@ -297,7 +299,7 @@
 
 class BinaryConverterTests(unittest.TestCase):
     def convert(s):
-        return bz2.decompress(s)
+        return zlib.decompress(s)
     convert = staticmethod(convert)
 
     def setUp(self):
@@ -309,7 +311,7 @@
 
     def CheckBinaryInputForConverter(self):
         testdata = b"abcdefg" * 10
-        result = self.con.execute('select ? as "x [bin]"', (memoryview(bz2.compress(testdata)),)).fetchone()[0]
+        result = self.con.execute('select ? as "x [bin]"', (memoryview(zlib.compress(testdata)),)).fetchone()[0]
         self.failUnlessEqual(testdata, result)
 
 class DateTimeTests(unittest.TestCase):
@@ -341,7 +343,8 @@
         if sqlite.sqlite_version_info < (3, 1):
             return
 
-        now = datetime.datetime.utcnow()
+        # SQLite's current_timestamp uses UTC time, while datetime.datetime.now() uses local time.
+        now = datetime.datetime.now()
         self.cur.execute("insert into test(ts) values (current_timestamp)")
         self.cur.execute("select ts from test")
         ts = self.cur.fetchone()[0]