From 6cde27fe9161a21b075c7b8faa09d1e77169f1f2 Mon Sep 17 00:00:00 2001 From: Mike Bayer Date: Sun, 26 May 2013 19:06:13 -0400 Subject: a pass where we try to squash down as many list()/keys() combinations as possible --- lib/sqlalchemy/testing/engines.py | 42 ++++++++++++++++++-------------------- lib/sqlalchemy/testing/entities.py | 2 +- lib/sqlalchemy/testing/schema.py | 4 ++-- 3 files changed, 23 insertions(+), 25 deletions(-) (limited to 'lib/sqlalchemy/testing') diff --git a/lib/sqlalchemy/testing/engines.py b/lib/sqlalchemy/testing/engines.py index cfaacc490..efc0103f2 100644 --- a/lib/sqlalchemy/testing/engines.py +++ b/lib/sqlalchemy/testing/engines.py @@ -8,7 +8,7 @@ from .util import decorator from .. import event, pool import re import warnings - +from .. import util class ConnectionKiller(object): @@ -37,12 +37,12 @@ class ConnectionKiller(object): "rollback/close connection: %s" % e) def rollback_all(self): - for rec in list(self.proxy_refs.keys()): + for rec in list(self.proxy_refs): if rec is not None and rec.is_valid: self._safe(rec.rollback) def close_all(self): - for rec in list(self.proxy_refs.keys()): + for rec in list(self.proxy_refs): if rec is not None: self._safe(rec._close) @@ -66,7 +66,7 @@ class ConnectionKiller(object): self.conns = set() - for rec in list(self.testing_engines.keys()): + for rec in list(self.testing_engines): if rec is not config.db: rec.dispose() @@ -75,7 +75,7 @@ class ConnectionKiller(object): for conn in self.conns: self._safe(conn.close) self.conns = set() - for rec in list(self.testing_engines.keys()): + for rec in list(self.testing_engines): rec.dispose() def assert_all_closed(self): @@ -353,24 +353,22 @@ class ReplayableSession(object): Callable = object() NoAttribute = object() -# start Py3K - Natives = set([getattr(types, t) - for t in dir(types) if not t.startswith('_')]). \ - union([type(t) if not isinstance(t, type) - else t for t in list(__builtins__.values())]).\ + if util.py2k: + Natives = set([getattr(types, t) + for t in dir(types) if not t.startswith('_')]).\ difference([getattr(types, t) - for t in ('FunctionType', 'BuiltinFunctionType', - 'MethodType', 'BuiltinMethodType', - 'LambdaType', )]) -# end Py3K -# start Py2K -# Natives = set([getattr(types, t) -# for t in dir(types) if not t.startswith('_')]). \ -# difference([getattr(types, t) -# for t in ('FunctionType', 'BuiltinFunctionType', -# 'MethodType', 'BuiltinMethodType', -# 'LambdaType', 'UnboundMethodType',)]) -# end Py2K + for t in ('FunctionType', 'BuiltinFunctionType', + 'MethodType', 'BuiltinMethodType', + 'LambdaType', 'UnboundMethodType',)]) + else: + Natives = set([getattr(types, t) + for t in dir(types) if not t.startswith('_')]).\ + union([type(t) if not isinstance(t, type) + else t for t in __builtins__.values()]).\ + difference([getattr(types, t) + for t in ('FunctionType', 'BuiltinFunctionType', + 'MethodType', 'BuiltinMethodType', + 'LambdaType', )]) def __init__(self): self.buffer = deque() diff --git a/lib/sqlalchemy/testing/entities.py b/lib/sqlalchemy/testing/entities.py index 221c23c56..c0dd58650 100644 --- a/lib/sqlalchemy/testing/entities.py +++ b/lib/sqlalchemy/testing/entities.py @@ -67,7 +67,7 @@ class ComparableEntity(BasicEntity): a = self b = other - for attr in list(a.__dict__.keys()): + for attr in list(a.__dict__): if attr.startswith('_'): continue value = getattr(a, attr) diff --git a/lib/sqlalchemy/testing/schema.py b/lib/sqlalchemy/testing/schema.py index 6f3e87cc9..025bbaabe 100644 --- a/lib/sqlalchemy/testing/schema.py +++ b/lib/sqlalchemy/testing/schema.py @@ -11,7 +11,7 @@ table_options = {} def Table(*args, **kw): """A schema.Table wrapper/hook for dialect-specific tweaks.""" - test_opts = dict([(k, kw.pop(k)) for k in list(kw.keys()) + test_opts = dict([(k, kw.pop(k)) for k in list(kw) if k.startswith('test_')]) kw.update(table_options) @@ -58,7 +58,7 @@ def Table(*args, **kw): def Column(*args, **kw): """A schema.Column wrapper/hook for dialect-specific tweaks.""" - test_opts = dict([(k, kw.pop(k)) for k in list(kw.keys()) + test_opts = dict([(k, kw.pop(k)) for k in list(kw) if k.startswith('test_')]) if not config.requirements.foreign_key_ddl.enabled: -- cgit v1.2.1