diff options
author | Jason Kirtland <jek@discorporate.us> | 2008-01-21 23:19:39 +0000 |
---|---|---|
committer | Jason Kirtland <jek@discorporate.us> | 2008-01-21 23:19:39 +0000 |
commit | 412c80dd6c5d6b940e86e7e142aa1fdd6ee4466d (patch) | |
tree | 2a5bfa8185dd888d52b31bfb26ada56c7db89139 /test/testlib/compat.py | |
parent | 08bbc3dfd84234c3cd691e43ff17ed36e2396d76 (diff) | |
download | sqlalchemy-412c80dd6c5d6b940e86e7e142aa1fdd6ee4466d.tar.gz |
- 2.3 fixup, part two: 100% passing for sqlite
- added 2.4-style binops to util.Set on 2.3
- OrderedSets pickle on 2.3
- more lib/sqlalchemy set vs Set corrections
- fixed InstrumentedSet.discard for 2.3
- set, sorted compatibility for test suite
- added testing.fails_if decorator
Diffstat (limited to 'test/testlib/compat.py')
-rw-r--r-- | test/testlib/compat.py | 57 |
1 files changed, 53 insertions, 4 deletions
diff --git a/test/testlib/compat.py b/test/testlib/compat.py index 590bf50f4..8d2b35d4a 100644 --- a/test/testlib/compat.py +++ b/test/testlib/compat.py @@ -1,17 +1,66 @@ -import new +import itertools, new __all__ = 'set', 'sorted', '_function_named' try: set = set except NameError: - from sets import Set as set + import sets + + # keep this in sync with sqlalchemy.util.Set + # can't just import it in testlib because of coverage, load order, etc. + class set(sets.Set): + def _binary_sanity_check(self, other): + pass + + def issubset(self, iterable): + other = type(self)(iterable) + return sets.Set.issubset(self, other) + def __le__(self, other): + sets.Set._binary_sanity_check(self, other) + return sets.Set.__le__(self, other) + def issuperset(self, iterable): + other = type(self)(iterable) + return sets.Set.issuperset(self, other) + def __ge__(self, other): + sets.Set._binary_sanity_check(self, other) + return sets.Set.__ge__(self, other) + + # lt and gt still require a BaseSet + def __lt__(self, other): + sets.Set._binary_sanity_check(self, other) + return sets.Set.__lt__(self, other) + def __gt__(self, other): + sets.Set._binary_sanity_check(self, other) + return sets.Set.__gt__(self, other) + + def __ior__(self, other): + if not isinstance(other, sets.BaseSet): + return NotImplemented + return sets.Set.__ior__(self, other) + def __iand__(self, other): + if not isinstance(other, sets.BaseSet): + return NotImplemented + return sets.Set.__iand__(self, other) + def __ixor__(self, other): + if not isinstance(other, sets.BaseSet): + return NotImplemented + return sets.Set.__ixor__(self, other) + def __isub__(self, other): + if not isinstance(other, sets.BaseSet): + return NotImplemented + return sets.Set.__isub__(self, other) try: sorted = sorted except NameError: - def sorted(iterable): - return list(iterable).sort() + def sorted(iterable, cmp=None): + l = list(iterable) + if cmp: + l.sort(cmp) + else: + l.sort() + return l def _function_named(fn, newname): try: |