error in zope.app.tree test

Bug #264614 reported by Dragos Petre
6
This bug affects 1 person
Affects Status Importance Assigned to Milestone
zope.app.tree
Fix Committed
Medium
Christian Theune

Bug Description

One of the tests in test_node.py in the zope.app.tree.tests package is not functioning as intended (as far as I understand the test).

The test case reads:

1 def test_children(self):
2 # test hasChildren()
3 root_node = self.root_node
4 self.failUnless(root_node.hasChildren())
5
6 # test getChildNodes()
7 children = [node.context for node in root_node.getChildNodes()]
8 expected = [self.items['b'], self.items['c']]
9 self.assertEqual(children, expected)
10
11 # test with filter
12 expand_all = self.items.keys() # expand all nodes
13 # emulate node expansion with the FilterByObject filter
14 filter = FilterByObject([self.items[id] for id in self.expanded_nodes])
15 filtered_root = Node(self.root_obj, expand_all, filter)
16 children = [node.context for node in root_node.getChildNodes()]
17 expected = [self.items['b'], self.items['c']]
18 self.assertEqual(children, expected)

The problem is in the filter part. For one thing, the filtered_root object defined in line 15 is not used for the test in line 18, making the latter a simple duplication of the test in line 9.
Furthermore, since the filter is on the exanded_nodes list which is defined as [self.items['a'], self.items['c']] in the basetest module, the expected returned children would only be the self.items['c'] (see basetest.py in the same module).

Another problem is in the declaration of the Filter class - see below:

 1 class FilterByObject(object):
 2 """Simple filter that filters out any objects that wasn't passed
 3 in as a valid object before
 4 """
 5 implements(IObjectFindFilter)
 6
 7 def __init__(self, *objects):
 8 self.objects = objects
 9
10 def match(self, obj):
11 return obj in self.objects

For one thing, the interface from zope.app.container.interfaces import IObjectFindFilter defines a matches() method. Another thing is that, as used in the test, the Filter constructor will be passed a list of items. The current constructor will just put the list as an item in a tuple and the matches function will never get an item out of it. A suggestion is to go through the constructor arguments and if any happens to be a list, add the list's items to self.objects and not the list itself.

Attached is a suggested patch for the above issues. I realize it may be quite crude and I would be happy for feedback as I'm all the way at the bottom of the learning curve.

Best regards,
Dragos.

Revision history for this message
Dragos Petre (drpetrea) wrote :
affects: zope3 → zope.app.tree
Revision history for this message
Christian Theune (ctheune) wrote :

That's definitely phishy. Looking at this.

Changed in zope.app.tree:
assignee: nobody → Christian Theune (ct-gocept)
importance: Undecided → Medium
status: New → Confirmed
Revision history for this message
Christian Theune (ctheune) wrote :

Fixed in revision 111333 (Any numerologists around?)

Changed in zope.app.tree:
status: Confirmed → Fix Committed
To post a comment you must log in.
This report contains Public information  
Everyone can see this information.

Other bug subscribers

Remote bug watches

Bug watches keep track of this bug in other bug trackers.