Files
sqlalchemy/doc/build/testdocs.py
T
Mike Bayer fe250af8eb - lazy loads for relationship attributes now use
the current state, not the "committed" state,
of foreign and primary key attributes
when issuing SQL, if a flush is not in process.
Previously, only the database-committed state would
be used.  In particular, this would cause a many-to-one
get()-on-lazyload operation to fail, as autoflush
is not triggered on these loads when the attributes are
determined and the "committed" state may not be
available.  [ticket:1910]

- A new flag on relationship(), load_on_pending, allows
the lazy loader to fire off on pending objects without a
flush taking place, as well as a transient object that's
been manually "attached" to the session. Note that this
flag blocks attribute events from taking place when an
object is loaded, so backrefs aren't available until
after a flush. The flag is only intended for very
specific use cases.
2010-09-12 19:18:08 -04:00

72 lines
1.9 KiB
Python

import sys
sys.path = ['../../lib', './lib/'] + sys.path
import os
import re
import doctest
import sqlalchemy.util as util
import sqlalchemy.log as salog
import logging
salog.default_enabled=True
rootlogger = logging.getLogger('sqlalchemy')
rootlogger.setLevel(logging.NOTSET)
class MyStream(object):
def write(self, string):
sys.stdout.write(string)
sys.stdout.flush()
def flush(self):
pass
handler = logging.StreamHandler(MyStream())
handler.setFormatter(logging.Formatter('%(message)s'))
rootlogger.addHandler(handler)
def teststring(s, name, globs=None, verbose=None, report=True,
optionflags=0, extraglobs=None, raise_on_error=False,
parser=doctest.DocTestParser()):
from doctest import DebugRunner, DocTestRunner, master
# Assemble the globals.
if globs is None:
globs = {}
else:
globs = globs.copy()
if extraglobs is not None:
globs.update(extraglobs)
if raise_on_error:
runner = DebugRunner(verbose=verbose, optionflags=optionflags)
else:
runner = DocTestRunner(verbose=verbose, optionflags=optionflags)
test = parser.get_doctest(s, globs, name, name, 0)
runner.run(test)
if report:
runner.summarize()
if master is None:
master = runner
else:
master.merge(runner)
return runner.failures, runner.tries
def replace_file(s, newfile):
engine = r"'(sqlite|postgresql|mysql):///.*'"
engine = re.compile(engine, re.MULTILINE)
s, n = re.subn(engine, "'sqlite:///" + newfile + "'", s)
if not n:
raise ValueError("Couldn't find suitable create_engine call to replace '%s' in it" % oldfile)
return s
for filename in ('orm/tutorial', 'core/tutorial'):
filename = '%s.rst' % filename
s = open(filename).read()
#s = replace_file(s, ':memory:')
s = re.sub(r'{(?:stop|sql|opensql)}', '', s)
teststring(s, filename)