def test_compare(self):
        # Same nodes, same list
        children1 = tree.ChildrenList()
        children1.add(tree.StructuredTreeNode(('keyA', 'keyB')))
        children1.add(tree.StructuredTreeNode(('keyA', 'keyC')))

        children2 = tree.ChildrenList()
        children2.add(tree.StructuredTreeNode(('keyA', 'keyC')))
        children2.add(tree.StructuredTreeNode(('keyA', 'keyB')))

        self.assertEqual(children1, children2)
        self.assertEqual(str(children1), str(children2))

        children2.add(tree.StructuredTreeNode(('keyA', 'keyD')))
        self.assertNotEqual(children1, children2)
 def test_getitem(self):
     children = tree.ChildrenList()
     children.add(tree.StructuredTreeNode(('keyA', 'keyB')))
     children.add(tree.StructuredTreeNode(('keyA', 'keyC')))
     # Not found
     raised = False
     try:
         children[('keyA', 'keyD')]
     except KeyError:
         raised = True
     self.assertTrue(raised)
     self.assertEqual(children[('keyA', 'keyB')],
                      tree.StructuredTreeNode(('keyA', 'keyB')))
 def test_sorted_add(self):
     children = tree.ChildrenList()
     # Append some
     children.add(tree.StructuredTreeNode(('keyA', 'keyB')))
     self.assertEqual(0, children.index(('keyA', 'keyB')))
     children.add(tree.StructuredTreeNode(('keyA', 'keyC')))
     self.assertEqual(1, children.index(('keyA', 'keyC')))
     children.add(tree.StructuredTreeNode(('keyA', 'keyZ')))
     self.assertEqual(2, children.index(('keyA', 'keyZ')))
     # Insert in the middle
     children.add(tree.StructuredTreeNode(('keyA', 'keyD')))
     self.assertEqual(2, children.index(('keyA', 'keyD')))
     self.assertEqual(3, children.index(('keyA', 'keyZ')))
     # Insert in front
     children.add(tree.StructuredTreeNode(('keyA', 'key')))
     self.assertEqual(0, children.index(('keyA', 'key')))
     # Verify whole list
     self.assertEqual([
         tree.StructuredTreeNode(('keyA', 'key')),
         tree.StructuredTreeNode(('keyA', 'keyB')),
         tree.StructuredTreeNode(('keyA', 'keyC')),
         tree.StructuredTreeNode(('keyA', 'keyD')),
         tree.StructuredTreeNode(('keyA', 'keyZ'))
     ], children._stash)
 def test_index_not_found(self):
     children = tree.ChildrenList()
     # non existing elem
     self.assertIsNone(children.index('test'))