Commit 2bdd3d57 authored by Tim Peters's avatar Tim Peters

Backporting this from the Zope3 branch. The version on the trunk was

way out of date (prints stuff and asserts instead of raising unittest
failures).
parent 405894e8
...@@ -12,66 +12,61 @@ ...@@ -12,66 +12,61 @@
# #
############################################################################## ##############################################################################
__version__ = '$Id: testBTreesUnicode.py,v 1.6 2002/02/11 23:40:40 gvanrossum Exp $' __version__ = '$Id: testBTreesUnicode.py,v 1.7 2002/06/08 19:40:13 tim_one Exp $'
import unittest,types import unittest,types
from BTrees.OOBTree import OOBTree from BTrees.OOBTree import OOBTree
# When an OOBtree contains unicode strings as keys,
# When a OOBtree contains unicode strings as keys,
# it is neccessary accessing non-unicode strings are # it is neccessary accessing non-unicode strings are
# either ascii strings or encoded as unicoded using the # either ascii strings or encoded as unicoded using the
# corresponding encoding # corresponding encoding
encoding = 'ISO-8859-1' encoding = 'ISO-8859-1'
class TestBTreesUnicode(unittest.TestCase): class TestBTreesUnicode(unittest.TestCase):
""" test unicode""" """ test unicode"""
def setUp(self): 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), self.data = [('alien', 1),
('k\xf6nnten', 284708389), ('k\xf6nnten', 2),
('fox', 284708387), ('fox', 3),
('future', 284708388), ('future', 4),
('quick', 284708387), ('quick', 5),
('zerst\xf6rt', 284708389), ('zerst\xf6rt', 6),
(unicode('dreit\xe4gigen','latin1'), 284708391) (unicode('dreit\xe4gigen','latin1'), 7),
] ]
self.tree = OOBTree() 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
def test1(self):
""" check every item of the tree """
for k, v in self.data: for k, v in self.data:
if isinstance(k,types.StringType): if isinstance(k, types.StringType):
key = unicode(k,encoding) k = unicode(k, 'latin1')
else: self.tree[k] = v
key = k
if self.tree[key]!=v:
print "fehler"
def test2(self):
""" try to access unicode keys in tree"""
assert self.data[-1][0]== self.s
assert self.tree[self.data[-1][0]]== self.data[-1][1]
assert self.tree[self.s]== self.data[-1][1],''
def testAllKeys(self):
# check every item of the tree
for k, v in self.data:
if isinstance(k, types.StringType):
k = unicode(k, encoding)
self.assert_(self.tree.has_key(k))
self.assertEqual(self.tree[k], v)
def testUnicodeKeys(self):
# try to access unicode keys in tree
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(): def test_suite():
return unittest.makeSuite(TestBTreesUnicode) return unittest.makeSuite(TestBTreesUnicode)
...@@ -81,4 +76,3 @@ def main(): ...@@ -81,4 +76,3 @@ def main():
if __name__ == '__main__': if __name__ == '__main__':
main() main()
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