本文整理汇总了Python中tree.Node.get_id方法的典型用法代码示例。如果您正苦于以下问题:Python Node.get_id方法的具体用法?Python Node.get_id怎么用?Python Node.get_id使用的例子?那么恭喜您, 这里精选的方法代码示例或许可以为您提供帮助。您也可以进一步了解该方法所在类tree.Node
的用法示例。
在下文中一共展示了Node.get_id方法的2个代码示例,这些例子默认根据受欢迎程度排序。您可以为喜欢或者感觉有用的代码点赞,您的评价将有助于系统推荐出更棒的Python代码示例。
示例1: TestNodeMethods
# 需要导入模块: from tree import Node [as 别名]
# 或者: from tree.Node import get_id [as 别名]
class TestNodeMethods(unittest.TestCase):
def setUp(self):
# create test objects
self.n = Node('node1')
self.n2 = Node('node2', '2')
self.n3 = Node('node3', '3')
self.n4 = Node('node4', '4')
self.n5 = Node('node5', '5')
self.n6 = Node('node6', '6')
self.n7 = Node('node7', '7')
def tearDown(self):
# set objects to none or delete stuff
self.n = None
self.n2 = None
def test_get_id_where_no_id(self):
self.assertEqual(self.n.get_id(), None)
def test_get_id_and_title_n_n2(self):
self.assertEqual(self.n.get_title(), 'node1')
self.assertEqual(self.n2.get_title(), 'node2')
self.assertEqual(self.n2.get_id(), '2')
def test_string_repr(self):
self.assertEqual(self.n.__str__(), 'node1')
self.assertEqual(self.n2.__str__(), 'node2')
def test_adding_2_children(self):
self.n.add_child(self.n2)
self.n.add_child(self.n3)
children = Set()
children.add(self.n2)
children.add(self.n3)
self.assertEqual(self.n.get_children(), children)
def test_parent_id(self):
n = Node(id='6', parent_id='1')
self.assertEqual(n.get_parent_id(), '1')
def test_set_and_get_parent_id(self):
n = Node(id='1')
n.set_parent_id(0)
id = n.get_parent_id()
self.assertEqual(0, id)
示例2: TestTreeMethods
# 需要导入模块: from tree import Node [as 别名]
# 或者: from tree.Node import get_id [as 别名]
class TestTreeMethods(unittest.TestCase):
def setUp(self):
self.n1 = Node(title='node1', id='1', parent_id='root')
self.n2 = Node(title='node2', id='2', parent_id='1')
self.n3 = Node(title='node3', id='3', parent_id='1')
self.n4 = Node(title='node4', id='4', parent_id='2')
self.n5 = Node(title='node5', id='5', parent_id='4')
# set up tree with multiple nodes
self.t1 = Tree()
self.t1.add(self.n1) # node1 has many children
self.t1.add(self.n2)
self.t1.add(self.n3)
self.t1.add(self.n4)
self.t1.add(self.n5)
#print("Tree before the test:")
#print(self.t1)
# set up tree with only one node besides root
self.n6 = Node('node6', '6', parent_id='root')
self.one_node_tree = Tree()
self.one_node_tree.add(self.n6)
def tearDown(self):
self.n1 = None
self.n2 = None
self.n3 = None
self.n4 = None
self.n5 = None
self.n6 = None
self.t1 = None
self.t2 = None
def test_get_root(self):
self.assertEqual(self.t1.get_root().get_id(), 'root')
def test_init_node_not_have_id_root(self):
""" test init using a node who's id is not 'root'"""
n = Node(title='foo', id=0)
t = Tree(n)
self.assertEqual(t.get_root().get_id(), 'root')
def test_init_node_has_id_of_root(self):
n = Node(title='foo', id='root')
t = Tree(n)
self.assertEqual(t.get_root().get_id(), 'root')
def test_string_empty_tree(self):
t2 = Tree(None)
self.assertEqual(t2.__str__(), '|---Google_Drive\n')
def test_string_non_empty_tree(self):
print("You can't really test this...automatically")
print(self.t1)
def test_search_for_root(self):
result = self.t1.search('root')
self.assertTrue(result.get_id() == 'root')
def test_search_for_first_node_added(self):
result = self.t1.search('1')
self.assertTrue(result.get_id() == '1')
def test_search_for_nonexisting_node_in_one_node_tree(self):
result = self.one_node_tree.search(self.n2.get_id())
self.assertTrue(result == None)
def test_new_tree_add_2_nodes_and_print_it(self):
t = Tree()
n = Node(title='test', id='1', parent_id='root')
t.add(n)
n = Node(title='test2', id='2', parent_id='1')
t.add(n)
print(t)
def test_new_tree_add_2_nodes_and_search_it(self):
t = Tree()
n = Node(title='test', id='1', parent_id='root')
t.add(n)
n = Node(title='test2', id='2', parent_id='1')
t.add(n)
#print(t)
result = t.search('2')
self.assertEqual(result.get_id(), '2')
# From here down, tests are failing
def test_search_for_nested_leaf_node(self):
result = self.t1.search(self.n5.get_id())
self.assertTrue('5' == result.get_id())
def test_search_for_node1(self):
result = self.t1.search(self.n1.get_id())
self.assertTrue(result.get_id(), '1')
def test_search_for_node2(self):
result = self.t1.search(self.n2.get_id())
self.assertTrue(result.get_id(), '2')
def test_search_for_node3(self):
#.........这里部分代码省略.........