1. diana clarke
  2. sqlalchemy-1418

Commits

diana  committed c076882

move the defer tests out of test_mapper and into test_deferred (also a pep8 pass of the new test file)

  • Participants
  • Parent commits a98001d
  • Branches default

Comments (0)

Files changed (2)

File test/orm/test_deferred.py

View file
+import sqlalchemy as sa
+
+from sqlalchemy import Integer, ForeignKey, String, util
+from sqlalchemy.orm import attributes, create_session, defer, \
+                           deferred, joinedload, mapper, \
+                           relationship, synonym, Session, \
+                           undefer, undefer_group
+
+from test.lib import fixtures
+from test.lib import testing
+from test.lib.testing import eq_
+from test.lib.schema import Table, Column
+from test.orm import _fixtures
+
+
+class DeferredTest(_fixtures.FixtureTest):
+
+    def test_basic(self):
+        """A basic deferred load."""
+
+        Order, orders = self.classes.Order, self.tables.orders
+
+        mapper(Order, orders, order_by=orders.c.id, properties={
+            'description': deferred(orders.c.description)})
+
+        o = Order()
+        self.assert_(o.description is None)
+
+        q = create_session().query(Order)
+
+        def go():
+            l = q.all()
+            o2 = l[2]
+            x = o2.description
+
+        self.sql_eq_(go, [
+            ("SELECT orders.id AS orders_id, "
+             "orders.user_id AS orders_user_id, "
+             "orders.address_id AS orders_address_id, "
+             "orders.isopen AS orders_isopen "
+             "FROM orders ORDER BY orders.id", {}),
+            ("SELECT orders.description AS orders_description "
+             "FROM orders WHERE orders.id = :param_1",
+             {'param_1':3})])
+
+    def test_unsaved(self):
+        """Deferred loading does not kick in when just PK cols are set."""
+
+        Order, orders = self.classes.Order, self.tables.orders
+
+        mapper(Order, orders, properties={
+            'description': deferred(orders.c.description)})
+
+        sess = create_session()
+        o = Order()
+        sess.add(o)
+        o.id = 7
+
+        def go():
+            o.description = "some description"
+
+        self.sql_count_(0, go)
+
+    def test_synonym_group_bug(self):
+        orders, Order = self.tables.orders, self.classes.Order
+
+        mapper(Order, orders, properties={
+            'isopen': synonym('_isopen', map_column=True),
+            'description': deferred(orders.c.description, group='foo')
+        })
+
+        sess = create_session()
+        o1 = sess.query(Order).get(1)
+        eq_(o1.description, "order 1")
+
+    def test_unsaved_2(self):
+        Order, orders = self.classes.Order, self.tables.orders
+
+        mapper(Order, orders, properties={
+            'description': deferred(orders.c.description)})
+
+        sess = create_session()
+        o = Order()
+        sess.add(o)
+
+        def go():
+            o.description = "some description"
+
+        self.sql_count_(0, go)
+
+    def test_unsaved_group(self):
+        """Deferred loading doesn't kick in when just PK cols are set"""
+
+        orders, Order = self.tables.orders, self.classes.Order
+
+        mapper(Order, orders, order_by=orders.c.id, properties=dict(
+            description=deferred(orders.c.description, group='primary'),
+            opened=deferred(orders.c.isopen, group='primary')))
+
+        sess = create_session()
+        o = Order()
+        sess.add(o)
+        o.id = 7
+
+        def go():
+            o.description = "some description"
+
+        self.sql_count_(0, go)
+
+    def test_unsaved_group_2(self):
+        orders, Order = self.tables.orders, self.classes.Order
+
+        mapper(Order, orders, order_by=orders.c.id, properties=dict(
+            description=deferred(orders.c.description, group='primary'),
+            opened=deferred(orders.c.isopen, group='primary')))
+
+        sess = create_session()
+        o = Order()
+        sess.add(o)
+
+        def go():
+            o.description = "some description"
+
+        self.sql_count_(0, go)
+
+    def test_save(self):
+        Order, orders = self.classes.Order, self.tables.orders
+
+        mapper(Order, orders, properties={
+            'description': deferred(orders.c.description)})
+
+        sess = create_session()
+        o2 = sess.query(Order).get(2)
+        o2.isopen = 1
+        sess.flush()
+
+    def test_group(self):
+        """Deferred load with a group"""
+
+        orders, Order = self.tables.orders, self.classes.Order
+
+        mapper(Order, orders, properties=util.OrderedDict([
+            ('userident', deferred(orders.c.user_id, group='primary')),
+            ('addrident', deferred(orders.c.address_id, group='primary')),
+            ('description', deferred(orders.c.description, group='primary')),
+            ('opened', deferred(orders.c.isopen, group='primary'))
+        ]))
+
+        sess = create_session()
+        q = sess.query(Order).order_by(Order.id)
+
+        def go():
+            l = q.all()
+            o2 = l[2]
+            eq_(o2.opened, 1)
+            eq_(o2.userident, 7)
+            eq_(o2.description, 'order 3')
+
+        self.sql_eq_(go, [
+            ("SELECT orders.id AS orders_id "
+             "FROM orders ORDER BY orders.id", {}),
+            ("SELECT orders.user_id AS orders_user_id, "
+             "orders.address_id AS orders_address_id, "
+             "orders.description AS orders_description, "
+             "orders.isopen AS orders_isopen "
+             "FROM orders WHERE orders.id = :param_1",
+             {'param_1':3})])
+
+        o2 = q.all()[2]
+        eq_(o2.description, 'order 3')
+        assert o2 not in sess.dirty
+        o2.description = 'order 3'
+
+        def go():
+            sess.flush()
+
+        self.sql_count_(0, go)
+
+    def test_preserve_changes(self):
+        """
+        A deferred load operation doesn't revert modifications on attributes
+
+        """
+
+        orders, Order = self.tables.orders, self.classes.Order
+
+        mapper(Order, orders, properties={
+            'userident': deferred(orders.c.user_id, group='primary'),
+            'description': deferred(orders.c.description, group='primary'),
+            'opened': deferred(orders.c.isopen, group='primary')
+        })
+
+        sess = create_session()
+        o = sess.query(Order).get(3)
+        assert 'userident' not in o.__dict__
+        o.description = 'somenewdescription'
+        eq_(o.description, 'somenewdescription')
+
+        def go():
+            eq_(o.opened, 1)
+
+        self.assert_sql_count(testing.db, go, 1)
+        eq_(o.description, 'somenewdescription')
+        assert o in sess.dirty
+
+    def test_commits_state(self):
+        """
+        When deferred elements are loaded via a group, they get the proper
+        CommittedState and don't result in changes being committed
+
+        """
+
+        orders, Order = self.tables.orders, self.classes.Order
+
+        mapper(Order, orders, properties={
+            'userident': deferred(orders.c.user_id, group='primary'),
+            'description': deferred(orders.c.description, group='primary'),
+            'opened': deferred(orders.c.isopen, group='primary')})
+
+        sess = create_session()
+        o2 = sess.query(Order).get(3)
+
+        # this will load the group of attributes
+        eq_(o2.description, 'order 3')
+        assert o2 not in sess.dirty
+        # this will mark it as 'dirty', but nothing actually changed
+        o2.description = 'order 3'
+        # therefore the flush() shouldn't actually issue any SQL
+        self.assert_sql_count(testing.db, sess.flush, 0)
+
+    def test_options(self):
+        """Options on a mapper to create deferred and undeferred columns"""
+
+        orders, Order = self.tables.orders, self.classes.Order
+
+        mapper(Order, orders)
+
+        sess = create_session()
+        q = sess.query(Order).order_by(Order.id).options(defer('user_id'))
+
+        def go():
+            q.all()[0].user_id
+
+        self.sql_eq_(go, [
+            ("SELECT orders.id AS orders_id, "
+             "orders.address_id AS orders_address_id, "
+             "orders.description AS orders_description, "
+             "orders.isopen AS orders_isopen "
+             "FROM orders ORDER BY orders.id", {}),
+            ("SELECT orders.user_id AS orders_user_id "
+             "FROM orders WHERE orders.id = :param_1",
+             {'param_1':1})])
+        sess.expunge_all()
+
+        q2 = q.options(undefer('user_id'))
+        self.sql_eq_(q2.all, [
+            ("SELECT orders.id AS orders_id, "
+             "orders.user_id AS orders_user_id, "
+             "orders.address_id AS orders_address_id, "
+             "orders.description AS orders_description, "
+             "orders.isopen AS orders_isopen "
+             "FROM orders ORDER BY orders.id",
+             {})])
+
+    def test_undefer_group(self):
+        orders, Order = self.tables.orders, self.classes.Order
+
+        mapper(Order, orders, properties=util.OrderedDict([
+            ('userident', deferred(orders.c.user_id, group='primary')),
+            ('description', deferred(orders.c.description, group='primary')),
+            ('opened', deferred(orders.c.isopen, group='primary'))]))
+
+        sess = create_session()
+        q = sess.query(Order).order_by(Order.id)
+
+        def go():
+            l = q.options(undefer_group('primary')).all()
+            o2 = l[2]
+            eq_(o2.opened, 1)
+            eq_(o2.userident, 7)
+            eq_(o2.description, 'order 3')
+
+        self.sql_eq_(go, [
+            ("SELECT orders.user_id AS orders_user_id, "
+             "orders.description AS orders_description, "
+             "orders.isopen AS orders_isopen, "
+             "orders.id AS orders_id, "
+             "orders.address_id AS orders_address_id "
+             "FROM orders ORDER BY orders.id",
+             {})])
+
+    def test_locates_col(self):
+        """Manually adding a column to the result undefers the column."""
+
+        orders, Order = self.tables.orders, self.classes.Order
+
+        mapper(Order, orders, properties={
+            'description': deferred(orders.c.description)})
+
+        sess = create_session()
+        o1 = sess.query(Order).order_by(Order.id).first()
+
+        def go():
+            eq_(o1.description, 'order 1')
+
+        self.sql_count_(1, go)
+
+        sess = create_session()
+        o1 = (sess.query(Order).
+              order_by(Order.id).
+              add_column(orders.c.description).first())[0]
+
+        def go():
+            eq_(o1.description, 'order 1')
+
+        self.sql_count_(0, go)
+
+    def test_map_selectable_wo_deferred(self):
+        """test mapping to a selectable with deferred cols,
+        the selectable doesn't include the deferred col.
+
+        """
+
+        Order, orders = self.classes.Order, self.tables.orders
+
+        order_select = sa.select([
+            orders.c.id,
+            orders.c.user_id,
+            orders.c.address_id,
+            orders.c.description,
+            orders.c.isopen]).alias()
+        mapper(Order, order_select, properties={
+            'description': deferred(order_select.c.description)})
+
+        sess = Session()
+        o1 = sess.query(Order).order_by(Order.id).first()
+        assert 'description' not in o1.__dict__
+        eq_(o1.description, 'order 1')
+
+    def test_deep_options(self):
+        users, items, order_items, orders = (
+            self.tables.users,
+            self.tables.items,
+            self.tables.order_items,
+            self.tables.orders)
+
+        Order, Item, User = (
+            self.classes.Order,
+            self.classes.Item,
+            self.classes.User)
+
+        mapper(Item, items, properties=dict(
+            description=deferred(items.c.description)))
+        mapper(Order, orders, properties=dict(
+            items=relationship(Item, secondary=order_items)))
+        mapper(User, users, properties=dict(
+            orders=relationship(Order, order_by=orders.c.id)))
+
+        sess = create_session()
+        q = sess.query(User).order_by(User.id)
+        l = q.all()
+        item = l[0].orders[1].items[1]
+
+        def go():
+            eq_(item.description, 'item 4')
+
+        self.sql_count_(1, go)
+        eq_(item.description, 'item 4')
+
+        sess.expunge_all()
+        l = q.options(undefer('orders.items.description')).all()
+        item = l[0].orders[1].items[1]
+
+        def go():
+            eq_(item.description, 'item 4')
+
+        self.sql_count_(0, go)
+        eq_(item.description, 'item 4')
+
+
+class DeferredPopulationTest(fixtures.MappedTest):
+
+    @classmethod
+    def define_tables(cls, metadata):
+        Table("thing", metadata,
+            Column("id", Integer, primary_key=True,
+                   test_needs_autoincrement=True),
+            Column("name", String(20)))
+
+        Table("human", metadata,
+            Column("id", Integer, primary_key=True,
+                   test_needs_autoincrement=True),
+            Column("thing_id", Integer, ForeignKey("thing.id")),
+            Column("name", String(20)))
+
+    @classmethod
+    def setup_mappers(cls):
+        thing, human = cls.tables.thing, cls.tables.human
+
+        class Human(cls.Basic):
+            pass
+
+        class Thing(cls.Basic):
+            pass
+
+        mapper(Human, human, properties={"thing": relationship(Thing)})
+        mapper(Thing, thing, properties={"name": deferred(thing.c.name)})
+
+    @classmethod
+    def insert_data(cls):
+        thing, human = cls.tables.thing, cls.tables.human
+
+        thing.insert().execute([
+            {"id": 1, "name": "Chair"},
+        ])
+
+        human.insert().execute([
+            {"id": 1, "thing_id": 1, "name": "Clark Kent"},
+        ])
+
+    def _test(self, thing):
+        assert "name" in attributes.instance_state(thing).dict
+
+    def test_no_previous_query(self):
+        Thing = self.classes.Thing
+
+        session = create_session()
+        thing = session.query(Thing).options(undefer("name")).first()
+        self._test(thing)
+
+    def test_query_twice_with_clear(self):
+        Thing = self.classes.Thing
+
+        session = create_session()
+        result = session.query(Thing).first()
+        session.expunge_all()
+        thing = session.query(Thing).options(undefer("name")).first()
+        self._test(thing)
+
+    def test_query_twice_no_clear(self):
+        Thing = self.classes.Thing
+
+        session = create_session()
+        result = session.query(Thing).first()
+        thing = session.query(Thing).options(undefer("name")).first()
+        self._test(thing)
+
+    def test_joinedload_with_clear(self):
+        Thing, Human = self.classes.Thing, self.classes.Human
+
+        session = create_session()
+        human = session.query(Human).options(joinedload("thing")).first()
+        session.expunge_all()
+        thing = session.query(Thing).options(undefer("name")).first()
+        self._test(thing)
+
+    def test_joinedload_no_clear(self):
+        Thing, Human = self.classes.Thing, self.classes.Human
+
+        session = create_session()
+        human = session.query(Human).options(joinedload("thing")).first()
+        thing = session.query(Thing).options(undefer("name")).first()
+        self._test(thing)
+
+    def test_join_with_clear(self):
+        Thing, Human = self.classes.Thing, self.classes.Human
+
+        session = create_session()
+        result = session.query(Human).add_entity(Thing).join("thing").first()
+        session.expunge_all()
+        thing = session.query(Thing).options(undefer("name")).first()
+        self._test(thing)
+
+    def test_join_no_clear(self):
+        Thing, Human = self.classes.Thing, self.classes.Human
+
+        session = create_session()
+        result = session.query(Human).add_entity(Thing).join("thing").first()
+        thing = session.query(Thing).options(undefer("name")).first()
+        self._test(thing)

