Changeset View
Changeset View
Standalone View
Standalone View
swh/scanner/tests/conftest.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 asyncio | import asyncio | ||||
import os | import os | ||||
from pathlib import Path | from pathlib import Path | ||||
import shutil | import shutil | ||||
import sys | |||||
import aiohttp | import aiohttp | ||||
from aioresponses import aioresponses # type: ignore | from aioresponses import aioresponses # type: ignore | ||||
import pytest | import pytest | ||||
from swh.model.cli import model_of_dir | from swh.model.cli import model_of_dir | ||||
from swh.scanner.data import MerkleNodeInfo | from swh.scanner.data import MerkleNodeInfo | ||||
from swh.scanner.policy import QUERY_LIMIT | from swh.scanner.policy import QUERY_LIMIT | ||||
▲ Show 20 Lines • Show All 54 Lines • ▼ Show 20 Lines | def source_tree(test_sample_folder): | ||||
""" | """ | ||||
return model_of_dir(str(test_sample_folder).encode()) | return model_of_dir(str(test_sample_folder).encode()) | ||||
@pytest.fixture(scope="function") | @pytest.fixture(scope="function") | ||||
def big_source_tree(tmp_path): | def big_source_tree(tmp_path): | ||||
"""Generate a model.from_disk.Directory from a "big" temporary directory | """Generate a model.from_disk.Directory from a "big" temporary directory | ||||
(more than 1000 nodes) | (more than 1000 nodes) | ||||
""" | """ | ||||
vlorentz: why? | |||||
Not Done Inline ActionsThis is used to avoid a possible RecursionError that could be generated by .mkdir. DanSeraf: This is used to avoid a possible RecursionError that could be generated by `.mkdir`. | |||||
Not Done Inline Actionsplease add a comment in the source code here, explaining why the recursion limit is needed (you explained it to @vlorentz in the diff, but the diff will not remain in the code :-)) zack: please add a comment in the source code here, explaining why the recursion limit is needed (you… | |||||
# workaround to avoid a RecursionError that could be generated while creating | |||||
# a large number of directories | |||||
sys.setrecursionlimit(1100) | |||||
dir_ = tmp_path / "big-directory" | dir_ = tmp_path / "big-directory" | ||||
dir_.mkdir() | sub_dirs = dir_ | ||||
for i in range(0, QUERY_LIMIT + 1): | for i in range(0, QUERY_LIMIT + 1): | ||||
file_ = dir_ / f"file_{i}.org" | sub_dirs = sub_dirs / "dir" | ||||
sub_dirs.mkdir(parents=True, exist_ok=True) | |||||
file_ = sub_dirs / "file.org" | |||||
file_.touch() | file_.touch() | ||||
dir_obj = model_of_dir(str(dir_).encode()) | dir_obj = model_of_dir(str(dir_).encode()) | ||||
assert len(dir_obj) > QUERY_LIMIT | |||||
return dir_obj | return dir_obj | ||||
@pytest.fixture(scope="function") | @pytest.fixture(scope="function") | ||||
def source_tree_policy(test_sample_folder_policy): | def source_tree_policy(test_sample_folder_policy): | ||||
"""Generate a model.from_disk.Directory object from the test sample | """Generate a model.from_disk.Directory object from the test sample | ||||
folder | folder | ||||
""" | """ | ||||
▲ Show 20 Lines • Show All 55 Lines • Show Last 20 Lines |
why?