def test_raw_roundtrip(self): metadata = self.metadata raw_table = Table('raw', metadata, Column('id', Integer, primary_key=True), Column('data', oracle.RAW(35))) metadata.create_all() testing.db.execute(raw_table.insert(), id=1, data=b("ABCDEF")) eq_( testing.db.execute(raw_table.select()).first(), (1, b("ABCDEF")) )
def test_nonunicode_default(self): default = b('foo') assert_raises_message( sa.exc.SAWarning, "Unicode column received non-unicode default value.", Column, Unicode(32), default=default )
def test_nonunicode_default(self): default = b('foo') assert_raises_message( sa.exc.SAWarning, "Unicode column 'foobar' has non-unicode " "default value b?'foo' specified.", Column, "foobar", Unicode(32), default=default )
def test_unicode_warnings_dialectlevel(self): unicodedata = self.data with testing.expect_deprecated( "The create_engine.convert_unicode parameter and " "corresponding dialect-level" ): dialect = default.DefaultDialect(convert_unicode=True) dialect.supports_unicode_binds = False s = String() uni = s.dialect_impl(dialect).bind_processor(dialect) uni(util.b("x")) assert isinstance(uni(unicodedata), util.binary_type) eq_(uni(unicodedata), unicodedata.encode("utf-8"))
def insert_data(cls): cls.data = data = [ dict( id=i, data='this is text %d' % i, bindata=b('this is binary %d' % i) ) for i in range(1, 20) ] testing.db.execute(cls.tables.z_test.insert(), data) binary_table = cls.tables.binary_table fname = os.path.join( os.path.dirname(__file__), "..", "..", 'binary_data_one.dat') with open(fname, "rb") as file_: cls.stream = stream = file_.read(12000) for i in range(1, 11): binary_table.insert().execute(id=i, data=stream)
def test_character_binary(self): self._test_round_trip(mssql.MSVarBinary(800), b("some normal data"))
def test_lobs_with_convert_raw(self): row = testing.db.execute("select data, bindata from z_test").first() eq_(row["data"], "this is text 1") eq_(row["bindata"], b("this is binary 1"))
def test_lobs_with_convert_raw(self): row = testing.db.execute("select data, bindata from z_test").first() eq_(row['data'], 'this is text 1') eq_(row['bindata'], b('this is binary 1'))
def test_lobs_without_convert(self): engine = testing_engine(options=dict(auto_convert_lobs=False)) t = self.tables.z_test row = engine.execute(t.select().where(t.c.id == 1)).first() eq_(row['data'].read(), 'this is text 1') eq_(row['bindata'].read(), b('this is binary 1'))
def test_lobs_with_convert(self): t = self.tables.z_test row = testing.db.execute(t.select().where(t.c.id == 1)).first() eq_(row['data'], 'this is text 1') eq_(row['bindata'], b('this is binary 1'))
def test_lobs_with_convert_raw(self, connection): row = exec_sql(connection, "select data, bindata from z_test").first() eq_(row["data"], "this is text 1") eq_(row["bindata"], b("this is binary 1"))
def test_bytes(self): module = __import__('pymssql') input = b('\x80\x03]q\x00X\x03\x00\x00\x00oneq\x01a.') expected_result = input result = module.Binary(input) eq_(result, expected_result)
def test_lobs_with_convert(self, connection): t = self.tables.z_test row = connection.execute(t.select().where(t.c.id == 1)).first() eq_(row["data"], "this is text 1") eq_(row["bindata"], b("this is binary 1"))
def test_lobs_with_convert(self): t = self.tables.z_test row = testing.db.execute(t.select().where(t.c.id == 1)).first() eq_(row["data"], "this is text 1") eq_(row["bindata"], b("this is binary 1"))
class BinaryTest(fixtures.TestBase): __only_on__ = "mssql" __requires__ = ("non_broken_binary", ) __backend__ = True @testing.combinations( ( mssql.MSVarBinary(800), b("some normal data"), None, True, None, False, ), ( mssql.VARBINARY("max"), "binary_data_one.dat", None, False, None, False, ), ( mssql.VARBINARY("max"), "binary_data_one.dat", None, True, None, False, ), ( sqltypes.LargeBinary, "binary_data_one.dat", None, False, None, False, ), (sqltypes.LargeBinary, "binary_data_one.dat", None, True, None, False), (mssql.MSImage, "binary_data_one.dat", None, True, None, False), (PickleType, pickleable.Foo("im foo 1"), None, True, None, False), ( MyPickleType, pickleable.Foo("im foo 1"), pickleable.Foo("im foo 1", stuff="BINDim stuffRESULT"), True, None, False, ), (types.BINARY(100), "binary_data_one.dat", None, True, 100, False), (types.VARBINARY(100), "binary_data_one.dat", None, True, 100, False), (mssql.VARBINARY(100), "binary_data_one.dat", None, True, 100, False), (types.BINARY(100), "binary_data_two.dat", None, True, 99, True), (types.VARBINARY(100), "binary_data_two.dat", None, True, 99, False), (mssql.VARBINARY(100), "binary_data_two.dat", None, True, 99, False), argnames="type_, data, expected, deprecate_large_types, " "slice_, zeropad", ) def test_round_trip( self, metadata, type_, data, expected, deprecate_large_types, slice_, zeropad, ): if (testing.db.dialect.deprecate_large_types is not deprecate_large_types): engine = engines.testing_engine( options={"deprecate_large_types": deprecate_large_types}) else: engine = testing.db binary_table = Table( "binary_table", metadata, Column("id", Integer, primary_key=True), Column("data", type_), ) binary_table.create(engine) if isinstance(data, str) and (data == "binary_data_one.dat" or data == "binary_data_two.dat"): data = self._load_stream(data) if slice_ is not None: data = data[0:slice_] if expected is None: if zeropad: expected = data[0:slice_] + b"\x00" else: expected = data with engine.begin() as conn: conn.execute(binary_table.insert(), dict(data=data)) eq_(conn.scalar(select(binary_table.c.data)), expected) eq_( conn.scalar( text("select data from binary_table").columns( binary_table.c.data)), expected, ) conn.execute(binary_table.delete()) conn.execute(binary_table.insert(), dict(data=None)) eq_(conn.scalar(select(binary_table.c.data)), None) eq_( conn.scalar( text("select data from binary_table").columns( binary_table.c.data)), None, ) def _load_stream(self, name, len_=3000): fp = open(os.path.join(os.path.dirname(__file__), "..", "..", name), "rb") stream = fp.read(len_) fp.close() return stream