Commit ccb453f0 authored by Tres Seaver's avatar Tres Seaver

100% coverage for Length.

#Rename test module to match 'test_<MUT>' pattern.
parent 28977e54
......@@ -28,8 +28,9 @@ class Length(persistent.Persistent):
longer works as expected, because new-style classes cache
class-defined slot methods (like __len__) in C type slots. Thus,
instance-defined slot fillers are ignored.
"""
# class-level default required to keep copy.deepcopy happy -- see
# https://bugs.launchpad.net/zodb/+bug/516653
value = 0
def __init__(self, v=0):
......
......@@ -11,40 +11,71 @@
# FOR A PARTICULAR PURPOSE
#
##############################################################################
"""\
Test for BTrees.Length module.
"""
__docformat__ = "reStructuredText"
import BTrees.Length
import copy
import sys
import unittest
_marker = object()
class LengthTestCase(unittest.TestCase):
def test_length_overflows_to_long(self):
length = BTrees.Length.Length(sys.maxint)
def _getTargetClass(self):
from BTrees.Length import Length
return Length
def _makeOne(self, value=_marker):
if value is _marker:
return self._getTargetClass()()
return self._getTargetClass()(value)
def test_ctor_default(self):
length = self._makeOne()
self.assertEqual(length.value, 0)
def test_ctor_explict(self):
length = self._makeOne(42)
self.assertEqual(length.value, 42)
def test___getstate___(self):
length = self._makeOne(42)
self.assertEqual(length.__getstate__(), 42)
def test___setstate__(self):
length = self._makeOne()
length.__setstate__(42)
self.assertEqual(length.value, 42)
def test_set(self):
length = self._makeOne()
length.set(42)
self.assertEqual(length.value, 42)
def test__p_resolveConflict(self):
length = self._makeOne()
self.assertEqual(length._p_resolveConflict(5, 7, 9), 11)
def test_change_overflows_to_long(self):
import sys
length = self._makeOne(sys.maxint)
self.assertEqual(length(), sys.maxint)
self.assert_(type(length()) is int)
length.change(+1)
self.assertEqual(length(), sys.maxint + 1)
self.assert_(type(length()) is long)
def test_length_underflows_to_long(self):
def test_change_underflows_to_long(self):
import sys
minint = (-sys.maxint) - 1
length = BTrees.Length.Length(minint)
length = self._makeOne(minint)
self.assertEqual(length(), minint)
self.assert_(type(length()) is int)
length.change(-1)
self.assertEqual(length(), minint - 1)
self.assert_(type(length()) is long)
def test_copy(self):
def test_lp_516653(self):
# Test for https://bugs.launchpad.net/zodb/+bug/516653
length = BTrees.Length.Length()
import copy
length = self._makeOne()
other = copy.copy(length)
self.assertEqual(other(), 0)
......
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