[Zope-Checkins] CVS: Zope/lib/python/ZTUtils/tests - testTree.py:1.4

Martijn Pieters mj@zope.com
Sat, 5 Oct 2002 17:24:04 -0400


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

Modified Files:
	testTree.py 
Log Message:
New method setStateFunction for TreeMaker.

- Refactor tree method to allow callback function (set with
  setStateFunction) to influence node state.

- hasChildren now stores the result of getChildren in a local cache, which
  getChildren uses and clears on a subsequent call. This was needed to avoid
  generating the children list for open nodes twice.

- hasChildren now flattens its return value to a boolean; tree relies on
  this.


=== Zope/lib/python/ZTUtils/tests/testTree.py 1.3 => 1.4 ===
--- Zope/lib/python/ZTUtils/tests/testTree.py:1.3	Sat Oct  5 16:26:40 2002
+++ Zope/lib/python/ZTUtils/tests/testTree.py	Sat Oct  5 17:24:03 2002
@@ -165,6 +165,24 @@
 
         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)