Skip to content

Commit

Permalink
Fix warnings
Browse files Browse the repository at this point in the history
  • Loading branch information
pzehner committed Feb 23, 2024
1 parent 6c984b2 commit 436b59c
Show file tree
Hide file tree
Showing 5 changed files with 31 additions and 31 deletions.
4 changes: 2 additions & 2 deletions src/dependencmake/dependency.py
Original file line number Diff line number Diff line change
Expand Up @@ -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."""
Expand Down Expand Up @@ -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]

Expand Down
10 changes: 10 additions & 0 deletions tests/path.py
Original file line number Diff line number Diff line change
@@ -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)
16 changes: 8 additions & 8 deletions tests/test_dependency.py
Original file line number Diff line number Diff line change
Expand Up @@ -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")

Expand All @@ -407,16 +407,16 @@ 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",
]
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", Path("destination"))

def test_fetch_folder(self, folder_dependency, mocker):
Expand Down
13 changes: 4 additions & 9 deletions tests/test_dependency_list_integration.py
Original file line number Diff line number Diff line change
@@ -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
Expand All @@ -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()
Expand All @@ -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

Expand Down
19 changes: 7 additions & 12 deletions tests/test_main_integration.py
Original file line number Diff line number Diff line change
@@ -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
Expand All @@ -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:
Expand All @@ -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:
Expand Down Expand Up @@ -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:
Expand Down Expand Up @@ -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:
Expand Down Expand Up @@ -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:
Expand Down Expand Up @@ -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:
Expand Down

0 comments on commit 436b59c

Please sign in to comment.