|
21 | 21 | # misrepresented as being the original software. |
22 | 22 | # 3. This notice may not be removed or altered from any source distribution. |
23 | 23 |
|
24 | | -import datetime |
| 24 | +import bz2, datetime |
25 | 25 | import unittest |
26 | 26 | import sqlite3 as sqlite |
27 | 27 |
|
@@ -273,6 +273,23 @@ def CheckCasterIsUsed(self): |
273 | 273 | val = self.cur.fetchone()[0] |
274 | 274 | self.failUnlessEqual(type(val), float) |
275 | 275 |
|
| 276 | +class BinaryConverterTests(unittest.TestCase): |
| 277 | + def convert(s): |
| 278 | + return bz2.decompress(s) |
| 279 | + convert = staticmethod(convert) |
| 280 | + |
| 281 | + def setUp(self): |
| 282 | + self.con = sqlite.connect(":memory:", detect_types=sqlite.PARSE_COLNAMES) |
| 283 | + sqlite.register_converter("bin", BinaryConverterTests.convert) |
| 284 | + |
| 285 | + def tearDown(self): |
| 286 | + self.con.close() |
| 287 | + |
| 288 | + def CheckBinaryInputForConverter(self): |
| 289 | + testdata = "abcdefg" * 10 |
| 290 | + result = self.con.execute('select ? as "x [bin]"', (buffer(bz2.compress(testdata)),)).fetchone()[0] |
| 291 | + self.failUnlessEqual(testdata, result) |
| 292 | + |
276 | 293 | class DateTimeTests(unittest.TestCase): |
277 | 294 | def setUp(self): |
278 | 295 | self.con = sqlite.connect(":memory:", detect_types=sqlite.PARSE_DECLTYPES) |
@@ -322,8 +339,9 @@ def suite(): |
322 | 339 | decltypes_type_suite = unittest.makeSuite(DeclTypesTests, "Check") |
323 | 340 | colnames_type_suite = unittest.makeSuite(ColNamesTests, "Check") |
324 | 341 | adaptation_suite = unittest.makeSuite(ObjectAdaptationTests, "Check") |
| 342 | + bin_suite = unittest.makeSuite(BinaryConverterTests, "Check") |
325 | 343 | date_suite = unittest.makeSuite(DateTimeTests, "Check") |
326 | | - return unittest.TestSuite((sqlite_type_suite, decltypes_type_suite, colnames_type_suite, adaptation_suite, date_suite)) |
| 344 | + return unittest.TestSuite((sqlite_type_suite, decltypes_type_suite, colnames_type_suite, adaptation_suite, bin_suite, date_suite)) |
327 | 345 |
|
328 | 346 | def test(): |
329 | 347 | runner = unittest.TextTestRunner() |
|
0 commit comments