Commit 861b1450 authored by Tres Seaver's avatar Tres Seaver

Coverage.

parent 9c2a03e7
......@@ -1363,7 +1363,8 @@ def to_float(self, v):
def to_long(self, v):
try:
if not unpack("q", pack("q", v))[0] == v:
# XXX Python 2.6 doesn't truncate, it spews a warning.
if not unpack("q", pack("q", v))[0] == v: #pragma NO COVER
if isinstance(v, int_types):
raise ValueError("Value out of range", v)
raise TypeError('64-bit integer expected')
......
......@@ -2798,7 +2798,7 @@ class Test_multiunion(unittest.TestCase, _SetObBase):
self.assertEqual(list(result), [1, 2])
class Test_converters(unittest.TestCase):
class Test_helpers(unittest.TestCase):
def test_to_ob(self):
from BTrees._base import to_ob
......@@ -2825,6 +2825,11 @@ class Test_converters(unittest.TestCase):
faux_self = object()
self.assertRaises(TypeError, to_int, faux_self, sys.maxint + 1)
def test_to_int_w_invalid(self):
from BTrees._base import to_int
faux_self = object()
self.assertRaises(TypeError, to_int, faux_self, ())
def test_to_float_w_float(self):
from BTrees._base import to_float
faux_self = object()
......@@ -2840,6 +2845,43 @@ class Test_converters(unittest.TestCase):
faux_self = object()
self.assertRaises(TypeError, to_float, faux_self, ())
def test_to_long_w_int(self):
from BTrees._base import to_long
faux_self = object()
self.assertEqual(to_long(faux_self, 3), 3)
def test_to_long_w_long_in_range(self):
from BTrees._base import to_long
faux_self = object()
try:
self.assertEqual(to_long(faux_self, long(3)), 3)
except NameError: #Python3
pass
def test_to_long_w_overflow(self):
import sys
from BTrees._base import to_long
faux_self = object()
self.assertRaises(ValueError, to_long, faux_self, sys.maxint + 1)
def test_to_long_w_invalid(self):
from BTrees._base import to_long
faux_self = object()
self.assertRaises(TypeError, to_long, faux_self, ())
def test_to_str_w_ok(self):
from BTrees._base import to_str
faux_self = object()
conv = to_str(3)
self.assertEqual(conv(faux_self, 'abc'), 'abc')
def test_to_str_w_invalid_length(self):
from BTrees._base import to_str
faux_self = object()
conv = to_str(3)
self.assertRaises(TypeError, conv, faux_self, 'ab')
self.assertRaises(TypeError, conv, faux_self, 'abcd')
class _Cache(object):
def __init__(self):
......
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