diff options
| author | Mike Bayer <mike_mp@zzzcomputing.com> | 2011-08-14 12:20:54 -0400 |
|---|---|---|
| committer | Mike Bayer <mike_mp@zzzcomputing.com> | 2011-08-14 12:20:54 -0400 |
| commit | 76a9219a1ebe9d6abdc510fec87968df905be4fe (patch) | |
| tree | 8c7f0304d7806b7ebe30597059785e6eaa474ddc /test/sql/test_metadata.py | |
| parent | 9a2edbf3ebf04bfff3ad2a7214605503d5cdcaa2 (diff) | |
| download | sqlalchemy-76a9219a1ebe9d6abdc510fec87968df905be4fe.tar.gz | |
- Added a slightly nicer __repr__() to SchemaItem
classes. Note the repr here can't fully support
the "repr is the constructor" idea since schema
items can be very deeply nested/cyclical, have
late initialization of some things, etc.
[ticket:2223]
Diffstat (limited to 'test/sql/test_metadata.py')
| -rw-r--r-- | test/sql/test_metadata.py | 56 |
1 files changed, 39 insertions, 17 deletions
diff --git a/test/sql/test_metadata.py b/test/sql/test_metadata.py index 406db27a7..2107a3a77 100644 --- a/test/sql/test_metadata.py +++ b/test/sql/test_metadata.py @@ -549,6 +549,35 @@ class MetaDataTest(fixtures.TestBase, ComparesTables): 'fake_table', MetaData(testing.db), autoload=True) + def test_assorted_repr(self): + t1 = Table("foo", MetaData(), Column("x", Integer)) + i1 = Index("bar", t1.c.x) + ck = schema.CheckConstraint("x > y", name="someconstraint") + + for const, exp in ( + (Sequence("my_seq"), + "Sequence('my_seq')"), + (Sequence("my_seq", start=5), + "Sequence('my_seq', start=5)"), + (Column("foo", Integer), + "Column('foo', Integer(), table=None)"), + (Table("bar", MetaData(), Column("x", String)), + "Table('bar', MetaData(bind=None), " + "Column('x', String(), table=<bar>), schema=None)"), + (schema.DefaultGenerator(for_update=True), + "DefaultGenerator(for_update=True)"), + (schema.Index("bar"), "Index('bar')"), + (i1, "Index('bar', Column('x', Integer(), table=<foo>))"), + (schema.FetchedValue(), "FetchedValue()"), + (ck, + "CheckConstraint(" + "%s" + ", name='someconstraint')" % repr(ck.sqltext)), + ): + eq_( + repr(const), + exp + ) class TableTest(fixtures.TestBase, AssertsCompiledSQL): def test_prefixes(self): @@ -1138,7 +1167,7 @@ class CatchAllEventsTest(fixtures.TestBase): canary.append("%s->%s" % (obj.__class__.__name__, parent.__class__.__name__)) def after_attach(obj, parent): - canary.append("%s->%s" % (obj, parent)) + canary.append("%s->%s" % (obj.__class__.__name__, parent)) event.listen(schema.SchemaItem, "before_parent_attach", before_attach) event.listen(schema.SchemaItem, "after_parent_attach", after_attach) @@ -1154,22 +1183,15 @@ class CatchAllEventsTest(fixtures.TestBase): eq_( canary, - [ - 'Sequence->Column', - "Sequence('foo_id', start=None, increment=None, optional=False)->id", - 'ForeignKey->Column', - "ForeignKey('t2.id')->bar", - 'Table->MetaData', - 'PrimaryKeyConstraint->Table', 'PrimaryKeyConstraint()->t1', - 'Column->Table', 't1.id->t1', - 'Column->Table', 't1.bar->t1', - 'ForeignKeyConstraint->Table', - 'ForeignKeyConstraint()->t1', - 't1->MetaData(None)', - 'Table->MetaData', - 'PrimaryKeyConstraint->Table', 'PrimaryKeyConstraint()->t2', - 'Column->Table', - 't2.id->t2', 't2->MetaData(None)'] + ['Sequence->Column', 'Sequence->id', 'ForeignKey->Column', + 'ForeignKey->bar', 'Table->MetaData', + 'PrimaryKeyConstraint->Table', 'PrimaryKeyConstraint->t1', + 'Column->Table', 'Column->t1', 'Column->Table', + 'Column->t1', 'ForeignKeyConstraint->Table', + 'ForeignKeyConstraint->t1', 'Table->MetaData(bind=None)', + 'Table->MetaData', 'PrimaryKeyConstraint->Table', + 'PrimaryKeyConstraint->t2', 'Column->Table', 'Column->t2', + 'Table->MetaData(bind=None)'] ) def test_events_per_constraint(self): |
