Split the binary tests out a bit.

This commit is contained in:
James Henstridge 2008-01-16 18:08:12 +00:00
parent f64cbeda46
commit bc663111b6

View File

@ -13,14 +13,14 @@
# or FITNESS FOR A PARTICULAR PURPOSE. See the GNU General Public License # or FITNESS FOR A PARTICULAR PURPOSE. See the GNU General Public License
# for more details. # for more details.
import sys
try: try:
import decimal import decimal
except: except:
pass pass
import psycopg2 import sys
import unittest import unittest
import psycopg2
import tests import tests
@ -65,11 +65,17 @@ class TypesBasicTests(unittest.TestCase):
b = psycopg2.Binary(s) b = psycopg2.Binary(s)
buf = self.execute("SELECT %s::bytea AS foo", (b,)) buf = self.execute("SELECT %s::bytea AS foo", (b,))
self.failUnless(str(buf) == s, "wrong binary quoting") self.failUnless(str(buf) == s, "wrong binary quoting")
def testBinaryEmptyString(self):
# test to make sure an empty Binary is converted to an empty string # test to make sure an empty Binary is converted to an empty string
b = psycopg2.Binary('') b = psycopg2.Binary('')
self.assertEqual(str(b), "''") self.assertEqual(str(b), "''")
def testBinaryRoundTrip(self):
# test to make sure buffers returned by psycopg2 are # test to make sure buffers returned by psycopg2 are
# understood by execute: # understood by execute:
s = ''.join([chr(x) for x in range(256)])
buf = self.execute("SELECT %s::bytea AS foo", (psycopg2.Binary(s),))
buf2 = self.execute("SELECT %s::bytea AS foo", (buf,)) buf2 = self.execute("SELECT %s::bytea AS foo", (buf,))
self.failUnless(str(buf2) == s, "wrong binary quoting") self.failUnless(str(buf2) == s, "wrong binary quoting")