diff options
Diffstat (limited to 'test/sql/selectable.py')
| -rwxr-xr-x | test/sql/selectable.py | 72 |
1 files changed, 36 insertions, 36 deletions
diff --git a/test/sql/selectable.py b/test/sql/selectable.py index 1b9959ec4..850e29e16 100755 --- a/test/sql/selectable.py +++ b/test/sql/selectable.py @@ -1,18 +1,18 @@ """tests that various From objects properly export their columns, as well as useable primary keys and foreign keys. Full relational algebra depends on every selectable unit behaving nicely with others..""" - + import testbase from sqlalchemy import * from testlib import * metadata = MetaData() -table = Table('table1', metadata, +table = Table('table1', metadata, Column('col1', Integer, primary_key=True), Column('col2', String(20)), Column('col3', Integer), Column('colx', Integer), - + ) table2 = Table('table2', metadata, @@ -31,47 +31,47 @@ class SelectableTest(AssertMixin): #assert s.corresponding_column(table.c.col1) is s.c.col1 assert s.corresponding_column(s.c.col1) is s.c.col1 assert s.corresponding_column(s.c.c1) is s.c.c1 - + def testjoinagainstself(self): jj = select([table.c.col1.label('bar_col1')]) jjj = join(table, jj, table.c.col1==jj.c.bar_col1) - + # test column directly agaisnt itself assert jjj.corresponding_column(jjj.c.table1_col1) is jjj.c.table1_col1 assert jjj.corresponding_column(jj.c.bar_col1) is jjj.c.bar_col1 - - # test alias of the join, targets the column with the least + + # test alias of the join, targets the column with the least # "distance" between the requested column and the returned column # (i.e. there is less indirection between j2.c.table1_col1 and table.c.col1, than # there is from j2.c.bar_col1 to table.c.col1) j2 = jjj.alias('foo') assert j2.corresponding_column(table.c.col1) is j2.c.table1_col1 - + def testselectontable(self): sel = select([table, table2], use_labels=True) assert sel.corresponding_column(table.c.col1) is sel.c.table1_col1 assert sel.corresponding_column(table.c.col1, require_embedded=True) is sel.c.table1_col1 assert table.corresponding_column(sel.c.table1_col1) is table.c.col1 assert table.corresponding_column(sel.c.table1_col1, require_embedded=True) is None - + def testjoinagainstjoin(self): j = outerjoin(table, table2, table.c.col1==table2.c.col2) jj = select([ table.c.col1.label('bar_col1')],from_obj=[j]).alias('foo') jjj = join(table, jj, table.c.col1==jj.c.bar_col1) assert jjj.corresponding_column(jjj.c.table1_col1) is jjj.c.table1_col1 - + j2 = jjj.alias('foo') print j2.corresponding_column(jjj.c.table1_col1) assert j2.corresponding_column(jjj.c.table1_col1) is j2.c.table1_col1 - + assert jjj.corresponding_column(jj.c.bar_col1) is jj.c.bar_col1 - + def testtablealias(self): a = table.alias('a') - + j = join(a, table2) - + criterion = a.c.col1 == table2.c.col2 print print str(j) @@ -124,7 +124,7 @@ class SelectableTest(AssertMixin): j1 = table.join(table2) assert u.corresponding_column(j1.c.table1_colx) is u.c.colx assert j1.corresponding_column(u.c.colx) is j1.c.table1_colx - + def testjoin(self): a = join(table, table2) print str(a.select(use_labels=True)) @@ -138,7 +138,7 @@ class SelectableTest(AssertMixin): a = table.select().alias('a') print str(a.select()) j = join(a, table2) - + criterion = a.c.col1 == table2.c.col2 print criterion print j.onclause @@ -148,7 +148,7 @@ class SelectableTest(AssertMixin): a = table.select(use_labels=True) print str(a.select()) j = join(a, table2) - + criterion = a.c.table1_col1 == table2.c.col2 print print str(j) @@ -163,17 +163,17 @@ class SelectableTest(AssertMixin): criterion = a.c.acol1 == table2.c.col2 print str(j) self.assert_(criterion.compare(j.onclause)) - + def testselectaliaslabels(self): a = table2.select(use_labels=True).alias('a') print str(a.select()) j = join(a, table) - + criterion = table.c.col1 == a.c.table2_col2 print str(criterion) print str(j.onclause) self.assert_(criterion.compare(j.onclause)) - + def testtablejoinedtoselectoftable(self): metadata = MetaData() a = Table('a', metadata, @@ -195,9 +195,10 @@ class SelectableTest(AssertMixin): assert j4.corresponding_column(j2.c.aid) is j4.c.aid assert j4.corresponding_column(a.c.id) is j4.c.id + @testing.emits_warning('.*replaced by another column with the same key') def test_oid(self): # the oid column of a selectable currently proxies all - # oid columns found within. + # oid columns found within. s = table.select() s2 = table2.select() s3 = select([s, s2]) @@ -205,18 +206,18 @@ class SelectableTest(AssertMixin): assert s3.corresponding_column(table2.oid_column) is s3.oid_column assert s3.corresponding_column(s.oid_column) is s3.oid_column assert s3.corresponding_column(s2.oid_column) is s3.oid_column - + u = s.union(s2) assert u.corresponding_column(table.oid_column) is u.oid_column assert u.corresponding_column(table2.oid_column) is u.oid_column assert u.corresponding_column(s.oid_column) is u.oid_column assert u.corresponding_column(s2.oid_column) is u.oid_column - + class PrimaryKeyTest(AssertMixin): def test_join_pk_collapse_implicit(self): - """test that redundant columns in a join get 'collapsed' into a minimal primary key, + """test that redundant columns in a join get 'collapsed' into a minimal primary key, which is the root column along a chain of foreign key relationships.""" - + meta = MetaData() a = Table('a', meta, Column('id', Integer, primary_key=True)) b = Table('b', meta, Column('id', Integer, ForeignKey('a.id'), primary_key=True)) @@ -225,7 +226,7 @@ class PrimaryKeyTest(AssertMixin): assert c.c.id.references(b.c.id) assert not d.c.id.references(a.c.id) - + assert list(a.join(b).primary_key) == [a.c.id] assert list(b.join(c).primary_key) == [b.c.id] assert list(a.join(b).join(c).primary_key) == [a.c.id] @@ -234,7 +235,7 @@ class PrimaryKeyTest(AssertMixin): assert list(a.join(b).join(c).join(d).primary_key) == [a.c.id] def test_join_pk_collapse_explicit(self): - """test that redundant columns in a join get 'collapsed' into a minimal primary key, + """test that redundant columns in a join get 'collapsed' into a minimal primary key, which is the root column along a chain of explicit join conditions.""" meta = MetaData() @@ -251,9 +252,9 @@ class PrimaryKeyTest(AssertMixin): assert list(b.join(c, c.c.id==b.c.x).join(d).primary_key) == [b.c.id] assert list(d.join(b, d.c.id==b.c.id).join(c, b.c.id==c.c.x).primary_key) == [c.c.id] assert list(a.join(b).join(c, c.c.id==b.c.x).join(d).primary_key) == [a.c.id] - + assert list(a.join(b, and_(a.c.id==b.c.id, a.c.x==b.c.id)).primary_key) == [a.c.id] - + def test_init_doesnt_blowitaway(self): meta = MetaData() a = Table('a', meta, Column('id', Integer, primary_key=True), Column('x', Integer)) @@ -261,7 +262,7 @@ class PrimaryKeyTest(AssertMixin): j = a.join(b) assert list(j.primary_key) == [a.c.id] - + j.foreign_keys assert list(j.primary_key) == [a.c.id] @@ -279,20 +280,20 @@ class DerivedTest(AssertMixin): meta = MetaData() t1 = Table('t1', meta, Column('c1', Integer, primary_key=True), Column('c2', String(30))) t2 = Table('t2', meta, Column('c1', Integer, primary_key=True), Column('c2', String(30))) - + assert t1.is_derived_from(t1) assert not t2.is_derived_from(t1) - - def test_alias(self): + + def test_alias(self): meta = MetaData() t1 = Table('t1', meta, Column('c1', Integer, primary_key=True), Column('c2', String(30))) t2 = Table('t2', meta, Column('c1', Integer, primary_key=True), Column('c2', String(30))) - + assert t1.alias().is_derived_from(t1) assert not t2.alias().is_derived_from(t1) assert not t1.is_derived_from(t1.alias()) assert not t1.is_derived_from(t2.alias()) - + def test_select(self): meta = MetaData() t1 = Table('t1', meta, Column('c1', Integer, primary_key=True), Column('c2', String(30))) @@ -309,4 +310,3 @@ class DerivedTest(AssertMixin): if __name__ == "__main__": testbase.main() - |