File test/orm/test_mapper.py

View file
 from sqlalchemy.engine import default
 from sqlalchemy.orm import mapper, relationship, backref, \
     create_session, class_mapper, configure_mappers, reconstructor, \
-    validates, aliased, defer, deferred, synonym, attributes, \
+    validates, aliased, deferred, synonym, attributes, \
     column_property, composite, dynamic_loader, \
     comparable_property, Session
 from sqlalchemy.orm.persistence import _sort_states
         self.assert_compile(aliased(User).addresses == Address(id=5, user_id=7), "foobar(users_1.id) = foobar(:foobar_1)", dialect=default.DefaultDialect())
 
 
-class DeferredTest(_fixtures.FixtureTest):
-
-    def test_basic(self):
-        """A basic deferred load."""
-
-        Order, orders = self.classes.Order, self.tables.orders
-
-
-        mapper(Order, orders, order_by=orders.c.id, properties={
-            'description': deferred(orders.c.description)})
-
-        o = Order()
-        self.assert_(o.description is None)
-
-        q = create_session().query(Order)
-        def go():
-            l = q.all()
-            o2 = l[2]
-            x = o2.description
-
-        self.sql_eq_(go, [
-            ("SELECT orders.id AS orders_id, "
-             "orders.user_id AS orders_user_id, "
-             "orders.address_id AS orders_address_id, "
-             "orders.isopen AS orders_isopen "
-             "FROM orders ORDER BY orders.id", {}),
-            ("SELECT orders.description AS orders_description "
-             "FROM orders WHERE orders.id = :param_1",
-             {'param_1':3})])
-
-    def test_unsaved(self):
-        """Deferred loading does not kick in when just PK cols are set."""
-
-        Order, orders = self.classes.Order, self.tables.orders
-
-
-        mapper(Order, orders, properties={
-            'description': deferred(orders.c.description)})
-
-        sess = create_session()
-        o = Order()
-        sess.add(o)
-        o.id = 7
-        def go():
-            o.description = "some description"
-        self.sql_count_(0, go)
-
-    def test_synonym_group_bug(self):
-        orders, Order = self.tables.orders, self.classes.Order
-
-        mapper(Order, orders, properties={
-            'isopen':synonym('_isopen', map_column=True),
-            'description':deferred(orders.c.description, group='foo')
-        })
-
-        sess = create_session()
-        o1 = sess.query(Order).get(1)
-        eq_(o1.description, "order 1")
-
-    def test_unsaved_2(self):
-        Order, orders = self.classes.Order, self.tables.orders
-
-        mapper(Order, orders, properties={
-            'description': deferred(orders.c.description)})
-
-        sess = create_session()
-        o = Order()
-        sess.add(o)
-        def go():
-            o.description = "some description"
-        self.sql_count_(0, go)
-
-    def test_unsaved_group(self):
-        """Deferred loading doesnt kick in when just PK cols are set"""
-
-        orders, Order = self.tables.orders, self.classes.Order
-
-
-        mapper(Order, orders, order_by=orders.c.id, properties=dict(
-            description=deferred(orders.c.description, group='primary'),
-            opened=deferred(orders.c.isopen, group='primary')))
-
-        sess = create_session()
-        o = Order()
-        sess.add(o)
-        o.id = 7
-        def go():
-            o.description = "some description"
-        self.sql_count_(0, go)
-
-    def test_unsaved_group_2(self):
-        orders, Order = self.tables.orders, self.classes.Order
-
-        mapper(Order, orders, order_by=orders.c.id, properties=dict(
-            description=deferred(orders.c.description, group='primary'),
-            opened=deferred(orders.c.isopen, group='primary')))
-
-        sess = create_session()
-        o = Order()
-        sess.add(o)
-        def go():
-            o.description = "some description"
-        self.sql_count_(0, go)
-
-    def test_save(self):
-        Order, orders = self.classes.Order, self.tables.orders
-
-        m = mapper(Order, orders, properties={
-            'description': deferred(orders.c.description)})
-
-        sess = create_session()
-        o2 = sess.query(Order).get(2)
-        o2.isopen = 1
-        sess.flush()
-
-    def test_group(self):
-        """Deferred load with a group"""
-
-        orders, Order = self.tables.orders, self.classes.Order
-
-        mapper(Order, orders, properties=util.OrderedDict([
-            ('userident', deferred(orders.c.user_id, group='primary')),
-            ('addrident', deferred(orders.c.address_id, group='primary')),
-            ('description', deferred(orders.c.description, group='primary')),
-            ('opened', deferred(orders.c.isopen, group='primary'))
-        ]))
-
-        sess = create_session()
-        q = sess.query(Order).order_by(Order.id)
-        def go():
-            l = q.all()
-            o2 = l[2]
-            eq_(o2.opened, 1)
-            eq_(o2.userident, 7)
-            eq_(o2.description, 'order 3')
-
-        self.sql_eq_(go, [
-            ("SELECT orders.id AS orders_id "
-             "FROM orders ORDER BY orders.id", {}),
-            ("SELECT orders.user_id AS orders_user_id, "
-             "orders.address_id AS orders_address_id, "
-             "orders.description AS orders_description, "
-             "orders.isopen AS orders_isopen "
-             "FROM orders WHERE orders.id = :param_1",
-             {'param_1':3})])
-
-        o2 = q.all()[2]
-        eq_(o2.description, 'order 3')
-        assert o2 not in sess.dirty
-        o2.description = 'order 3'
-        def go():
-            sess.flush()
-        self.sql_count_(0, go)
-
-    def test_preserve_changes(self):
-        """A deferred load operation doesn't revert modifications on attributes"""
-
-        orders, Order = self.tables.orders, self.classes.Order
-
-        mapper(Order, orders, properties = {
-            'userident': deferred(orders.c.user_id, group='primary'),
-            'description': deferred(orders.c.description, group='primary'),
-            'opened': deferred(orders.c.isopen, group='primary')
-        })
-        sess = create_session()
-        o = sess.query(Order).get(3)
-        assert 'userident' not in o.__dict__
-        o.description = 'somenewdescription'
-        eq_(o.description, 'somenewdescription')
-        def go():
-            eq_(o.opened, 1)
-        self.assert_sql_count(testing.db, go, 1)
-        eq_(o.description, 'somenewdescription')
-        assert o in sess.dirty
-
-    def test_commits_state(self):
-        """
-        When deferred elements are loaded via a group, they get the proper
-        CommittedState and don't result in changes being committed
-
-        """
-
-        orders, Order = self.tables.orders, self.classes.Order
-
-        mapper(Order, orders, properties = {
-            'userident':deferred(orders.c.user_id, group='primary'),
-            'description':deferred(orders.c.description, group='primary'),
-            'opened':deferred(orders.c.isopen, group='primary')})
-
-        sess = create_session()
-        o2 = sess.query(Order).get(3)
-
-        # this will load the group of attributes
-        eq_(o2.description, 'order 3')
-        assert o2 not in sess.dirty
-        # this will mark it as 'dirty', but nothing actually changed
-        o2.description = 'order 3'
-        # therefore the flush() shouldnt actually issue any SQL
-        self.assert_sql_count(testing.db, sess.flush, 0)
-
-    def test_options(self):
-        """Options on a mapper to create deferred and undeferred columns"""
-
-        orders, Order = self.tables.orders, self.classes.Order
-
-
-        mapper(Order, orders)
-
-        sess = create_session()
-        q = sess.query(Order).order_by(Order.id).options(defer('user_id'))
-
-        def go():
-            q.all()[0].user_id
-
-        self.sql_eq_(go, [
-            ("SELECT orders.id AS orders_id, "
-             "orders.address_id AS orders_address_id, "
-             "orders.description AS orders_description, "
-             "orders.isopen AS orders_isopen "
-             "FROM orders ORDER BY orders.id", {}),
-            ("SELECT orders.user_id AS orders_user_id "
-             "FROM orders WHERE orders.id = :param_1",
-             {'param_1':1})])
-        sess.expunge_all()
-
-        q2 = q.options(sa.orm.undefer('user_id'))
-        self.sql_eq_(q2.all, [
-            ("SELECT orders.id AS orders_id, "
-             "orders.user_id AS orders_user_id, "
-             "orders.address_id AS orders_address_id, "
-             "orders.description AS orders_description, "
-             "orders.isopen AS orders_isopen "
-             "FROM orders ORDER BY orders.id",
-             {})])
-
-    def test_undefer_group(self):
-        orders, Order = self.tables.orders, self.classes.Order
-
-        mapper(Order, orders, properties=util.OrderedDict([
-            ('userident',deferred(orders.c.user_id, group='primary')),
-            ('description',deferred(orders.c.description, group='primary')),
-            ('opened',deferred(orders.c.isopen, group='primary'))
-            ]
-            ))
-
-        sess = create_session()
-        q = sess.query(Order).order_by(Order.id)
-        def go():
-            l = q.options(sa.orm.undefer_group('primary')).all()
-            o2 = l[2]
-            eq_(o2.opened, 1)
-            eq_(o2.userident, 7)
-            eq_(o2.description, 'order 3')
-
-        self.sql_eq_(go, [
-            ("SELECT orders.user_id AS orders_user_id, "
-             "orders.description AS orders_description, "
-             "orders.isopen AS orders_isopen, "
-             "orders.id AS orders_id, "
-             "orders.address_id AS orders_address_id "
-             "FROM orders ORDER BY orders.id",
-             {})])
-
-    def test_locates_col(self):
-        """Manually adding a column to the result undefers the column."""
-
-        orders, Order = self.tables.orders, self.classes.Order
-
-
-        mapper(Order, orders, properties={
-            'description':deferred(orders.c.description)})
-
-        sess = create_session()
-        o1 = sess.query(Order).order_by(Order.id).first()
-        def go():
-            eq_(o1.description, 'order 1')
-        self.sql_count_(1, go)
-
-        sess = create_session()
-        o1 = (sess.query(Order).
-              order_by(Order.id).
-              add_column(orders.c.description).first())[0]
-        def go():
-            eq_(o1.description, 'order 1')
-        self.sql_count_(0, go)
-
-    def test_map_selectable_wo_deferred(self):
-        """test mapping to a selectable with deferred cols,
-        the selectable doesn't include the deferred col.
-
-        """
-
-        Order, orders = self.classes.Order, self.tables.orders
-
-
-        order_select = sa.select([
-                        orders.c.id, 
-                        orders.c.user_id, 
-                        orders.c.address_id, 
-                        orders.c.description,
-                        orders.c.isopen]).alias()
-        mapper(Order, order_select, properties={
-            'description':deferred(order_select.c.description)
-        })
-
-        sess = Session()
-        o1 = sess.query(Order).order_by(Order.id).first()
-        assert 'description' not in o1.__dict__
-        eq_(o1.description, 'order 1')
-
-    def test_deep_options(self):
-        users, items, order_items, Order, Item, User, orders = (self.tables.users,
-                                self.tables.items,
-                                self.tables.order_items,
-                                self.classes.Order,
-                                self.classes.Item,
-                                self.classes.User,
-                                self.tables.orders)
-
-        mapper(Item, items, properties=dict(
-            description=deferred(items.c.description)))
-        mapper(Order, orders, properties=dict(
-            items=relationship(Item, secondary=order_items)))
-        mapper(User, users, properties=dict(
-            orders=relationship(Order, order_by=orders.c.id)))
-
-        sess = create_session()
-        q = sess.query(User).order_by(User.id)
-        l = q.all()
-        item = l[0].orders[1].items[1]
-        def go():
-            eq_(item.description, 'item 4')
-        self.sql_count_(1, go)
-        eq_(item.description, 'item 4')
-
-        sess.expunge_all()
-        l = q.options(sa.orm.undefer('orders.items.description')).all()
-        item = l[0].orders[1].items[1]
-        def go():
-            eq_(item.description, 'item 4')
-        self.sql_count_(0, go)
-        eq_(item.description, 'item 4')
-
-
 class SecondaryOptionsTest(fixtures.MappedTest):
     """test that the contains_eager() option doesn't bleed into a secondary load."""
 
         )
 
 
