[ZPT] CVS: Zope/lib/python/ZTUtils/tests - testTree.py:1.2.2.3

Martijn Pieters mj@zope.com
Mon, 7 Oct 2002 16:03:31 -0400


Update of /cvs-repository/Zope/lib/python/ZTUtils/tests
In directory cvs.zope.org:/tmp/cvs-serv4425/lib/python/ZTUtils/tests

Modified Files:
      Tag: Zope-2_6-branch
	testTree.py 
Log Message:
Merge additional TreeMaker accessor methods and stateFunction functionality
from the trunk.


=== Zope/lib/python/ZTUtils/tests/testTree.py 1.2.2.2 => 1.2.2.3 ===
--- Zope/lib/python/ZTUtils/tests/testTree.py:1.2.2.2	Sat Oct  5 16:26:47 2002
+++ Zope/lib/python/ZTUtils/tests/testTree.py	Mon Oct  7 16:03:30 2002
@@ -115,12 +115,12 @@
         self.assertEqual(treeroot[1][1].state, 0)
 
     def testAssumeChildren(self):
-        self.tm._assume_children = 1
+        self.tm.setAssumeChildren(1)
         treeroot = self.tm.tree(self.root, self.expansionmap)
         self.assertEqual(treeroot[1][1].state, -1)
 
     def testNoExpandRoot(self):
-        self.tm._expand_root = 0
+        self.tm.setExpandRoot(0)
         treeroot = self.tm.tree(self.root)
 
         self.assertEqual(treeroot.state, -1)
@@ -128,7 +128,7 @@
 
     def testIdAttribute(self):
         treeroot = self.tm.tree(self.root)
-        self.tm._id = 'id'
+        self.tm.setIdAttr('id')
         treeroot2 = self.tm.tree(self.root)
 
         self.assertEqual(treeroot.id, treeroot2.id)
@@ -164,6 +164,24 @@
         treeroot = self.tm.tree(self.root)
 
         self.assertEqual(len(treeroot), 2)
+
+    def testStateFunction(self):
+        def stateFunction(object, state):
+            if object.id == 'b':
+                return 1
+            if object.id == 'd':
+                return -1
+            return state
+        
+        self.tm.setStateFunction(stateFunction)
+        treeroot = self.tm.tree(self.root)
+
+        self.assertEqual(treeroot.size, 5)
+        self.assertEqual(treeroot.state, 1)
+        self.assertEqual(treeroot[0].state, 1)
+        self.assertEqual(treeroot[0][0].state, -1)
+        self.assertEqual(treeroot[0][1].state, 0)
+        self.assertEqual(treeroot[1].state, -1)
 
     def testEncodeDecode(self):
         treeroot1 = self.tm.tree(self.root, self.expansionmap)