~pythonregexp2.7/python/issue2636

« back to all changes in this revision

Viewing changes to Lib/sqlite3/test/types.py

  • Committer: Jeffrey C. "The TimeHorse" Jacobs
  • Date: 2008-05-24 16:05:21 UTC
  • mfrom: (39021.1.401 Regexp-2.6)
  • Revision ID: darklord@timehorse.com-20080524160521-1xenj7p6u3wb89et
Merged in changes from the latest python source snapshot.

Show diffs side-by-side

added added

removed removed

Lines of Context:
98
98
    def setUp(self):
99
99
        self.con = sqlite.connect(":memory:", detect_types=sqlite.PARSE_DECLTYPES)
100
100
        self.cur = self.con.cursor()
101
 
        self.cur.execute("create table test(i int, s str, f float, b bool, u unicode, foo foo, bin blob)")
 
101
        self.cur.execute("create table test(i int, s str, f float, b bool, u unicode, foo foo, bin blob, n1 number, n2 number(5))")
102
102
 
103
103
        # override float, make them always return the same number
104
104
        sqlite.converters["FLOAT"] = lambda x: 47.2
107
107
        sqlite.converters["BOOL"] = lambda x: bool(int(x))
108
108
        sqlite.converters["FOO"] = DeclTypesTests.Foo
109
109
        sqlite.converters["WRONG"] = lambda x: "WRONG"
 
110
        sqlite.converters["NUMBER"] = float
110
111
 
111
112
    def tearDown(self):
112
113
        del sqlite.converters["FLOAT"]
113
114
        del sqlite.converters["BOOL"]
114
115
        del sqlite.converters["FOO"]
 
116
        del sqlite.converters["NUMBER"]
115
117
        self.cur.close()
116
118
        self.con.close()
117
119
 
203
205
        row = self.cur.fetchone()
204
206
        self.failUnlessEqual(row[0], val)
205
207
 
 
208
    def CheckNumber1(self):
 
209
        self.cur.execute("insert into test(n1) values (5)")
 
210
        value = self.cur.execute("select n1 from test").fetchone()[0]
 
211
        # if the converter is not used, it's an int instead of a float
 
212
        self.failUnlessEqual(type(value), float)
 
213
 
 
214
    def CheckNumber2(self):
 
215
        """Checks wether converter names are cut off at '(' characters"""
 
216
        self.cur.execute("insert into test(n2) values (5)")
 
217
        value = self.cur.execute("select n2 from test").fetchone()[0]
 
218
        # if the converter is not used, it's an int instead of a float
 
219
        self.failUnlessEqual(type(value), float)
 
220
 
206
221
class ColNamesTests(unittest.TestCase):
207
222
    def setUp(self):
208
223
        self.con = sqlite.connect(":memory:", detect_types=sqlite.PARSE_COLNAMES)