1
from sqlalchemy.test.testing import assert_raises, assert_raises_message
1
from test.lib.testing import assert_raises, assert_raises_message
2
2
import copy, threading
3
3
from sqlalchemy import util, sql, exc
4
from sqlalchemy.test import TestBase
5
from sqlalchemy.test.testing import eq_, is_, ne_
6
from sqlalchemy.test.util import gc_collect, picklers
4
from test.lib.testing import eq_, is_, ne_, fails_if
5
from test.lib.util import gc_collect, picklers
7
6
from sqlalchemy.util import classproperty
10
class OrderedDictTest(TestBase):
7
from test.lib import fixtures
9
class OrderedDictTest(fixtures.TestBase):
11
10
def test_odict(self):
12
11
o = util.OrderedDict()
72
71
eq_(o3.keys(), o.keys())
74
class OrderedSetTest(TestBase):
73
class OrderedSetTest(fixtures.TestBase):
75
74
def test_mutators_against_iter(self):
76
75
# testing a set modified against an iterator
77
76
o = util.OrderedSet([3,2, 4, 5])
80
79
eq_(o.intersection(iter([3,4, 6])), util.OrderedSet([3, 4]))
81
80
eq_(o.union(iter([3,4, 6])), util.OrderedSet([2, 3, 4, 5, 6]))
83
class FrozenDictTest(TestBase):
82
class FrozenDictTest(fixtures.TestBase):
84
83
def test_serialize(self):
85
d = util.frozendict({1:2, 3:4})
84
d = util.immutabledict({1:2, 3:4})
86
85
for loads, dumps in picklers():
87
86
print loads(dumps(d))
90
class MemoizedAttrTest(TestBase):
89
class MemoizedAttrTest(fixtures.TestBase):
91
90
def test_memoized_property(self):
196
195
class ImmutableSubclass(str):
199
class FlattenIteratorTest(TestBase):
198
class FlattenIteratorTest(fixtures.TestBase):
201
200
def test_flatten(self):
202
201
assert list(util.flatten_iterator([[1, 2, 3], [4, 5, 6], 7,
370
370
assert_raises(TypeError, lambda: s1 - os2)
371
371
assert_raises(TypeError, lambda: s1 - [3, 4, 5])
373
class OrderedIdentitySetTest(TestBase):
373
class OrderedIdentitySetTest(fixtures.TestBase):
375
375
def assert_eq(self, identityset, expected_iterable):
376
376
expected = [id(o) for o in expected_iterable]
398
398
eq_(s1.union(s2).intersection(s3), [a, d, f])
401
class DictlikeIteritemsTest(TestBase):
401
class DictlikeIteritemsTest(fixtures.TestBase):
402
402
baseline = set([('a', 1), ('b', 2), ('c', 3)])
404
404
def _ok(self, instance):
860
860
'apply_kw': 'a=a, b=b', 'apply_pos': 'a, b' },
863
@fails_if(lambda: util.pypy, "object.__init__ is introspectable")
863
864
def test_init_grouped(self):
865
866
'args': '(self)', 'self_arg': 'self',
875
876
self._test_init(None, object_spec, wrapper_spec, custom_spec)
876
877
self._test_init(True, object_spec, wrapper_spec, custom_spec)
879
@fails_if(lambda: util.pypy, "object.__init__ can be introspected")
878
880
def test_init_bare(self):
880
882
'args': 'self', 'self_arg': 'self',
936
938
test(O.__init__, custom_spec)
938
class AsInterfaceTest(TestBase):
941
class GenericReprTest(fixtures.TestBase):
942
def test_all_positional(self):
944
def __init__(self, a, b, c):
949
util.generic_repr(Foo(1, 2, 3)),
953
def test_positional_plus_kw(self):
955
def __init__(self, a, b, c=5, d=4):
961
util.generic_repr(Foo(1, 2, 3, 6)),
962
"Foo(1, 2, c=3, d=6)"
965
def test_kw_defaults(self):
967
def __init__(self, a=1, b=2, c=3, d=4):
973
util.generic_repr(Foo(1, 5, 3, 7)),
977
def test_discard_vargs(self):
979
def __init__(self, a, b, *args):
982
self.c, self.d = args[0:2]
984
util.generic_repr(Foo(1, 2, 3, 4)),
988
def test_discard_vargs_kwargs(self):
990
def __init__(self, a, b, *args, **kw):
993
self.c, self.d = args[0:2]
995
util.generic_repr(Foo(1, 2, 3, 4, x=7, y=4)),
999
def test_significant_vargs(self):
1001
def __init__(self, a, b, *args):
1006
util.generic_repr(Foo(1, 2, 3, 4)),
1010
def test_no_args(self):
1015
util.generic_repr(Foo()),
1019
def test_no_init(self):
1023
util.generic_repr(Foo()),
1027
class AsInterfaceTest(fixtures.TestBase):
940
1029
class Something(object):
941
1030
def _ignoreme(self): pass