diff options
| author | Mike Bayer <mike_mp@zzzcomputing.com> | 2012-10-25 20:28:03 -0400 |
|---|---|---|
| committer | Mike Bayer <mike_mp@zzzcomputing.com> | 2012-10-25 20:28:03 -0400 |
| commit | 7f043a9666eecdecc54fe779ffdd50a7d5bb0086 (patch) | |
| tree | 945a98439e89265422632d20289babbe3079f7b1 /test | |
| parent | 519c705317e801d714bd05a28f8b2786695d81cc (diff) | |
| download | sqlalchemy-7f043a9666eecdecc54fe779ffdd50a7d5bb0086.tar.gz | |
- some naming changes on PropComparator, Comparator:
1. all Comparators now have "parent" which is always the parent mapper
or AliasedClass instance
2. only RelationshipProperty.Comparator has "mapper" now, which
is the target mapper
3. The names "parententity" and "parentmapper" are underscored
also improved the message with the "neither comparator nor instruentedattribute...."
to include the classname + attribute name
Diffstat (limited to 'test')
| -rw-r--r-- | test/orm/test_inspect.py | 42 | ||||
| -rw-r--r-- | test/orm/test_mapper.py | 26 |
2 files changed, 58 insertions, 10 deletions
diff --git a/test/orm/test_inspect.py b/test/orm/test_inspect.py index f504ad16e..cd9a30b1a 100644 --- a/test/orm/test_inspect.py +++ b/test/orm/test_inspect.py @@ -175,23 +175,61 @@ class TestORMInspection(_fixtures.FixtureTest): set(['orders', 'addresses']) ) - def test_insp_prop(self): + def test_insp_relationship_prop(self): User = self.classes.User + Address = self.classes.Address prop = inspect(User.addresses) is_(prop, User.addresses) + is_(prop.parent, class_mapper(User)) + is_(prop._parentmapper, class_mapper(User)) + is_(prop.mapper, class_mapper(Address)) - def test_insp_aliased_prop(self): + def test_insp_aliased_relationship_prop(self): User = self.classes.User + Address = self.classes.Address ua = aliased(User) prop = inspect(ua.addresses) is_(prop, ua.addresses) + is_(prop.property.parent, class_mapper(User)) + is_(prop.property.mapper, class_mapper(Address)) + is_(prop.parent, ua) + is_(prop._parentmapper, class_mapper(User)) + is_(prop.mapper, class_mapper(Address)) + + is_(prop._parententity, ua) + + def test_insp_column_prop(self): + User = self.classes.User + prop = inspect(User.name) + is_(prop, User.name) + + is_(prop.parent, class_mapper(User)) + assert not hasattr(prop, "mapper") + + def test_insp_aliased_column_prop(self): + User = self.classes.User + ua = aliased(User) + prop = inspect(ua.name) + is_(prop, ua.name) + + is_(prop.property.parent, class_mapper(User)) + assert not hasattr(prop.property, "mapper") + is_(prop.parent, ua) + is_(prop._parentmapper, class_mapper(User)) + + assert not hasattr(prop, "mapper") + + is_(prop._parententity, ua) + def test_rel_accessors(self): User = self.classes.User Address = self.classes.Address prop = inspect(User.addresses) is_(prop.property.parent, class_mapper(User)) is_(prop.property.mapper, class_mapper(Address)) + is_(prop.parent, class_mapper(User)) + is_(prop.mapper, class_mapper(Address)) assert not hasattr(prop, 'columns') assert hasattr(prop, 'expression') diff --git a/test/orm/test_mapper.py b/test/orm/test_mapper.py index f41843455..1d7e0228c 100644 --- a/test/orm/test_mapper.py +++ b/test/orm/test_mapper.py @@ -1331,7 +1331,7 @@ class MapperTest(_fixtures.FixtureTest, AssertsCompiledSQL): assert_raises_message( AttributeError, "Neither 'extendedproperty' object nor 'UCComparator' " - "object has an attribute 'nonexistent'", + "object associated with User.uc_name has an attribute 'nonexistent'", getattr, User.uc_name, 'nonexistent') # test compile @@ -1350,8 +1350,8 @@ class MapperTest(_fixtures.FixtureTest, AssertsCompiledSQL): sess.expunge_all() q = sess.query(User) - u2 = q.filter(User.name=='some user name').one() - u3 = q.filter(User.uc_name=='SOME USER NAME').one() + u2 = q.filter(User.name == 'some user name').one() + u3 = q.filter(User.uc_name == 'SOME USER NAME').one() assert u2 is u3 @@ -1365,23 +1365,33 @@ class MapperTest(_fixtures.FixtureTest, AssertsCompiledSQL): __hash__ = None def __eq__(self, other): # lower case comparison - return func.lower(self.__clause_element__()) == func.lower(other) + return func.lower(self.__clause_element__() + ) == func.lower(other) def intersects(self, other): # non-standard comparator return self.__clause_element__().op('&=')(other) mapper(User, users, properties={ - 'name':sa.orm.column_property(users.c.name, comparator_factory=MyComparator) + 'name': sa.orm.column_property(users.c.name, + comparator_factory=MyComparator) }) assert_raises_message( AttributeError, - "Neither 'InstrumentedAttribute' object nor 'MyComparator' object has an attribute 'nonexistent'", + "Neither 'InstrumentedAttribute' object nor " + "'MyComparator' object associated with User.name has " + "an attribute 'nonexistent'", getattr, User.name, "nonexistent") - eq_(str((User.name == 'ed').compile(dialect=sa.engine.default.DefaultDialect())) , "lower(users.name) = lower(:lower_1)") - eq_(str((User.name.intersects('ed')).compile(dialect=sa.engine.default.DefaultDialect())), "users.name &= :name_1") + eq_( + str((User.name == 'ed').compile( + dialect=sa.engine.default.DefaultDialect())), + "lower(users.name) = lower(:lower_1)") + eq_( + str((User.name.intersects('ed')).compile( + dialect=sa.engine.default.DefaultDialect())), + "users.name &= :name_1") def test_reentrant_compile(self): |
