[Zodb-checkins] CVS: Zope3/lib/python/Persistence/BTrees/tests - testBTreesUnicode.py:1.1.2.5

Tim Peters tim.one@comcast.net
Sat, 8 Jun 2002 15:38:38 -0400


Update of /cvs-repository/Zope3/lib/python/Persistence/BTrees/tests
In directory cvs.zope.org:/tmp/cvs-serv5664/tests

Modified Files:
      Tag: Zope-3x-branch
	testBTreesUnicode.py 
Log Message:
Code cleanup (simplify, give tests meaningful names, add an ASCII-key
test).


=== Zope3/lib/python/Persistence/BTrees/tests/testBTreesUnicode.py 1.1.2.4 => 1.1.2.5 ===
 # Copyright (c) 2001, 2002 Zope Corporation and Contributors.
 # All Rights Reserved.
-# 
+#
 # This software is subject to the provisions of the Zope Public License,
 # Version 2.0 (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.
-# 
+#
 ##############################################################################
 __version__ = '$Id$'
 
@@ -17,7 +17,7 @@
 import unittest
 from Persistence.BTrees.OOBTree import OOBTree
 
-# When a OOBtree contains unicode strings as keys,
+# When an OOBtree contains unicode strings as keys,
 # it is neccessary accessing non-unicode strings are
 # either ascii strings or encoded as unicoded using the
 # corresponding encoding
@@ -28,44 +28,45 @@
     """ test unicode"""
 
     def setUp(self):
-        """ setup an OOBTree with some unicode strings """
+        """setup an OOBTree with some unicode strings"""
 
-        self.s = unicode('dreit\xe4gigen','latin1')
+        self.s = unicode('dreit\xe4gigen', 'latin1')
 
-        self.data = [('alien', 284708388), 
-                ('k\xf6nnten', 284708389),
-                ('fox', 284708387), 
-                ('future', 284708388), 
-                ('quick', 284708387), 
-                ('zerst\xf6rt', 284708389), 
-                (unicode('dreit\xe4gigen','latin1'), 284708391)
-                ]
+        self.data = [('alien', 1),
+                     ('k\xf6nnten', 2),
+                     ('fox', 3),
+                     ('future', 4),
+                     ('quick', 5),
+                     ('zerst\xf6rt', 6),
+                     (unicode('dreit\xe4gigen','latin1'), 7),
+                    ]
 
         self.tree = OOBTree()
         for k, v in self.data:
             if isinstance(k, types.StringType):
-                self.tree[unicode(k,'latin1')] = v
-            else:
-                self.tree[k] = v
+                k = unicode(k, 'latin1')
+            self.tree[k] = v
 
-    def test1(self):
+    def testAllKeys(self):
         # check every item of the tree
-
         for k, v in self.data:
             if isinstance(k, types.StringType):
-                key = unicode(k, encoding)
-            else:
-                key = k
-
-            self.assertEqual(self.tree[key], v)
+                k = unicode(k, encoding)
+            self.assert_(self.tree.has_key(k))
+            self.assertEqual(self.tree[k], v)
 
-    def test2(self):
+    def testUnicodeKeys(self):
         # try to access unicode keys in tree
-
-        self.assertEqual(self.data[-1][0], self.s)
-        self.assertEqual(self.tree[self.data[-1][0]], self.data[-1][1])
-        self.assertEqual(self.tree[self.s], self.data[-1][1])
-
+        k, v = self.data[-1]
+        self.assertEqual(k, self.s)
+        self.assertEqual(self.tree[k], v)
+        self.assertEqual(self.tree[self.s], v)
+
+    def testAsciiKeys(self):
+        # try to access some "plain ASCII" keys in the tree
+        for k, v in self.data[0], self.data[2]:
+            self.assert_(isinstance(k, types.StringType))
+            self.assertEqual(self.tree[k], v)
 
 def test_suite():
     return unittest.makeSuite(TestBTreesUnicode)
@@ -75,4 +76,3 @@
 
 if __name__ == '__main__':
     main()
-