initial fixes to get tests to pass on py 3.3, [ticket:2542]

This commit is contained in:
Mike Bayer 2012-08-11 22:25:05 -04:00
parent 159c75b0ca
commit 1018e3b1d6
7 changed files with 54 additions and 40 deletions

View File

@ -46,7 +46,7 @@ except ImportError:
args = [quote(arg) for arg in args] args = [quote(arg) for arg in args]
return os.spawnl(os.P_WAIT, sys.executable, *args) == 0 return os.spawnl(os.P_WAIT, sys.executable, *args) == 0
DEFAULT_VERSION = "0.6.13" DEFAULT_VERSION = "0.6.28"
DEFAULT_URL = "http://pypi.python.org/packages/source/d/distribute/" DEFAULT_URL = "http://pypi.python.org/packages/source/d/distribute/"
SETUPTOOLS_FAKED_VERSION = "0.6c11" SETUPTOOLS_FAKED_VERSION = "0.6c11"
@ -63,7 +63,7 @@ Description: xxx
""" % SETUPTOOLS_FAKED_VERSION """ % SETUPTOOLS_FAKED_VERSION
def _install(tarball): def _install(tarball, install_args=()):
# extracting the tarball # extracting the tarball
tmpdir = tempfile.mkdtemp() tmpdir = tempfile.mkdtemp()
log.warn('Extracting in %s', tmpdir) log.warn('Extracting in %s', tmpdir)
@ -81,7 +81,7 @@ def _install(tarball):
# installing # installing
log.warn('Installing Distribute') log.warn('Installing Distribute')
if not _python_cmd('setup.py', 'install'): if not _python_cmd('setup.py', 'install', *install_args):
log.warn('Something went wrong during the installation.') log.warn('Something went wrong during the installation.')
log.warn('See the error message above.') log.warn('See the error message above.')
finally: finally:
@ -144,7 +144,7 @@ def use_setuptools(version=DEFAULT_VERSION, download_base=DEFAULT_URL,
except ImportError: except ImportError:
return _do_download(version, download_base, to_dir, download_delay) return _do_download(version, download_base, to_dir, download_delay)
try: try:
pkg_resources.require("distribute>="+version) pkg_resources.require("distribute>=" + version)
return return
except pkg_resources.VersionConflict: except pkg_resources.VersionConflict:
e = sys.exc_info()[1] e = sys.exc_info()[1]
@ -167,6 +167,7 @@ def use_setuptools(version=DEFAULT_VERSION, download_base=DEFAULT_URL,
if not no_fake: if not no_fake:
_create_fake_setuptools_pkg_info(to_dir) _create_fake_setuptools_pkg_info(to_dir)
def download_setuptools(version=DEFAULT_VERSION, download_base=DEFAULT_URL, def download_setuptools(version=DEFAULT_VERSION, download_base=DEFAULT_URL,
to_dir=os.curdir, delay=15): to_dir=os.curdir, delay=15):
"""Download distribute from a specified location and return its filename """Download distribute from a specified location and return its filename
@ -203,6 +204,7 @@ def download_setuptools(version=DEFAULT_VERSION, download_base=DEFAULT_URL,
dst.close() dst.close()
return os.path.realpath(saveto) return os.path.realpath(saveto)
def _no_sandbox(function): def _no_sandbox(function):
def __no_sandbox(*args, **kw): def __no_sandbox(*args, **kw):
try: try:
@ -227,6 +229,7 @@ def _no_sandbox(function):
return __no_sandbox return __no_sandbox
def _patch_file(path, content): def _patch_file(path, content):
"""Will backup the file then patch it""" """Will backup the file then patch it"""
existing_content = open(path).read() existing_content = open(path).read()
@ -245,15 +248,18 @@ def _patch_file(path, content):
_patch_file = _no_sandbox(_patch_file) _patch_file = _no_sandbox(_patch_file)
def _same_content(path, content): def _same_content(path, content):
return open(path).read() == content return open(path).read() == content
def _rename_path(path): def _rename_path(path):
new_name = path + '.OLD.%s' % time.time() new_name = path + '.OLD.%s' % time.time()
log.warn('Renaming %s into %s', path, new_name) log.warn('Renaming %s into %s', path, new_name)
os.rename(path, new_name) os.rename(path, new_name)
return new_name return new_name
def _remove_flat_installation(placeholder): def _remove_flat_installation(placeholder):
if not os.path.isdir(placeholder): if not os.path.isdir(placeholder):
log.warn('Unkown installation at %s', placeholder) log.warn('Unkown installation at %s', placeholder)
@ -289,11 +295,13 @@ def _remove_flat_installation(placeholder):
_remove_flat_installation = _no_sandbox(_remove_flat_installation) _remove_flat_installation = _no_sandbox(_remove_flat_installation)
def _after_install(dist): def _after_install(dist):
log.warn('After install bootstrap.') log.warn('After install bootstrap.')
placeholder = dist.get_command_obj('install').install_purelib placeholder = dist.get_command_obj('install').install_purelib
_create_fake_setuptools_pkg_info(placeholder) _create_fake_setuptools_pkg_info(placeholder)
def _create_fake_setuptools_pkg_info(placeholder): def _create_fake_setuptools_pkg_info(placeholder):
if not placeholder or not os.path.exists(placeholder): if not placeholder or not os.path.exists(placeholder):
log.warn('Could not find the install location') log.warn('Could not find the install location')
@ -306,6 +314,9 @@ def _create_fake_setuptools_pkg_info(placeholder):
log.warn('%s already exists', pkg_info) log.warn('%s already exists', pkg_info)
return return
if not os.access(pkg_info, os.W_OK):
log.warn("Don't have permissions to write %s, skipping", pkg_info)
log.warn('Creating %s', pkg_info) log.warn('Creating %s', pkg_info)
f = open(pkg_info, 'w') f = open(pkg_info, 'w')
try: try:
@ -321,7 +332,10 @@ def _create_fake_setuptools_pkg_info(placeholder):
finally: finally:
f.close() f.close()
_create_fake_setuptools_pkg_info = _no_sandbox(_create_fake_setuptools_pkg_info) _create_fake_setuptools_pkg_info = _no_sandbox(
_create_fake_setuptools_pkg_info
)
def _patch_egg_dir(path): def _patch_egg_dir(path):
# let's check if it's already patched # let's check if it's already patched
@ -343,6 +357,7 @@ def _patch_egg_dir(path):
_patch_egg_dir = _no_sandbox(_patch_egg_dir) _patch_egg_dir = _no_sandbox(_patch_egg_dir)
def _before_install(): def _before_install():
log.warn('Before install bootstrap.') log.warn('Before install bootstrap.')
_fake_setuptools() _fake_setuptools()
@ -351,7 +366,7 @@ def _before_install():
def _under_prefix(location): def _under_prefix(location):
if 'install' not in sys.argv: if 'install' not in sys.argv:
return True return True
args = sys.argv[sys.argv.index('install')+1:] args = sys.argv[sys.argv.index('install') + 1:]
for index, arg in enumerate(args): for index, arg in enumerate(args):
for option in ('--root', '--prefix'): for option in ('--root', '--prefix'):
if arg.startswith('%s=' % option): if arg.startswith('%s=' % option):
@ -359,7 +374,7 @@ def _under_prefix(location):
return location.startswith(top_dir) return location.startswith(top_dir)
elif arg == option: elif arg == option:
if len(args) > index: if len(args) > index:
top_dir = args[index+1] top_dir = args[index + 1]
return location.startswith(top_dir) return location.startswith(top_dir)
if arg == '--user' and USER_SITE is not None: if arg == '--user' and USER_SITE is not None:
return location.startswith(USER_SITE) return location.startswith(USER_SITE)
@ -376,11 +391,14 @@ def _fake_setuptools():
return return
ws = pkg_resources.working_set ws = pkg_resources.working_set
try: try:
setuptools_dist = ws.find(pkg_resources.Requirement.parse('setuptools', setuptools_dist = ws.find(
replacement=False)) pkg_resources.Requirement.parse('setuptools', replacement=False)
)
except TypeError: except TypeError:
# old distribute API # old distribute API
setuptools_dist = ws.find(pkg_resources.Requirement.parse('setuptools')) setuptools_dist = ws.find(
pkg_resources.Requirement.parse('setuptools')
)
if setuptools_dist is None: if setuptools_dist is None:
log.warn('No setuptools distribution found') log.warn('No setuptools distribution found')
@ -422,7 +440,8 @@ def _relaunch():
log.warn('Relaunching...') log.warn('Relaunching...')
# we have to relaunch the process # we have to relaunch the process
# pip marker to avoid a relaunch bug # pip marker to avoid a relaunch bug
if sys.argv[:3] == ['-c', 'install', '--single-version-externally-managed']: _cmd = ['-c', 'install', '--single-version-externally-managed']
if sys.argv[:3] == _cmd:
sys.argv[0] = 'setup.py' sys.argv[0] = 'setup.py'
args = [sys.executable] + sys.argv args = [sys.executable] + sys.argv
sys.exit(subprocess.call(args)) sys.exit(subprocess.call(args))
@ -448,7 +467,7 @@ def _extractall(self, path=".", members=None):
# Extract directories with a safe mode. # Extract directories with a safe mode.
directories.append(tarinfo) directories.append(tarinfo)
tarinfo = copy.copy(tarinfo) tarinfo = copy.copy(tarinfo)
tarinfo.mode = 448 # decimal for oct 0700 tarinfo.mode = 448 # decimal for oct 0700
self.extract(tarinfo, path) self.extract(tarinfo, path)
# Reverse sort directories. # Reverse sort directories.
@ -475,10 +494,21 @@ def _extractall(self, path=".", members=None):
self._dbg(1, "tarfile: %s" % e) self._dbg(1, "tarfile: %s" % e)
def _build_install_args(argv):
install_args = []
user_install = '--user' in argv
if user_install and sys.version_info < (2, 6):
log.warn("--user requires Python 2.6 or later")
raise SystemExit(1)
if user_install:
install_args.append('--user')
return install_args
def main(argv, version=DEFAULT_VERSION): def main(argv, version=DEFAULT_VERSION):
"""Install or upgrade setuptools and EasyInstall""" """Install or upgrade setuptools and EasyInstall"""
tarball = download_setuptools() tarball = download_setuptools()
_install(tarball) _install(tarball, _build_install_args(argv))
if __name__ == '__main__': if __name__ == '__main__':

View File

@ -1125,8 +1125,9 @@ class ParseConnectTest(fixtures.TestBase, AssertsCompiledSQL):
url.make_url('mssql://username:password@mydsn/?LANGUAGE=us_' url.make_url('mssql://username:password@mydsn/?LANGUAGE=us_'
'english&foo=bar') 'english&foo=bar')
connection = dialect.create_connect_args(u) connection = dialect.create_connect_args(u)
eq_([['dsn=mydsn;UID=username;PWD=password;LANGUAGE=us_english;' dsn_string = connection[0][0]
'foo=bar'], {}], connection) assert ";LANGUAGE=us_english" in dsn_string
assert ";foo=bar" in dsn_string
def test_pyodbc_connect(self): def test_pyodbc_connect(self):
u = url.make_url('mssql://username:password@hostspec/database') u = url.make_url('mssql://username:password@hostspec/database')

View File

@ -117,7 +117,7 @@ class UserDefinedTest(fixtures.TestBase, AssertsCompiledSQL):
assert_raises_message( assert_raises_message(
exc.CompileError, exc.CompileError,
"<class 'test.ext.test_compiler.MyThingy'> " "<class 'test.ext.test_compiler..*MyThingy'> "
"construct has no default compilation handler.", "construct has no default compilation handler.",
str, MyThingy('x') str, MyThingy('x')
) )

View File

@ -845,9 +845,9 @@ class DeclarativeTest(DeclarativeTestBase):
sa.exc.SAWarning, sa.exc.SAWarning,
r"Regular \(i.e. not __special__\) attribute 'MyBase.somecol' " r"Regular \(i.e. not __special__\) attribute 'MyBase.somecol' "
"uses @declared_attr, but owning class " "uses @declared_attr, but owning class "
"<class 'test.ext.test_declarative.MyBase'> is " "<class 'test.ext..*test_declarative..*MyBase'> is "
"mapped - not applying to subclass <class " "mapped - not applying to subclass <class "
"'test.ext.test_declarative.MyClass'>.", "'test.ext..*test_declarative..*MyClass'>.",
go go
) )

View File

@ -798,10 +798,10 @@ class EagerTest(_fixtures.FixtureTest, testing.AssertsCompiledSQL):
mapper(User, users, properties=odict( mapper(User, users, properties=odict(
orders=relationship(Order, backref='user') orders=relationship(Order, backref='user')
)) ))
mapper(Order, orders, properties=odict( mapper(Order, orders, properties=odict([
items=relationship(Item, secondary=order_items, backref='orders'), ('items', relationship(Item, secondary=order_items, backref='orders')),
address=relationship(Address) ('address', relationship(Address))
)) ]))
mapper(Address, addresses) mapper(Address, addresses)
mapper(Item, items) mapper(Item, items)

View File

@ -1236,23 +1236,6 @@ class FilterTest(QueryTest, AssertsCompiledSQL):
create_session().query(User.id).filter_by(**{}).order_by(User.id).all() create_session().query(User.id).filter_by(**{}).order_by(User.id).all()
) )
def test_filter_conjunctions(self):
User = self.classes.User
s = create_session()
self.assert_compile(
s.query(User).filter(User.name=="ed", User.id>5),
"SELECT users.id AS users_id, users.name "
"AS users_name FROM users WHERE users.name = "
":name_1 AND users.id > :id_1"
)
self.assert_compile(
s.query(User).filter_by(name='ed', id=5),
"SELECT users.id AS users_id, users.name "
"AS users_name FROM users WHERE users.name "
"= :name_1 AND users.id = :id_1"
)
def test_text_coerce(self): def test_text_coerce(self):
User = self.classes.User User = self.classes.User
s = create_session() s = create_session()

View File

@ -1198,7 +1198,7 @@ class ColumnDefinitionTest(AssertsCompiledSQL, fixtures.TestBase):
assert_raises_message( assert_raises_message(
TypeError, TypeError,
"Could not create a copy of this <class " "Could not create a copy of this <class "
"'test.sql.test_metadata.MyColumn'> " "'test.sql.test_metadata..*MyColumn'> "
"object. Ensure the class includes a _constructor()", "object. Ensure the class includes a _constructor()",
getattr, select([t1.select().alias()]), 'c' getattr, select([t1.select().alias()]), 'c'
) )