def random_update_order_parameters(): from sqlalchemy import ARRAY t = table( "foo", column("data1", ARRAY(Integer)), column("data2", ARRAY(Integer)), column("data3", ARRAY(Integer)), column("data4", ARRAY(Integer)), ) idx_to_value = [ (t.c.data1, 5, 7), (t.c.data2, 10, 18), (t.c.data3, 8, 4), (t.c.data4, 12, 14), ] def combinations(): while True: random.shuffle(idx_to_value) yield list(idx_to_value) return testing.combinations(*[ (t, combination) for i, combination in zip(range(10), combinations()) ], argnames="t, idx_to_value")
class EncodingErrorsTest(fixtures.TestBase): """mock test for encoding_errors. While we tried to write a round trip test, I could only reproduce the problem on Python 3 and only for STRING/CHAR. I couldn't get a CLOB to come back with broken encoding and also under py2k cx_Oracle would always return a bytestring with the correct encoding. Since the test barely worked, it is not included here to avoid future problems. It's not clear what other levels of encode/decode are going on such that explicitly selecting for AL16UTF16 is still returning a utf-8 bytestring under py2k or for CLOBs, nor is it really clear that this flag is useful, however, at least for the Py3K case, cx_Oracle supports the flag and we did have one user reporting that they had a (non-reproducible) database which illustrated the problem so we will pass it in. """ # NOTE: these numbers are arbitrary, they are not the actual # cx_Oracle constants cx_Oracle_NUMBER = 0 cx_Oracle_STRING = 1 cx_Oracle_FIXED_CHAR = 2 cx_Oracle_CLOB = 3 cx_Oracle_NCLOB = 4 @testing.fixture def cx_Oracle(self): return mock.Mock( NUMBER=self.cx_Oracle_NUMBER, STRING=self.cx_Oracle_STRING, FIXED_CHAR=self.cx_Oracle_FIXED_CHAR, CLOB=self.cx_Oracle_CLOB, NCLOB=self.cx_Oracle_NCLOB, version="7.0.1", __future__=mock.Mock(), ) _oracle_char_combinations = testing.combinations( ( "STRING", cx_Oracle_STRING, ), ( "FIXED_CHAR", cx_Oracle_FIXED_CHAR, ), ( "CLOB", cx_Oracle_CLOB, ), ( "NCLOB", cx_Oracle_NCLOB, ), argnames="cx_oracle_type", id_="ia", ) def _assert_errorhandler(self, outconverter, has_errorhandler): data = "\uee2c\u9a66" # this is u"\uee2c\u9a66" utf8_w_errors = data.encode("utf-16") if has_errorhandler: eq_( outconverter(utf8_w_errors), data.encode("utf-16").decode("utf-8", "ignore"), ) else: assert_raises(UnicodeDecodeError, outconverter, utf8_w_errors) @_oracle_char_combinations def test_encoding_errors_cx_oracle( self, cx_Oracle, cx_oracle_type, ): ignore_dialect = cx_oracle.dialect(dbapi=cx_Oracle, encoding_errors="ignore") ignore_outputhandler = ( ignore_dialect._generate_connection_outputtype_handler()) cursor = mock.Mock() ignore_outputhandler(cursor, "foo", cx_oracle_type, None, None, None) eq_( cursor.mock_calls, [ mock.call.var( mock.ANY, None, cursor.arraysize, encodingErrors="ignore", ) ], ) @_oracle_char_combinations def test_no_encoding_errors_cx_oracle( self, cx_Oracle, cx_oracle_type, ): plain_dialect = cx_oracle.dialect(dbapi=cx_Oracle) plain_outputhandler = ( plain_dialect._generate_connection_outputtype_handler()) cursor = mock.Mock() plain_outputhandler(cursor, "foo", cx_oracle_type, None, None, None) if cx_oracle_type in (cx_Oracle.FIXED_CHAR, cx_Oracle.STRING): # no calls; without encodingErrors, use cx_Oracle's default unicode # handling eq_( cursor.mock_calls, [], ) else: eq_( cursor.mock_calls, [mock.call.var(mock.ANY, None, cursor.arraysize)], )
def _cases(): return testing.combinations( (orm_util, ), (Session, ), )
def _cases(): return testing.combinations((orm_util, ), (Session, ), argnames="ormutil")