summaryrefslogtreecommitdiff
path: root/test
diff options
context:
space:
mode:
Diffstat (limited to 'test')
-rw-r--r--test/orm/mapper.py9
-rw-r--r--test/testbase.py14
2 files changed, 23 insertions, 0 deletions
diff --git a/test/orm/mapper.py b/test/orm/mapper.py
index b2118b647..d1c4cf546 100644
--- a/test/orm/mapper.py
+++ b/test/orm/mapper.py
@@ -541,6 +541,15 @@ class MapperTest(MapperSuperTest):
assert len(u.addresses) == 3
self.assert_sql_count(db, go, 0)
+ sess.clear()
+
+ # test that eager loading doesnt modify parent mapper
+ def go():
+ u = sess.query(User).get_by(user_id=8)
+ assert u.user_id == 8
+ assert len(u.addresses) == 3
+ assert "tbl_row_count" not in self.capture_sql(db, go)
+
def testlazyoptionswithlimit(self):
sess = create_session()
mapper(User, users, properties = dict(
diff --git a/test/testbase.py b/test/testbase.py
index aae455673..1bcc5c142 100644
--- a/test/testbase.py
+++ b/test/testbase.py
@@ -224,6 +224,17 @@ class AssertMixin(PersistTest):
finally:
self.assert_(testdata.sql_count == count, "desired statement count %d does not match %d" % (count, testdata.sql_count))
+ def capture_sql(self, db, callable_):
+ global testdata
+ testdata = TestData(db)
+ buffer = StringIO.StringIO()
+ testdata.buffer = buffer
+ try:
+ callable_()
+ return buffer.getvalue()
+ finally:
+ testdata.buffer = None
+
class ORMTest(AssertMixin):
keep_mappers = False
keep_data = False
@@ -251,6 +262,7 @@ class TestData(object):
self.logger = engine.logger
self.set_assert_list(None, None)
self.sql_count = 0
+ self.buffer = None
def set_assert_list(self, unittest, list):
self.unittest = unittest
@@ -270,6 +282,8 @@ class ExecutionContextWrapper(object):
ctx = self.ctx
statement = unicode(ctx.compiled)
statement = re.sub(r'\n', '', ctx.statement)
+ if testdata.buffer is not None:
+ testdata.buffer.write(statement + "\n")
if testdata.assert_list is not None:
item = testdata.assert_list[-1]