[Zodb-checkins] SVN: ZODB/branches/3.8/src/BTrees/tests/testLength.py there are no tests for BTrees.Length; add tests that show that the Length

Fred L. Drake, Jr. fdrake at gmail.com
Fri May 9 01:10:02 EDT 2008


Log message for revision 86558:
  there are no tests for BTrees.Length; add tests that show that the Length
  object will properly switch to longs when over/underflowing 32-bit values
  

Changed:
  A   ZODB/branches/3.8/src/BTrees/tests/testLength.py

-=-
Added: ZODB/branches/3.8/src/BTrees/tests/testLength.py
===================================================================
--- ZODB/branches/3.8/src/BTrees/tests/testLength.py	                        (rev 0)
+++ ZODB/branches/3.8/src/BTrees/tests/testLength.py	2008-05-09 05:10:01 UTC (rev 86558)
@@ -0,0 +1,46 @@
+##############################################################################
+#
+# Copyright (c) 2008 Zope Corporation and Contributors.
+# All Rights Reserved.
+#
+# This software is subject to the provisions of the Zope Public License,
+# Version 2.1 (ZPL).  A copy of the ZPL should accompany this distribution.
+# THIS SOFTWARE IS PROVIDED "AS IS" AND ANY AND ALL EXPRESS OR IMPLIED
+# WARRANTIES ARE DISCLAIMED, INCLUDING, BUT NOT LIMITED TO, THE IMPLIED
+# WARRANTIES OF TITLE, MERCHANTABILITY, AGAINST INFRINGEMENT, AND FITNESS
+# FOR A PARTICULAR PURPOSE
+#
+##############################################################################
+"""\
+Test for BTrees.Length module.
+
+"""
+__docformat__ = "reStructuredText"
+
+import BTrees.Length
+import sys
+import unittest
+
+
+class LengthTestCase(unittest.TestCase):
+
+    def test_length_overflows_to_long(self):
+        length = BTrees.Length.Length(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):
+        minint = (-sys.maxint) - 1
+        length = BTrees.Length.Length(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_suite():
+    return unittest.makeSuite(LengthTestCase)


Property changes on: ZODB/branches/3.8/src/BTrees/tests/testLength.py
___________________________________________________________________
Name: svn:mime-type
   + text/x-python
Name: svn:eol-style
   + native



More information about the Zodb-checkins mailing list