[Checkins] SVN: BTrees/branches/pure_python/ Coverage.

Tres Seaver cvs-admin at zope.org
Tue Dec 4 21:49:46 UTC 2012


Log message for revision 128523:
  Coverage.

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 21:49:45 UTC (rev 128522)
+++ BTrees/branches/pure_python/BTrees/_base.py	2012-12-04 21:49:46 UTC (rev 128523)
@@ -1363,7 +1363,8 @@
 
 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')

Modified: BTrees/branches/pure_python/BTrees/tests/test__base.py
===================================================================
--- BTrees/branches/pure_python/BTrees/tests/test__base.py	2012-12-04 21:49:45 UTC (rev 128522)
+++ BTrees/branches/pure_python/BTrees/tests/test__base.py	2012-12-04 21:49:46 UTC (rev 128523)
@@ -2798,7 +2798,7 @@
         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 @@
         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,7 +2845,44 @@
         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):
         self._mru = []



More information about the checkins mailing list