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.exceptions import InvalidDirectoryPath | |||||
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, False) | example_tree.addNode(path, pid, False) | ||||
for path, node in example_tree.children.items(): | for path, node in example_tree.children.items(): | ||||
▲ Show 20 Lines • Show All 57 Lines • ▼ Show 20 Lines | for path, pid in temp_folder["paths"].items(): | ||||
example_tree.addNode(path, pid, True) | example_tree.addNode(path, pid, True) | ||||
else: | else: | ||||
example_tree.addNode(path, pid, False) | example_tree.addNode(path, pid, False) | ||||
directories = example_tree.getDirectoriesInfo(example_tree.path) | directories = example_tree.getDirectoriesInfo(example_tree.path) | ||||
assert subsubdir_path not in directories | assert subsubdir_path not in directories | ||||
assert directories[subdir_path] == (2, 2) | assert directories[subdir_path] == (2, 2) | ||||
def test_get_files_from_dir(example_tree, temp_folder): | |||||
subdir_path = temp_folder["subdir"] | |||||
for path, pid in temp_folder["paths"].items(): | |||||
example_tree.addNode(path, pid, True) | |||||
files = example_tree.getFilesFromDir(subdir_path) | |||||
assert len(files) == 2 | |||||
def test_get_files_source_path(example_tree, temp_folder): | |||||
for path, pid in temp_folder["paths"].items(): | |||||
example_tree.addNode(path, pid, True) | |||||
files = example_tree.getFilesFromDir(example_tree.path) | |||||
assert len(files) == 1 | |||||
def test_get_files_from_dir_raise_exception(example_tree, temp_folder): | |||||
for path, pid in temp_folder["paths"].items(): | |||||
example_tree.addNode(path, pid, True) | |||||
with pytest.raises(InvalidDirectoryPath): | |||||
example_tree.getFilesFromDir("test/") |