Commit 7408ed7a authored by Tres Seaver's avatar Tres Seaver

Split out conflict resolution between sets and buckets.

parent 5a1e5949
This diff is collapsed.
...@@ -21,13 +21,6 @@ class Test_BucketBase(unittest.TestCase): ...@@ -21,13 +21,6 @@ class Test_BucketBase(unittest.TestCase):
from .._base import _BucketBase from .._base import _BucketBase
return _BucketBase return _BucketBase
def assertRaises(self, e_type, checked, *args, **kw):
try:
checked(*args, **kw)
except e_type as e:
return e
self.fail("Didn't raise: %s" % e_type.__name__)
def _makeOne(self, *args, **kw): def _makeOne(self, *args, **kw):
return self._getTargetClass()(*args, **kw) return self._getTargetClass()(*args, **kw)
...@@ -362,14 +355,24 @@ class Test_BucketBase(unittest.TestCase): ...@@ -362,14 +355,24 @@ class Test_BucketBase(unittest.TestCase):
for key in KEYS: for key in KEYS:
self.assertTrue(key in bucket) self.assertTrue(key in bucket)
def _with_setstate_set(self):
class _WithSetState(self._getTargetClass()):
def __setstate__(self, state):
self._keys, self._next = state
return _WithSetState()
def _with_setstate_bucket(self): def _assertRaises(self, e_type, checked, *args, **kw):
class _WithSetState(self._getTargetClass()): try:
checked(*args, **kw)
except e_type as e:
return e
self.fail("Didn't raise: %s" % e_type.__name__)
class Test__MappingBase(unittest.TestCase):
assertRaises = _assertRaises
def _getTargetClass(self):
from .._base import _MappingBase
return _MappingBase
def _makeOne(self):
class _TestMapping(self._getTargetClass()):
_values = None _values = None
def __setstate__(self, state): def __setstate__(self, state):
state, self._next = state state, self._next = state
...@@ -378,13 +381,56 @@ class Test_BucketBase(unittest.TestCase): ...@@ -378,13 +381,56 @@ class Test_BucketBase(unittest.TestCase):
for i in range(len(state) // 2): for i in range(len(state) // 2):
self._keys.append(state[i]) self._keys.append(state[i])
self._values.append(state[i+1]) self._values.append(state[i+1])
def clear(self):
self._keys, self._values, self._next = [], [], None
def iteritems(self): def iteritems(self):
return iter(zip(self._keys, self._values)) return iter(zip(self._keys, self._values))
return _WithSetState() return _TestMapping()
def test__p_resolveConflict_delete_first_new(self):
from ..Interfaces import BTreesConflictError
bucket = self._makeOne()
s_old = (['a', 0, 'b', 1], None)
s_com = (['a', 1, 'b', 2, 'c', 3], None)
s_new = (['b', 4], None)
e = self.assertRaises(BTreesConflictError,
bucket._p_resolveConflict, s_old, s_com, s_new)
self.assertEqual(e.reason, 2)
def test__p_resolveConflict_delete_first_committed(self):
from ..Interfaces import BTreesConflictError
bucket = self._makeOne()
s_old = (['a', 0, 'b', 1], None)
s_com = (['b', 4], None)
s_new = (['a', 1, 'b', 2, 'c', 3], None)
e = self.assertRaises(BTreesConflictError,
bucket._p_resolveConflict, s_old, s_com, s_new)
self.assertEqual(e.reason, 3)
class Test__SetBase(unittest.TestCase):
assertRaises = _assertRaises
def _getTargetClass(self):
from .._base import _SetBase
return _SetBase
def _makeOne(self):
class _TestSet(self._getTargetClass()):
def __setstate__(self, state):
self._keys, self._next = state
def clear(self):
self._keys, self._next = [], None
def __len__(self):
return len(self._keys)
def __iter__(self):
return iter(self._keys)
return _TestSet()
def test__p_resolveConflict_new_next(self): def test__p_resolveConflict_new_next(self):
from ..Interfaces import BTreesConflictError from ..Interfaces import BTreesConflictError
bucket = self._with_setstate_set() bucket = self._makeOne()
N_NEW = object() N_NEW = object()
s_old = ([], None) s_old = ([], None)
s_com = ([], N_NEW) s_com = ([], N_NEW)
...@@ -395,7 +441,7 @@ class Test_BucketBase(unittest.TestCase): ...@@ -395,7 +441,7 @@ class Test_BucketBase(unittest.TestCase):
def test__p_resolveConflict_committed_next(self): def test__p_resolveConflict_committed_next(self):
from ..Interfaces import BTreesConflictError from ..Interfaces import BTreesConflictError
bucket = self._with_setstate_set() bucket = self._makeOne()
N_NEW = object() N_NEW = object()
s_old = ([], None) s_old = ([], None)
s_com = ([], None) s_com = ([], None)
...@@ -406,7 +452,7 @@ class Test_BucketBase(unittest.TestCase): ...@@ -406,7 +452,7 @@ class Test_BucketBase(unittest.TestCase):
def test__p_resolveConflict_empty_committed(self): def test__p_resolveConflict_empty_committed(self):
from ..Interfaces import BTreesConflictError from ..Interfaces import BTreesConflictError
bucket = self._with_setstate_set() bucket = self._makeOne()
s_old = ([], None) s_old = ([], None)
s_com = ([], None) s_com = ([], None)
s_new = (['a'], None) s_new = (['a'], None)
...@@ -416,7 +462,7 @@ class Test_BucketBase(unittest.TestCase): ...@@ -416,7 +462,7 @@ class Test_BucketBase(unittest.TestCase):
def test__p_resolveConflict_empty_new(self): def test__p_resolveConflict_empty_new(self):
from ..Interfaces import BTreesConflictError from ..Interfaces import BTreesConflictError
bucket = self._with_setstate_set() bucket = self._makeOne()
s_old = ([], None) s_old = ([], None)
s_com = (['a'], None) s_com = (['a'], None)
s_new = ([], None) s_new = ([], None)
...@@ -424,9 +470,9 @@ class Test_BucketBase(unittest.TestCase): ...@@ -424,9 +470,9 @@ class Test_BucketBase(unittest.TestCase):
bucket._p_resolveConflict, s_old, s_com, s_new) bucket._p_resolveConflict, s_old, s_com, s_new)
self.assertEqual(e.reason, 12) self.assertEqual(e.reason, 12)
def test__p_resolveConflict_delete_first_new_set(self): def test__p_resolveConflict_delete_first_new(self):
from ..Interfaces import BTreesConflictError from ..Interfaces import BTreesConflictError
bucket = self._with_setstate_set() bucket = self._makeOne()
s_old = (['a','b'], None) s_old = (['a','b'], None)
s_com = (['a','b','c'], None) s_com = (['a','b','c'], None)
s_new = (['b'], None) s_new = (['b'], None)
...@@ -434,19 +480,9 @@ class Test_BucketBase(unittest.TestCase): ...@@ -434,19 +480,9 @@ class Test_BucketBase(unittest.TestCase):
bucket._p_resolveConflict, s_old, s_com, s_new) bucket._p_resolveConflict, s_old, s_com, s_new)
self.assertEqual(e.reason, 13) self.assertEqual(e.reason, 13)
def test__p_resolveConflict_delete_first_new_bucket(self): def test__p_resolveConflict_delete_first_committed(self):
from ..Interfaces import BTreesConflictError
bucket = self._with_setstate_bucket()
s_old = (['a', 0, 'b', 1], None)
s_com = (['a', 1, 'b', 2, 'c', 3], None)
s_new = (['b', 4], None)
e = self.assertRaises(BTreesConflictError,
bucket._p_resolveConflict, s_old, s_com, s_new)
self.assertEqual(e.reason, 2)
def test__p_resolveConflict_delete_first_committed_set(self):
from ..Interfaces import BTreesConflictError from ..Interfaces import BTreesConflictError
bucket = self._with_setstate_set() bucket = self._makeOne()
s_old = (['a','b'], None) s_old = (['a','b'], None)
s_com = (['b'], None) s_com = (['b'], None)
s_new = (['a', 'b', 'c'], None) s_new = (['a', 'b', 'c'], None)
...@@ -454,16 +490,6 @@ class Test_BucketBase(unittest.TestCase): ...@@ -454,16 +490,6 @@ class Test_BucketBase(unittest.TestCase):
bucket._p_resolveConflict, s_old, s_com, s_new) bucket._p_resolveConflict, s_old, s_com, s_new)
self.assertEqual(e.reason, 13) self.assertEqual(e.reason, 13)
def test__p_resolveConflict_delete_first_committed_bucket(self):
from ..Interfaces import BTreesConflictError
bucket = self._with_setstate_bucket()
s_old = (['a', 0, 'b', 1], None)
s_com = (['b', 4], None)
s_new = (['a', 1, 'b', 2, 'c', 3], None)
e = self.assertRaises(BTreesConflictError,
bucket._p_resolveConflict, s_old, s_com, s_new)
self.assertEqual(e.reason, 3)
def test_suite(): def test_suite():
return unittest.TestSuite(( return unittest.TestSuite((
......
Markdown is supported
0%
or
You are about to add 0 people to the discussion. Proceed with caution.
Finish editing this message first!
Please register or to comment