]> git.ipfire.org Git - thirdparty/sqlalchemy/sqlalchemy.git/commitdiff
o don't need to str() Jython arrays twice
authorPhilip Jenvey <pjenvey@underboss.org>
Sat, 12 Sep 2009 00:18:06 +0000 (00:18 +0000)
committerPhilip Jenvey <pjenvey@underboss.org>
Sat, 12 Sep 2009 00:18:06 +0000 (00:18 +0000)
o map the Binary types w/ new str handling in mssql's BinaryTest.test_binary

lib/sqlalchemy/types.py
test/dialect/test_mssql.py

index 9a35e1a4af302d6ca05ed72855e58181baf675ab..cdd5439db8f474a39a6f7e5a773bc6d073473ea4 100644 (file)
@@ -782,7 +782,7 @@ class Binary(TypeEngine):
         def process(value):
             if value is not None:
                 if util.jython and isinstance(value, array.array):
-                    value = value.tostring()
+                    return value.tostring()
                 return str(value)
             else:
                 return None
index 013170ed2018cfafdf9c1d46e76f5bbd1fdcbc24..ddb57c5b924385005c9bea0efcf3de70524c82cf 100644 (file)
@@ -1175,8 +1175,8 @@ class BinaryTest(TestBase, AssertsExecutionResults):
         testobj2 = pickleable.Foo('im foo 2')
         testobj3 = pickleable.Foo('im foo 3')
 
-        stream1 =self.load_stream('binary_data_one.dat')
-        stream2 =self.load_stream('binary_data_two.dat')
+        stream1 = self.load_stream('binary_data_one.dat')
+        stream2 = self.load_stream('binary_data_two.dat')
         binary_table.insert().execute(primary_id=1, misc='binary_data_one.dat', data=stream1, data_image=stream1, data_slice=stream1[0:100], pickled=testobj1, mypickle=testobj3)
         binary_table.insert().execute(primary_id=2, misc='binary_data_two.dat', data=stream2, data_image=stream2, data_slice=stream2[0:99], pickled=testobj2)
         
@@ -1188,7 +1188,10 @@ class BinaryTest(TestBase, AssertsExecutionResults):
 
         for stmt in (
             binary_table.select(order_by=binary_table.c.primary_id),
-            text("select * from binary_table order by binary_table.primary_id", typemap={'pickled':PickleType, 'mypickle':MyPickleType}, bind=testing.db)
+            text("select * from binary_table order by binary_table.primary_id",
+                 typemap=dict(data=mssql.MSVarBinary(8000), data_image=mssql.MSImage,
+                              data_slice=Binary(100), pickled=PickleType, mypickle=MyPickleType),
+                 bind=testing.db)
         ):
             l = stmt.execute().fetchall()
             eq_(list(stream1), list(l[0]['data']))
@@ -1205,7 +1208,7 @@ class BinaryTest(TestBase, AssertsExecutionResults):
             eq_(l[0]['mypickle'].stuff, 'this is the right stuff')
 
     def load_stream(self, name, len=3000):
-        f = os.path.join(os.path.dirname(__file__), "..", name)
-        return file(f, 'rb').read(len)
-
-
+        fp = open(os.path.join(os.path.dirname(__file__), "..", name), 'rb')
+        stream = fp.read(len)
+        fp.close()
+        return stream