diff options
| author | Mike Bayer <mike_mp@zzzcomputing.com> | 2011-05-18 12:07:40 -0400 |
|---|---|---|
| committer | Mike Bayer <mike_mp@zzzcomputing.com> | 2011-05-18 12:07:40 -0400 |
| commit | 00380cf3c304ea7f1c7397f17b828166364c36ac (patch) | |
| tree | 06313059c6b410815aa40192ae86bbcede3a7b61 /test/sql/test_selectable.py | |
| parent | aea4b9928e99b04237f61aeccbeb31c02367a2c0 (diff) | |
| download | sqlalchemy-00380cf3c304ea7f1c7397f17b828166364c36ac.tar.gz | |
- Fixed bug whereby nesting a label of a select()
with another label in it would produce incorrect
exported columns. Among other things this would
break an ORM column_property() mapping against
another column_property(). [ticket:2167].
Also in 0.6.8
- _Label() is always against a column or selectable. remove
uncovered case of label against something else.
- start taking notes to clean up some of this labeling stuff,
which will be [ticket:2168]
Diffstat (limited to 'test/sql/test_selectable.py')
| -rw-r--r-- | test/sql/test_selectable.py | 52 |
1 files changed, 51 insertions, 1 deletions
diff --git a/test/sql/test_selectable.py b/test/sql/test_selectable.py index a529842bf..47d81b879 100644 --- a/test/sql/test_selectable.py +++ b/test/sql/test_selectable.py @@ -27,7 +27,7 @@ table2 = Table('table2', metadata, ) -class SelectableTest(fixtures.TestBase, AssertsExecutionResults): +class SelectableTest(fixtures.TestBase, AssertsExecutionResults, AssertsCompiledSQL): def test_indirect_correspondence_on_labels(self): # this test depends upon 'distance' to @@ -302,6 +302,56 @@ class SelectableTest(fixtures.TestBase, AssertsExecutionResults): assert_raises(exc.NoReferencedTableError, s.join, t1) + def test_multi_label_chain_naming_col(self): + # See [ticket:2167] for this one. + l1 = table1.c.col1.label('a') + l2 = select([l1]).label('b') + s = select([l2]) + assert s.c.b is not None + self.assert_compile( + s.select(), + "SELECT b FROM (SELECT (SELECT table1.col1 AS a FROM table1) AS b)" + ) + + s2 = select([s.label('c')]) + self.assert_compile( + s2.select(), + "SELECT c FROM (SELECT (SELECT (SELECT table1.col1 AS a FROM table1) AS b) AS c)" + ) + + +class AnonLabelTest(fixtures.TestBase): + """Test behaviors that we hope to change with [ticket:2168].""" + + def test_anon_labels_named_column(self): + c1 = column('x') + + # surprising + assert c1.label(None) is c1 + eq_(str(select([c1.label(None)])), "SELECT x") + + def test_anon_labels_literal_column(self): + c1 = literal_column('x') + assert c1.label(None) is c1 + eq_(str(select([c1.label(None)])), "SELECT x") + + def test_anon_labels_func(self): + c1 = func.count('*') + assert c1.label(None) is not c1 + + eq_(str(select([c1])), "SELECT count(:param_1) AS count_1") + c2 = select([c1]).compile() + + eq_(str(select([c1.label(None)])), "SELECT count(:param_1) AS count_1") + + def test_named_labels_named_column(self): + c1 = column('x') + eq_(str(select([c1.label('y')])), "SELECT x AS y") + + def test_named_labels_literal_column(self): + c1 = literal_column('x') + eq_(str(select([c1.label('y')])), "SELECT x AS y") + class JoinConditionTest(fixtures.TestBase, AssertsExecutionResults): def test_join_condition(self): |
