Changeset View
Changeset View
Standalone View
Standalone View
swh/scanner/tests/test_model.py
# Copyright (C) 2020 The Software Heritage developers | # Copyright (C) 2020 The Software Heritage developers | ||||
# See the AUTHORS file at the top-level directory of this distribution | # See the AUTHORS file at the top-level directory of this distribution | ||||
# License: GNU General Public License version 3, or any later version | # License: GNU General Public License version 3, or any later version | ||||
# See top-level LICENSE file for more information | # See top-level LICENSE file for more information | ||||
import pytest | |||||
from swh.scanner.model import Tree | |||||
@pytest.fixture(scope='function') | |||||
def example_tree(temp_folder): | |||||
"""Fixture that generate a Tree with the root present in the | |||||
session fixture "temp_folder". | |||||
""" | |||||
example_tree = Tree(temp_folder['root']) | |||||
assert example_tree.path == temp_folder['root'] | |||||
return example_tree | |||||
def test_tree_add_node(example_tree, temp_folder): | def test_tree_add_node(example_tree, temp_folder): | ||||
avail_paths = temp_folder['paths'].keys() | avail_paths = temp_folder['paths'].keys() | ||||
for path, pid in temp_folder['paths'].items(): | for path, pid in temp_folder['paths'].items(): | ||||
example_tree.addNode(path, pid) | example_tree.addNode(path, pid) | ||||
for path, node in example_tree.children.items(): | for path, node in example_tree.children.items(): | ||||
Show All 31 Lines | for path, pid in temp_folder['paths'].items(): | ||||
example_tree.addNode(path, pid) | example_tree.addNode(path, pid) | ||||
else: | else: | ||||
example_tree.addNode(path) | example_tree.addNode(path) | ||||
tree_dict = example_tree.getTree() | tree_dict = example_tree.getTree() | ||||
assert len(tree_dict) == 1 | assert len(tree_dict) == 1 | ||||
assert tree_dict['subdir0']['filesample.txt'] | assert tree_dict['subdir0']['filesample.txt'] | ||||
def test_get_directories_info(example_tree, temp_folder): | |||||
root_path = temp_folder['root'] | |||||
filesample_path = temp_folder['filesample'] | |||||
filesample2_path = temp_folder['filesample2'] | |||||
subdir_path = temp_folder['subdir'].relative_to(root_path) | |||||
subsubdir_path = temp_folder['subsubdir'].relative_to(root_path) | |||||
for path, pid in temp_folder['paths'].items(): | |||||
if path == filesample_path or path == filesample2_path: | |||||
vlorentz: forgot to remove this print | |||||
example_tree.addNode(path, pid) | |||||
else: | |||||
example_tree.addNode(path) | |||||
directories = example_tree.getDirectoriesInfo(example_tree.path) | |||||
assert subsubdir_path not in directories | |||||
assert directories[subdir_path] == (2, 2) |
forgot to remove this print