diff options
| author | Mike Bayer <mike_mp@zzzcomputing.com> | 2013-06-07 17:51:12 -0400 |
|---|---|---|
| committer | Mike Bayer <mike_mp@zzzcomputing.com> | 2013-06-07 17:51:12 -0400 |
| commit | 0d9ec9fe840eb71935c2a55c3063620a028e59aa (patch) | |
| tree | b1243b5b7bba44066d3f5bb451f0d3ab2c97cd57 /test | |
| parent | 1188edccf6b796fdc2d8bd24985a71fb6060eae7 (diff) | |
| download | sqlalchemy-0d9ec9fe840eb71935c2a55c3063620a028e59aa.tar.gz | |
remove all remaining start/end py2k/py3k blocks
Diffstat (limited to 'test')
| -rw-r--r-- | test/base/test_except.py | 11 | ||||
| -rw-r--r-- | test/base/test_utils.py | 85 | ||||
| -rw-r--r-- | test/orm/test_mapper.py | 46 | ||||
| -rw-r--r-- | test/orm/test_query.py | 32 | ||||
| -rw-r--r-- | test/orm/test_utils.py | 49 |
5 files changed, 96 insertions, 127 deletions
diff --git a/test/base/test_except.py b/test/base/test_except.py index f2428c22d..75e411c5e 100644 --- a/test/base/test_except.py +++ b/test/base/test_except.py @@ -2,15 +2,14 @@ from sqlalchemy import exc as sa_exceptions +from sqlalchemy import util from sqlalchemy.testing import fixtures from sqlalchemy.testing import eq_ -# start Py3K -Exception = BaseException -# end Py3K -# start Py2K -#from exceptions import StandardError, KeyboardInterrupt, SystemExit -# end Py2K +if util.py2k: + from exceptions import StandardError, KeyboardInterrupt, SystemExit +else: + Exception = BaseException class Error(Exception): diff --git a/test/base/test_utils.py b/test/base/test_utils.py index 194ef1222..aefc6d421 100644 --- a/test/base/test_utils.py +++ b/test/base/test_utils.py @@ -968,23 +968,21 @@ class DictlikeIteritemsTest(fixtures.TestBase): d = subdict(a=1, b=2, c=3) self._ok(d) -# start Py2K -# def test_UserDict(self): -# import UserDict -# d = UserDict.UserDict(a=1, b=2, c=3) -# self._ok(d) -# end Py2K + if util.py2k: + def test_UserDict(self): + import UserDict + d = UserDict.UserDict(a=1, b=2, c=3) + self._ok(d) def test_object(self): self._notok(object()) -# start Py2K -# def test_duck_1(self): -# class duck1(object): -# def iteritems(duck): -# return iter(self.baseline) -# self._ok(duck1()) -# end Py2K + if util.py2k: + def test_duck_1(self): + class duck1(object): + def iteritems(duck): + return iter(self.baseline) + self._ok(duck1()) def test_duck_2(self): class duck2(object): @@ -992,16 +990,15 @@ class DictlikeIteritemsTest(fixtures.TestBase): return list(self.baseline) self._ok(duck2()) -# start Py2K -# def test_duck_3(self): -# class duck3(object): -# def iterkeys(duck): -# return iter(['a', 'b', 'c']) -# -# def __getitem__(duck, key): -# return dict(a=1, b=2, c=3).get(key) -# self._ok(duck3()) -# end Py2K + if util.py2k: + def test_duck_3(self): + class duck3(object): + def iterkeys(duck): + return iter(['a', 'b', 'c']) + + def __getitem__(duck, key): + return dict(a=1, b=2, c=3).get(key) + self._ok(duck3()) def test_duck_4(self): class duck4(object): @@ -1028,10 +1025,6 @@ class DictlikeIteritemsTest(fixtures.TestBase): class DuckTypeCollectionTest(fixtures.TestBase): def test_sets(self): -# start Py2K -# import sets -# end Py2K - class SetLike(object): def add(self): pass @@ -1040,20 +1033,13 @@ class DuckTypeCollectionTest(fixtures.TestBase): __emulates__ = set for type_ in (set, -# start Py2K -# sets.Set, -# end Py2K SetLike, ForcedSet): eq_(util.duck_type_collection(type_), set) instance = type_() eq_(util.duck_type_collection(instance), set) - for type_ in (frozenset, -# start Py2K -# sets.ImmutableSet -# end Py2K - ): + for type_ in (frozenset, ): is_(util.duck_type_collection(type_), None) instance = type_() is_(util.duck_type_collection(instance), None) @@ -1569,21 +1555,20 @@ class TestClassHierarchy(fixtures.TestBase): eq_(set(util.class_hierarchy(A)), set((A, B, C, object))) eq_(set(util.class_hierarchy(B)), set((A, B, C, object))) -# start Py2K -# def test_oldstyle_mixin(self): -# class A(object): -# pass -# -# class Mixin: -# pass -# -# class B(A, Mixin): -# pass -# -# eq_(set(util.class_hierarchy(B)), set((A, B, object))) -# eq_(set(util.class_hierarchy(Mixin)), set()) -# eq_(set(util.class_hierarchy(A)), set((A, B, object))) -# end Py2K + if util.py2k: + def test_oldstyle_mixin(self): + class A(object): + pass + + class Mixin: + pass + + class B(A, Mixin): + pass + + eq_(set(util.class_hierarchy(B)), set((A, B, object))) + eq_(set(util.class_hierarchy(Mixin)), set()) + eq_(set(util.class_hierarchy(A)), set((A, B, object))) class TestClassProperty(fixtures.TestBase): diff --git a/test/orm/test_mapper.py b/test/orm/test_mapper.py index ed09e72c1..06ec4ce27 100644 --- a/test/orm/test_mapper.py +++ b/test/orm/test_mapper.py @@ -272,14 +272,11 @@ class MapperTest(_fixtures.FixtureTest, AssertsCompiledSQL): ) m = mapper(Foo, foo_t) class DontCompareMeToString(int): -# start Py3K - pass -# end Py3K -# start Py2K -# def __lt__(self, other): -# assert not isinstance(other, basestring) -# return int(self) < other -# end Py2K + if util.py2k: + def __lt__(self, other): + assert not isinstance(other, basestring) + return int(self) < other + foos = [Foo(id='f%d' % i) for i in range(5)] states = [attributes.instance_state(f) for f in foos] @@ -2989,23 +2986,22 @@ class RequirementsTest(fixtures.MappedTest): Column('ht1b_id', Integer, ForeignKey('ht1.id'), primary_key=True), Column('value', String(10))) -# start Py2K -# def test_baseclass(self): -# ht1 = self.tables.ht1 -# -# class OldStyle: -# pass -# -# assert_raises(sa.exc.ArgumentError, mapper, OldStyle, ht1) -# -# assert_raises(sa.exc.ArgumentError, mapper, 123) -# -# class NoWeakrefSupport(str): -# pass -# -# # TODO: is weakref support detectable without an instance? -# #self.assertRaises(sa.exc.ArgumentError, mapper, NoWeakrefSupport, t2) -# end Py2K + if util.py2k: + def test_baseclass(self): + ht1 = self.tables.ht1 + + class OldStyle: + pass + + assert_raises(sa.exc.ArgumentError, mapper, OldStyle, ht1) + + assert_raises(sa.exc.ArgumentError, mapper, 123) + + class NoWeakrefSupport(str): + pass + + # TODO: is weakref support detectable without an instance? + #self.assertRaises(sa.exc.ArgumentError, mapper, NoWeakrefSupport, t2) class _ValueBase(object): def __init__(self, value='abc', id=None): diff --git a/test/orm/test_query.py b/test/orm/test_query.py index 2e0355e63..c38fb351e 100644 --- a/test/orm/test_query.py +++ b/test/orm/test_query.py @@ -1,4 +1,4 @@ -import operator +from sqlalchemy.sql import operators from sqlalchemy import MetaData, null, exists, text, union, literal, \ literal_column, func, between, Unicode, desc, and_, bindparam, \ select, distinct, or_, collate @@ -407,12 +407,7 @@ class GetTest(QueryTest): Column('data', Unicode(40))) try: metadata.create_all() -# start Py3K - ustring = b'petit voix m\xe2\x80\x99a'.decode('utf-8') -# end Py3K -# start Py2K -# ustring = 'petit voix m\xe2\x80\x99a'.decode('utf-8') -# end Py2K + ustring = util.b('petit voix m\xe2\x80\x99a').decode('utf-8') table.insert().execute(id=ustring, data=ustring) class LocalFoo(self.classes.Base): @@ -634,13 +629,10 @@ class OperatorTest(QueryTest, AssertsCompiledSQL): User = self.classes.User create_session().query(User) - for (py_op, sql_op) in ((operator.add, '+'), (operator.mul, '*'), - (operator.sub, '-'), - # Py3k - #(operator.truediv, '/'), -# start Py2K -# (operator.div, '/'), -# end Py2K + for (py_op, sql_op) in ((operators.add, '+'), (operators.mul, '*'), + (operators.sub, '-'), + (operators.truediv, '/'), + (operators.div, '/'), ): for (lhs, rhs, res) in ( (5, User.id, ':id_1 %s users.id'), @@ -660,12 +652,12 @@ class OperatorTest(QueryTest, AssertsCompiledSQL): create_session().query(User) ualias = aliased(User) - for (py_op, fwd_op, rev_op) in ((operator.lt, '<', '>'), - (operator.gt, '>', '<'), - (operator.eq, '=', '='), - (operator.ne, '!=', '!='), - (operator.le, '<=', '>='), - (operator.ge, '>=', '<=')): + for (py_op, fwd_op, rev_op) in ((operators.lt, '<', '>'), + (operators.gt, '>', '<'), + (operators.eq, '=', '='), + (operators.ne, '!=', '!='), + (operators.le, '<=', '>='), + (operators.ge, '>=', '<=')): for (lhs, rhs, l_sql, r_sql) in ( ('a', User.id, ':id_1', 'users.id'), ('a', literal('b'), ':param_2', ':param_1'), # note swap! diff --git a/test/orm/test_utils.py b/test/orm/test_utils.py index 49ff61ea0..d15881075 100644 --- a/test/orm/test_utils.py +++ b/test/orm/test_utils.py @@ -1,6 +1,7 @@ from sqlalchemy.testing import assert_raises, assert_raises_message -from sqlalchemy.orm import util +from sqlalchemy.orm import util as orm_util from sqlalchemy import Column +from sqlalchemy import util from sqlalchemy import Integer from sqlalchemy import MetaData from sqlalchemy import Table @@ -52,10 +53,10 @@ class AliasedClassTest(fixtures.TestBase): alias = aliased(Point) assert Point.zero -# start Py2K -# # TODO: what is this testing ?? -# assert not getattr(alias, 'zero') -# end Py2K + + if util.py2k: + # TODO: what is this testing ?? + assert not getattr(alias, 'zero') def test_classmethods(self): class Point(object): @@ -123,19 +124,15 @@ class AliasedClassTest(fixtures.TestBase): self.func = func def __get__(self, instance, owner): if instance is None: -# start Py3K - args = (self.func, owner) -# end Py3K -# start Py2K -# args = (self.func, owner, owner.__class__) -# end Py2K + if util.py2k: + args = (self.func, owner, owner.__class__) + else: + args = (self.func, owner) else: -# start Py3K - args = (self.func, instance) -# end Py3K -# start Py2K -# args = (self.func, instance, owner) -# end Py2K + if util.py2k: + args = (self.func, instance, owner) + else: + args = (self.func, instance) return types.MethodType(*args) class PropertyDescriptor(object): @@ -195,9 +192,9 @@ class IdentityKeyTest(_fixtures.FixtureTest): mapper(User, users) - key = util.identity_key(User, [1]) + key = orm_util.identity_key(User, [1]) eq_(key, (User, (1,))) - key = util.identity_key(User, ident=[1]) + key = orm_util.identity_key(User, ident=[1]) eq_(key, (User, (1,))) def test_identity_key_scalar(self): @@ -205,9 +202,9 @@ class IdentityKeyTest(_fixtures.FixtureTest): mapper(User, users) - key = util.identity_key(User, 1) + key = orm_util.identity_key(User, 1) eq_(key, (User, (1,))) - key = util.identity_key(User, ident=1) + key = orm_util.identity_key(User, ident=1) eq_(key, (User, (1,))) def test_identity_key_2(self): @@ -218,7 +215,7 @@ class IdentityKeyTest(_fixtures.FixtureTest): u = User(name='u1') s.add(u) s.flush() - key = util.identity_key(instance=u) + key = orm_util.identity_key(instance=u) eq_(key, (User, (u.id,))) def test_identity_key_3(self): @@ -227,7 +224,7 @@ class IdentityKeyTest(_fixtures.FixtureTest): mapper(User, users) row = {users.c.id: 1, users.c.name: "Frank"} - key = util.identity_key(User, row=row) + key = orm_util.identity_key(User, row=row) eq_(key, (User, (1,))) @@ -244,12 +241,12 @@ class PathRegistryTest(_fixtures.FixtureTest): def test_root_registry(self): umapper = inspect(self.classes.User) is_( - util.RootRegistry()[umapper], + orm_util.RootRegistry()[umapper], umapper._path_registry ) eq_( - util.RootRegistry()[umapper], - util.PathRegistry.coerce((umapper,)) + orm_util.RootRegistry()[umapper], + orm_util.PathRegistry.coerce((umapper,)) ) def test_expand(self): |
