コード例 #1
0
 def test_find_node_with_relative_path_returns_None_if_node_does_not_exist(self):
     root = Tree('root')
     child = Tree('a')
     root.add_child(child)
     node = root.find_path('b')
     self.assertIsNone(node)
     node = root.find_path('/b')
     self.assertIsNone(node)
コード例 #2
0
 def test_find_with_absolute_path_with_root_node_is_defaulted_slash(self):
     root = Tree(root=True)
     a = Tree('a')
     root.add_child(a)
     b = Tree('b')
     a.add_child(b)
     node = b.find_path('/a/b')
     self.assertEqual(node, b)
コード例 #3
0
 def test_find_with_just_a_slash_returns_root_node_from_a_nested_path(self):
     root = Tree('root')
     a = Tree('a')
     root.add_child(a)
     b = Tree('b')
     a.add_child(b)
     node = b.find_path('/')
     self.assertEqual(node, root)
コード例 #4
0
 def test_find_nested_node_with_relative_path(self):
     root = Tree('root')
     a = Tree('a')
     root.add_child(a)
     b = Tree('b')
     a.add_child(b)
     node = root.find_path('a/b')
     self.assertEqual(node, b)
コード例 #5
0
def init_tree_from_file(input_file):
    with open(input_file, 'r') as f:
        tree = PathTree(root=True)
        for line in f:
            tree.insert_path(line.strip())
            node = tree.find_path(line.strip())
            node.meta = {
                'type': 'file',
                'id': '',
                'modified': '',
                'size': '',
                'details': 'added from file'
            }
    return tree
コード例 #6
0
 def get_tree(self):
     tree = PathTree(root=True)
     for response in self.contents:
         for entry in response.entries:
             tree.insert_path(entry.path_display)
             node = tree.find_path(entry.path_display)
             if isinstance(entry, dropbox.files.FileMetadata):
                 node.meta = {
                     'type': 'file',
                     'id': entry.id,
                     'modified': entry.server_modified,
                     'size': entry.size
                 }
             if isinstance(entry, dropbox.files.FolderMetadata):
                 node.meta = {
                     'type': 'folder',
                     'id': entry.id
                 }
     return tree
コード例 #7
0
 def test_find_with_just_a_slash_returns_root_node(self):
     root = Tree('root')
     node = root.find_path('/')
     self.assertEqual(node, root)
コード例 #8
0
 def test_find_node_with_missing_node_in_middle_of_path_returns_None(self):
     root = Tree('root')
     node = root.find_path('b/c')
     self.assertIsNone(node)
     node = root.find_path('/b/c')
     self.assertIsNone(node)
コード例 #9
0
 def test_find_node_with_relative_path(self):
     root = Tree('root')
     child = Tree('a')
     root.add_child(child)
     node = root.find_path('a')
     self.assertEqual(node, child)