-class DeferredPopulationTest(fixtures.MappedTest):
-    @classmethod
-    def define_tables(cls, metadata):
-        Table("thing", metadata,
-            Column("id", Integer, primary_key=True, test_needs_autoincrement=True),
-            Column("name", String(20)))
-
-        Table("human", metadata,
-            Column("id", Integer, primary_key=True, test_needs_autoincrement=True),
-            Column("thing_id", Integer, ForeignKey("thing.id")),
-            Column("name", String(20)))
-
-    @classmethod
-    def setup_mappers(cls):
-        thing, human = cls.tables.thing, cls.tables.human
-
-        class Human(cls.Basic): pass
-        class Thing(cls.Basic): pass
-
-        mapper(Human, human, properties={"thing": relationship(Thing)})
-        mapper(Thing, thing, properties={"name": deferred(thing.c.name)})
-
-    @classmethod
-    def insert_data(cls):
-        thing, human = cls.tables.thing, cls.tables.human
-
-        thing.insert().execute([
-            {"id": 1, "name": "Chair"},
-        ])
-
-        human.insert().execute([
-            {"id": 1, "thing_id": 1, "name": "Clark Kent"},
-        ])
-
-    def _test(self, thing):
-        assert "name" in attributes.instance_state(thing).dict
-
-    def test_no_previous_query(self):
-        Thing = self.classes.Thing
-
-        session = create_session()
-        thing = session.query(Thing).options(sa.orm.undefer("name")).first()
-        self._test(thing)
-
-    def test_query_twice_with_clear(self):
-        Thing = self.classes.Thing
-
-        session = create_session()
-        result = session.query(Thing).first()
-        session.expunge_all()
-        thing = session.query(Thing).options(sa.orm.undefer("name")).first()
-        self._test(thing)
-
-    def test_query_twice_no_clear(self):
-        Thing = self.classes.Thing
-
-        session = create_session()
-        result = session.query(Thing).first()
-        thing = session.query(Thing).options(sa.orm.undefer("name")).first()
-        self._test(thing)
-
-    def test_joinedload_with_clear(self):
-        Thing, Human = self.classes.Thing, self.classes.Human
-
-        session = create_session()
-        human = session.query(Human).options(sa.orm.joinedload("thing")).first()
-        session.expunge_all()
-        thing = session.query(Thing).options(sa.orm.undefer("name")).first()
-        self._test(thing)
-
-    def test_joinedload_no_clear(self):
-        Thing, Human = self.classes.Thing, self.classes.Human
-
-        session = create_session()
-        human = session.query(Human).options(sa.orm.joinedload("thing")).first()
-        thing = session.query(Thing).options(sa.orm.undefer("name")).first()
-        self._test(thing)
-
-    def test_join_with_clear(self):
-        Thing, Human = self.classes.Thing, self.classes.Human
-
-        session = create_session()
-        result = session.query(Human).add_entity(Thing).join("thing").first()
-        session.expunge_all()
-        thing = session.query(Thing).options(sa.orm.undefer("name")).first()
-        self._test(thing)
-
-    def test_join_no_clear(self):
-        Thing, Human = self.classes.Thing, self.classes.Human
-
-        session = create_session()
-        result = session.query(Human).add_entity(Thing).join("thing").first()
-        thing = session.query(Thing).options(sa.orm.undefer("name")).first()
-        self._test(thing)
-
-
-
-
 class NoLoadTest(_fixtures.FixtureTest):
     run_inserts = 'once'
     run_deletes = None