[Checkins] SVN: BTrees/branches/pure_python/ Coverage for BTrees._base.multiunion.
Tres Seaver
cvs-admin at zope.org
Tue Dec 4 20:17:49 UTC 2012
Log message for revision 128506:
Coverage for BTrees._base.multiunion.
Changed:
_U BTrees/branches/pure_python/
U BTrees/branches/pure_python/BTrees/_base.py
U BTrees/branches/pure_python/BTrees/tests/test__base.py
-=-
Modified: BTrees/branches/pure_python/BTrees/_base.py
===================================================================
--- BTrees/branches/pure_python/BTrees/_base.py 2012-12-04 20:17:48 UTC (rev 128505)
+++ BTrees/branches/pure_python/BTrees/_base.py 2012-12-04 20:17:49 UTC (rev 128506)
@@ -1253,8 +1253,6 @@
def multiunion(set_type, seqs):
# XXX simple/slow implementation. Goal is just to get tests to pass.
- if not seqs:
- return set_type()
result = set_type()
for s in seqs:
try:
Modified: BTrees/branches/pure_python/BTrees/tests/test__base.py
===================================================================
--- BTrees/branches/pure_python/BTrees/tests/test__base.py 2012-12-04 20:17:48 UTC (rev 128505)
+++ BTrees/branches/pure_python/BTrees/tests/test__base.py 2012-12-04 20:17:49 UTC (rev 128506)
@@ -2690,6 +2690,29 @@
self.assertEqual(result['a'], 23)
+class Test_multiunion(unittest.TestCase, _SetObBase):
+
+ def _callFUT(self, *args, **kw):
+ from .._base import multiunion
+ return multiunion(*args, **kw)
+
+ def test_no_seqs(self):
+ result = self._callFUT(_Set, ())
+ self.assertEqual(list(result), [])
+
+ def test_w_non_iterable_seq(self):
+ result = self._callFUT(_Set, (1, 2))
+ self.assertEqual(list(result), [1, 2])
+
+ def test_w_iterable_seqs(self):
+ result = self._callFUT(_Set, [(1,), (2,)])
+ self.assertEqual(list(result), [1, 2])
+
+ def test_w_mix(self):
+ result = self._callFUT(_Set, [1, (2,)])
+ self.assertEqual(list(result), [1, 2])
+
+
class _Cache(object):
def __init__(self):
self._mru = []
@@ -2709,12 +2732,17 @@
class _Set(object):
def __init__(self, *args, **kw):
- keys = set(args)
+ if len(args) == 1 and isinstance(args[0], tuple):
+ keys = args[0]
+ else:
+ keys = set(args)
self._keys = sorted(keys)
def keys(self):
return self._keys
def __iter__(self):
return iter(self._keys)
+ def update(self, items):
+ self._keys = sorted(self._keys + list(items))
_Set._set_type = _Set
@@ -2764,4 +2792,5 @@
unittest.makeSuite(Test_intersection),
unittest.makeSuite(Test_weightedUnion),
unittest.makeSuite(Test_weightedIntersection),
+ unittest.makeSuite(Test_multiunion),
))
More information about the checkins
mailing list