当前位置: 首页>>代码示例>>Python>>正文


Python Tree.removeTree方法代码示例

本文整理汇总了Python中tree.Tree.removeTree方法的典型用法代码示例。如果您正苦于以下问题:Python Tree.removeTree方法的具体用法?Python Tree.removeTree怎么用?Python Tree.removeTree使用的例子?那么恭喜您, 这里精选的方法代码示例或许可以为您提供帮助。您也可以进一步了解该方法所在tree.Tree的用法示例。


在下文中一共展示了Tree.removeTree方法的1个代码示例,这些例子默认根据受欢迎程度排序。您可以为喜欢或者感觉有用的代码点赞,您的评价将有助于系统推荐出更棒的Python代码示例。

示例1: TestTree

# 需要导入模块: from tree import Tree [as 别名]
# 或者: from tree.Tree import removeTree [as 别名]
class TestTree(unittest.TestCase):

  
  def setUp(self):
    self.root = Tree(NAME)
    self.tree2 = None
    self.tree3 = None
    self.tree4 = None

  def _AddChild(self, name):
    new_tree = Tree(name)
    self.root.addChild(new_tree)
    return new_tree

  def _createComplexTree(self):
    """
    Creates the following tree
      NAME1->NAME2->NAME4
      NAME1->NAME3
    """
    self.tree2 = self._AddChild(NAME2)
    self.tree3 = self._AddChild(NAME3)
    self.tree4 = Tree(NAME4)
    self.tree2.addChild(self.tree4)

  def testConstructor(self):
    if IGNORE_TEST:
      return
    self.assertEqual(self.root._name, NAME)
    self.assertEqual(len(self.root._children), 0)

  def testAddChild(self):
    if IGNORE_TEST:
      return
    new_tree = self._AddChild(NAME2)
    self.assertEqual(len(self.root._children), 1)
    self.assertEqual(self.root._children[0], new_tree)
    newer_tree = self._AddChild(NAME3)
    self.assertEqual(len(self.root._children), 2)
    self.assertEqual(self.root._children[1], newer_tree)

  def testAddChildComplex(self):
    if IGNORE_TEST:
      return
    self._createComplexTree()
    self.assertTrue(self.tree4 in self.tree2.getChildren())

  def testRemoveChildSimple(self):
    if IGNORE_TEST:
      return
    new_tree = self._AddChild(NAME2)
    new_tree.removeTree()
    self.assertIsNone(new_tree._parent)
    self.assertEqual(len(self.root._children), 0)

  def testRemoveChildComplex(self):
    if IGNORE_TEST:
      return
    self._createComplexTree()
    self.tree4.removeTree()
    self.assertIsNone(self.tree4._parent)
    self.assertEqual(len(self.tree2._children), 0)
    self.assertEqual(len(self.root._children), 2)

  def testGetRoot(self):
    if IGNORE_TEST:
      return
    self._createComplexTree()
    self.assertEqual(self.tree2._children[0], self.tree4)
    root = self.tree4.getRoot()
    self.assertEqual(root, self.root)
    root = self.root.getRoot()
    self.assertEqual(root, self.root)
    root = self.tree3.getRoot()
    self.assertEqual(root, self.root)

  def testGetChildrenFromRoot(self):
    if IGNORE_TEST:
      return
    self._createComplexTree()
    children = self.tree2.getChildren(is_from_root=False)
    self.assertEqual(children, [self.tree4])
    children = self.tree4.getChildren(is_from_root=True, 
        is_recursive=True)
    self.assertEqual(len(children), 3)
    self.assertFalse(self.root in children)
    self.assertTrue(self.tree2 in children)
    self.assertTrue(self.tree4 in children)

  def testGetChildrenFromSelf(self):
    if IGNORE_TEST:
      return
    self._createComplexTree()
    children = self.tree2.getChildren(is_from_root=False)
    grandchildren = self.tree4.getChildren(is_from_root=False)
    self.assertEqual(len(children), 1)
    self.assertEqual(len(grandchildren), 0)
    self.assertTrue(self.tree4 in children)

  def testFindPathFromRoot(self):
#.........这里部分代码省略.........
开发者ID:ScienceStacks,项目名称:SciSheets,代码行数:103,代码来源:test_tree.py


注:本文中的tree.Tree.removeTree方法示例由纯净天空整理自Github/MSDocs等开源代码及文档管理平台,相关代码片段筛选自各路编程大神贡献的开源项目,源码版权归原作者所有,传播和使用请参考对应项目的License;未经允许,请勿转载。