diff --git a/src/dependencmake/dependency.py b/src/dependencmake/dependency.py index 7cdee20..f25018e 100644 --- a/src/dependencmake/dependency.py +++ b/src/dependencmake/dependency.py @@ -68,7 +68,7 @@ def get_hash_url(self) -> str: def get_extension(self) -> str: """Get extension in the URL.""" - return Path(self.url_parsed.path.segments[-1]).ext + return Path(self.url_parsed.path.segments[-1]).suffix def refresh(self): """Refresh state of dependency based on cache content.""" @@ -276,7 +276,7 @@ def move_decompress_path(self, decompress_path: Path, destination_path: Path): directory. If it contains multiple files, move the decompress directory instead. """ - decompress_files_paths = decompress_path.listdir() + decompress_files_paths = decompress_path.files() if len(decompress_files_paths) == 1: to_move_path = decompress_files_paths[0] diff --git a/tests/path.py b/tests/path.py new file mode 100644 index 0000000..132048b --- /dev/null +++ b/tests/path.py @@ -0,0 +1,10 @@ +import contextlib +from importlib.resources import files, as_file + +from path import Path + + +@contextlib.contextmanager +def path(module: str, name: str) -> Path: + with as_file(files(module) / name) as file: + yield Path(file) diff --git a/tests/test_dependency.py b/tests/test_dependency.py index 203471c..61ccc99 100644 --- a/tests/test_dependency.py +++ b/tests/test_dependency.py @@ -380,21 +380,21 @@ def test_decompress_error(self, mocker, zip_dependency): def test_move_decompress_path_single(self, mocker, dependency): """Move a single directory.""" - mocked_listdir = mocker.patch.object(Path, "listdir", autospec=True) - mocked_listdir.return_value = [Path("temp") / "extract" / "my_dep"] + mocked_files = mocker.patch.object(Path, "files", autospec=True) + mocked_files.return_value = [Path("temp") / "extract" / "my_dep"] mocked_move = mocker.patch.object(Path, "move", autospec=True) dependency.move_decompress_path(Path("temp") / "extract", Path("destination")) - mocked_listdir.assert_called_with(Path("temp") / "extract") + mocked_files.assert_called_with(Path("temp") / "extract") mocked_move.assert_called_with( Path("temp") / "extract" / "my_dep", Path("destination") ) def test_move_decompress_path_single_error(self, mocker, dependency): """Error when moving a single directory.""" - mocked_listdir = mocker.patch.object(Path, "listdir", autospec=True) - mocked_listdir.return_value = [Path("temp") / "extract" / "my_dep"] + mocked_files = mocker.patch.object(Path, "files", autospec=True) + mocked_files.return_value = [Path("temp") / "extract" / "my_dep"] mocked_move = mocker.patch.object(Path, "move", autospec=True) mocked_move.side_effect = OSError("error") @@ -407,8 +407,8 @@ def test_move_decompress_path_single_error(self, mocker, dependency): def test_move_decompress_path_multiple(self, mocker, dependency): """Move several elements.""" - mocked_listdir = mocker.patch.object(Path, "listdir", autospec=True) - mocked_listdir.return_value = [ + mocked_files = mocker.patch.object(Path, "files", autospec=True) + mocked_files.return_value = [ Path("temp") / "extract" / "file1", Path("temp") / "extract" / "file2", ] @@ -416,7 +416,7 @@ def test_move_decompress_path_multiple(self, mocker, dependency): dependency.move_decompress_path(Path("temp") / "extract", Path("destination")) - mocked_listdir.assert_called_with(Path("temp") / "extract") + mocked_files.assert_called_with(Path("temp") / "extract") mocked_move.assert_called_with(Path("temp") / "extract", Path("destination")) def test_fetch_folder(self, folder_dependency, mocker): diff --git a/tests/test_dependency_list_integration.py b/tests/test_dependency_list_integration.py index 34fc351..72c2e41 100644 --- a/tests/test_dependency_list_integration.py +++ b/tests/test_dependency_list_integration.py @@ -1,13 +1,8 @@ -try: - from importlib.resources import path - -except ImportError: - from importlib_resources import path # type: ignore - import pytest from path import Path from dependencmake.dependency_list import DependencyList +from tests.path import path @pytest.fixture @@ -18,7 +13,7 @@ def temp_directory(tmp_path): @pytest.fixture def subdependencies_temp_directory(temp_directory): with path("tests.resources.subdependencies", "dependencmake.yaml") as config: - Path(config).copy(temp_directory) + config.copy(temp_directory) fetch_directory = (temp_directory / "dependencmake" / "fetch").makedirs_p() (fetch_directory / "dep11_1d264692d45516dcae4a8f07a847d742").mkdir_p() @@ -33,13 +28,13 @@ def subdependencies_temp_directory(temp_directory): f"{resource}.dep1_36e47005e2edb6e84fdb0e2e411bff5a", "dependencmake.yaml", ) as config: - Path(config).copy(dep1) + config.copy(dep1) with path( f"{resource}.dep2_4b35bd592421ea9170dfb690d7550744", "dependencmake.yaml", ) as config: - Path(config).copy(dep2) + config.copy(dep2) return temp_directory diff --git a/tests/test_main_integration.py b/tests/test_main_integration.py index a04e3bc..e7f483b 100644 --- a/tests/test_main_integration.py +++ b/tests/test_main_integration.py @@ -1,17 +1,12 @@ from argparse import Namespace from io import StringIO -try: - from importlib.resources import path - -except ImportError: - from importlib_resources import path # type: ignore - import pytest from path import Path from dependencmake.__main__ import run_build, run_fetch, run_install, run_list from dependencmake.filesystem import CACHE_INSTALL +from tests.path import path @pytest.fixture @@ -24,7 +19,7 @@ def test_run(self, temp_directory): """List dependencies.""" # copy test files with path("tests.resources", "dependencmake.yaml") as config: - Path(config).copy(temp_directory) + config.copy(temp_directory) # run test with temp_directory: @@ -49,7 +44,7 @@ def test_run(self, mocker, temp_directory): # copy test files with path("tests.resources", "dependencmake.yaml") as config: - Path(config).copy(temp_directory) + config.copy(temp_directory) # run test with temp_directory: @@ -78,7 +73,7 @@ def test_run(self, mocker, temp_directory): # copy test files with path("tests.resources", "dependencmake.yaml") as config: - Path(config).copy(temp_directory) + config.copy(temp_directory) # run test with temp_directory: @@ -107,7 +102,7 @@ def test_run_install_path(self, mocker, temp_directory): # copy test files with path("tests.resources", "dependencmake.yaml") as config: - Path(config).copy(temp_directory) + config.copy(temp_directory) # run test with temp_directory: @@ -138,7 +133,7 @@ def test_run(self, mocker, temp_directory): # copy test files with path("tests.resources", "dependencmake.yaml") as config: - Path(config).copy(temp_directory) + config.copy(temp_directory) # run test with temp_directory: @@ -173,7 +168,7 @@ def test_run_install_path(self, mocker, temp_directory): # copy test files with path("tests.resources", "dependencmake.yaml") as config: - Path(config).copy(temp_directory) + config.copy(temp_directory) # run test with temp_directory: