From: Mike Bayer Date: Sat, 10 Oct 2009 16:14:13 +0000 (+0000) Subject: - unit test fixes X-Git-Tag: rel_0_6beta1~263 X-Git-Url: http://git.ipfire.org/cgi-bin/gitweb.cgi?a=commitdiff_plain;h=9bab004a9b9e9d6d6d0f1ce8b173309279350fc0;p=thirdparty%2Fsqlalchemy%2Fsqlalchemy.git - unit test fixes - py3k readme - removed column.sequence accessor --- diff --git a/CHANGES b/CHANGES index 1c2b913c4d..c52d94d3c3 100644 --- a/CHANGES +++ b/CHANGES @@ -152,7 +152,8 @@ CHANGES table.append_constraint(PrimaryKeyConstraint(...)) - Column.bind (get via column.table.bind) - Column.metadata (get via column.table.metadata) - + - Column.sequence (use column.default) + - The use_alter flag on ForeignKey is now a shortcut option for operations that can be hand-constructed using the DDL() event system. A side effect of this refactor is diff --git a/README.py3k b/README.py3k new file mode 100644 index 0000000000..c43ec6827b --- /dev/null +++ b/README.py3k @@ -0,0 +1,39 @@ +================= +PYTHON 3 SUPPORT +================= + +Current Python 3k support in SQLAlchemy is provided by a customized +2to3 script which wraps Python's 2to3 tool. + +This document will refer to the Python 2.6 interpreter binary as +"python26" and the Python 3.xx interpreter binary as "python3". + +To build the Python 3K version, use the Python 2.6 interpreter to +run the 2to3 script on the lib/ directory, and optionally the test/ +directory. The -w flag indicates that the new files should be +written. + + python26 sa2to3.py ./lib/ ./test/ -w + +You now have a Python 3 version of SQLAlchemy in lib/. + + +Running Tests +------------- + +The unit test runner, described in README.unittests, is built on +Nose, and uses a plugin that is ordinarily installed using setuptools +entry points. At the time of this writing setuptools isn't available +for Python 3 although the "Distribute" project does seem to provide support. +Additionally, Nose itself is only available in an old version for Python 3, +which is available at http://bitbucket.org/jpellerin/nose3/ . + +To run the unit tests using the old version of nose and without the usage of +setuptools, use the "sqla_nose.py" script: + + python3 sqla_nose.py + +When running with Python 3, lots of debug output is dumped to the console. +This is due to hacking around the old version of Nose to support the +SQLAlchemy test plugin without setuptools (details at +http://groups.google.com/group/nose-dev/browse_thread/thread/c6a25531baaa2531). \ No newline at end of file diff --git a/lib/sqlalchemy/dialects/oracle/cx_oracle.py b/lib/sqlalchemy/dialects/oracle/cx_oracle.py index 721c455884..65f3cb928a 100644 --- a/lib/sqlalchemy/dialects/oracle/cx_oracle.py +++ b/lib/sqlalchemy/dialects/oracle/cx_oracle.py @@ -123,9 +123,12 @@ class _OracleTimestamp(sqltypes.TIMESTAMP): class _LOBMixin(object): def result_processor(self, dialect): - super_process = super(_LOBMixin, self).result_processor(dialect) if not dialect.auto_convert_lobs: - return super_process + # return the cx_oracle.LOB directly. + # don't even call super.result_processor here. + return None + + super_process = super(_LOBMixin, self).result_processor(dialect) lob = dialect.dbapi.LOB def process(value): if isinstance(value, lob): diff --git a/lib/sqlalchemy/schema.py b/lib/sqlalchemy/schema.py index dc212ccac3..b91764da12 100644 --- a/lib/sqlalchemy/schema.py +++ b/lib/sqlalchemy/schema.py @@ -642,7 +642,7 @@ class Column(SchemaItem, expression.ColumnClause): self._table_events = set() if self.default is not None: - if isinstance(self.default, ColumnDefault): + if isinstance(self.default, (ColumnDefault, Sequence)): args.append(self.default) else: args.append(ColumnDefault(self.default)) @@ -1152,7 +1152,7 @@ class Sequence(DefaultGenerator): def _set_parent(self, column): super(Sequence, self)._set_parent(column) - column.sequence = self +# column.sequence = self column._on_table_attach(self._set_table) diff --git a/test/engine/test_metadata.py b/test/engine/test_metadata.py index 2b751db263..2612f10293 100644 --- a/test/engine/test_metadata.py +++ b/test/engine/test_metadata.py @@ -1,8 +1,7 @@ from sqlalchemy.test.testing import assert_raises, assert_raises_message import pickle -from sqlalchemy import Integer, String, UniqueConstraint, CheckConstraint, ForeignKey, MetaData -from sqlalchemy.test.schema import Table -from sqlalchemy.test.schema import Column +from sqlalchemy import Integer, String, UniqueConstraint, CheckConstraint, ForeignKey, MetaData, Sequence +from sqlalchemy.test.schema import Table, Column from sqlalchemy import schema import sqlalchemy as tsa from sqlalchemy.test import TestBase, ComparesTables, AssertsCompiledSQL, testing, engines @@ -38,7 +37,7 @@ class MetaDataTest(TestBase, ComparesTables): assert str(e) == "Table 'table1' is already defined for this MetaData instance. Specify 'useexisting=True' to redefine options and columns on an existing Table object." finally: metadata.drop_all() - + @testing.exclude('mysql', '<', (4, 1, 1), 'early types are squirrely') def test_to_metadata(self): meta = MetaData() @@ -54,7 +53,7 @@ class MetaDataTest(TestBase, ComparesTables): ) table2 = Table('othertable', meta, - Column('id', Integer, primary_key=True), + Column('id', Integer, Sequence('foo_seq'), primary_key=True), Column('myid', Integer, ForeignKey('mytable.myid')), test_needs_fk=True, ) @@ -100,7 +99,8 @@ class MetaDataTest(TestBase, ComparesTables): assert str(table_c.c.foo.server_onupdate.arg) == 'q' assert str(table_c.c.bar.default.arg) == 'y' assert getattr(table_c.c.bar.onupdate.arg, 'arg', table_c.c.bar.onupdate.arg) == 'z' - + assert isinstance(table2_c.c.id.default, Sequence) + # constraints dont get reflected for any dialect right now if has_constraints: for c in table_c.c.description.constraints: diff --git a/test/ext/test_declarative.py b/test/ext/test_declarative.py index 066ce2a9f7..6bd45833c7 100644 --- a/test/ext/test_declarative.py +++ b/test/ext/test_declarative.py @@ -276,11 +276,11 @@ class DeclarativeTest(DeclarativeTestBase): class Master(Base): __tablename__ = 'master' - id = Column(Integer, primary_key=True) + id = Column(Integer, primary_key=True, test_needs_autoincrement=True) class Detail(Base): __tablename__ = 'detail' - id = Column(Integer, primary_key=True) + id = Column(Integer, primary_key=True, test_needs_autoincrement=True) master_id = Column(None, ForeignKey(Master.id)) master = relation(Master) diff --git a/test/orm/inheritance/test_query.py b/test/orm/inheritance/test_query.py index c74ddcad6f..bebad14186 100644 --- a/test/orm/inheritance/test_query.py +++ b/test/orm/inheritance/test_query.py @@ -1190,7 +1190,8 @@ class EagerToSubclassTest(_base.MappedTest): sess = create_session() def go(): eq_( - sess.query(Parent).join(Parent.children).options(contains_eager(Parent.children)).all(), + sess.query(Parent).join(Parent.children).options(contains_eager(Parent.children)).\ + order_by(Parent.data, Sub.data).all(), [ Parent(data='p1', children=[Sub(data='s1'), Sub(data='s2'), Sub(data='s3')]), Parent(data='p2', children=[Sub(data='s4'), Sub(data='s5')]) diff --git a/test/orm/test_unitofwork.py b/test/orm/test_unitofwork.py index b987291ca9..8ff6b1a657 100644 --- a/test/orm/test_unitofwork.py +++ b/test/orm/test_unitofwork.py @@ -310,7 +310,7 @@ class BinaryHistTest(_base.MappedTest, testing.AssertsExecutionResults): @classmethod def define_tables(cls, metadata): Table('t1', metadata, - Column('id', sa.Integer, primary_key=True), + Column('id', sa.Integer, primary_key=True, test_needs_autoincrement=True), Column('data', sa.Binary), ) diff --git a/test/sql/test_defaults.py b/test/sql/test_defaults.py index 95e87ecbf8..baed19f885 100644 --- a/test/sql/test_defaults.py +++ b/test/sql/test_defaults.py @@ -613,7 +613,7 @@ class SequenceTest(testing.TestBase): @testing.fails_on('maxdb', 'FIXME: unknown') def teststandalone2(self): - x = cartitems.c.cart_id.sequence.execute() + x = cartitems.c.cart_id.default.execute() self.assert_(1 <= x <= 4) @classmethod