From e0be575d03b48685dc49cb1a61363a6a3db3f747 Mon Sep 17 00:00:00 2001 From: "pre-commit-ci[bot]" <66853113+pre-commit-ci[bot]@users.noreply.github.com> Date: Thu, 21 Nov 2024 14:53:18 +0000 Subject: [PATCH] [pre-commit.ci] auto fixes from pre-commit.com hooks for more information, see https://pre-commit.ci --- src/aiida/orm/nodes/data/remote/base.py | 14 ++++++-------- tests/orm/nodes/data/test_remote.py | 11 +++++++---- 2 files changed, 13 insertions(+), 12 deletions(-) diff --git a/src/aiida/orm/nodes/data/remote/base.py b/src/aiida/orm/nodes/data/remote/base.py index d77f25000..99e25a5b8 100644 --- a/src/aiida/orm/nodes/data/remote/base.py +++ b/src/aiida/orm/nodes/data/remote/base.py @@ -10,8 +10,8 @@ from __future__ import annotations -import os import logging +import os from pathlib import Path from aiida.orm import AuthInfo @@ -220,18 +220,17 @@ def get_size_on_disk(self, relpath: Path | None = None) -> str: total_size: int = self._get_size_on_disk_du(full_path, transport) except RuntimeError: - lstat_warn = ( - "Problem executing `du` command. Will return total file size based on `lstat`. " - "Take the result with a grain of salt, as `lstat` does not consider the file system block size, " - "but instead returns the true size of the files in bytes, which differs from the actual space requirements on disk." + 'Problem executing `du` command. Will return total file size based on `lstat`. ' + 'Take the result with a grain of salt, as `lstat` does not consider the file system block size, ' + 'but instead returns the true size of the files in bytes, which differs from the actual space requirements on disk.' ) _logger.warning(lstat_warn) total_size: int = self._get_size_on_disk_lstat(full_path, transport) except OSError: - _logger.critical("Could not evaluate directory size using either `du` or `lstat`.") + _logger.critical('Could not evaluate directory size using either `du` or `lstat`.') return format_directory_size(size_in_bytes=total_size) @@ -254,10 +253,9 @@ def _get_size_on_disk_du(self, full_path: Path, transport: 'Transport') -> int: total_size: int = int(stdout.split('\t')[0]) return total_size else: - raise RuntimeError(f"Error executing `du` command: {stderr}") + raise RuntimeError(f'Error executing `du` command: {stderr}') def _get_size_on_disk_lstat(self, full_path, transport) -> int: - """Connects to the remote folder and returns the total size of all files in the directory recursively in bytes using ``lstat``. Note that even if a file is only 1 byte, on disk, it still occupies one full disk block size. As such, getting accurate measures of the total expected size on disk when retrieving a ``RemoteData`` is not diff --git a/tests/orm/nodes/data/test_remote.py b/tests/orm/nodes/data/test_remote.py index 50b0db05e..d60a409f3 100644 --- a/tests/orm/nodes/data/test_remote.py +++ b/tests/orm/nodes/data/test_remote.py @@ -23,6 +23,7 @@ def remote_data_local(tmp_path, aiida_localhost): (tmp_path / 'file.txt').write_bytes(b'some content') return node + @pytest.fixture def remote_data_ssh(tmp_path, aiida_computer_ssh): """Return a non-empty ``RemoteData`` instance.""" @@ -35,7 +36,8 @@ def remote_data_ssh(tmp_path, aiida_computer_ssh): (tmp_path / 'file.txt').write_bytes(b'some content') return node -@pytest.mark.parametrize('fixture', ["remote_data_local", "remote_data_ssh"]) + +@pytest.mark.parametrize('fixture', ['remote_data_local', 'remote_data_ssh']) def test_clean(request, fixture): """Test the :meth:`aiida.orm.nodes.data.remote.base.RemoteData.clean` method.""" @@ -47,7 +49,8 @@ def test_clean(request, fixture): assert remote_data.is_empty assert remote_data.is_cleaned -@pytest.mark.parametrize('fixture', ["remote_data_local", "remote_data_ssh"]) + +@pytest.mark.parametrize('fixture', ['remote_data_local', 'remote_data_ssh']) def test_get_size_on_disk_du(request, fixture, monkeypatch): """Test the :meth:`aiida.orm.nodes.data.remote.base.RemoteData.clean` method.""" @@ -70,7 +73,7 @@ def mock_exec_command_wait(command): remote_data._get_size_on_disk_du(full_path, transport) -@pytest.mark.parametrize('fixture', ["remote_data_local", "remote_data_ssh"]) +@pytest.mark.parametrize('fixture', ['remote_data_local', 'remote_data_ssh']) def test_get_size_on_disk_lstat(request, fixture): """Test the :meth:`aiida.orm.nodes.data.remote.base.RemoteData.clean` method.""" @@ -84,7 +87,7 @@ def test_get_size_on_disk_lstat(request, fixture): assert size_on_disk == 12 -@pytest.mark.parametrize('fixture', ["remote_data_local", "remote_data_ssh"]) +@pytest.mark.parametrize('fixture', ['remote_data_local', 'remote_data_ssh']) def test_get_size_on_disk(request, fixture): """Test the :meth:`aiida.orm.nodes.data.remote.base.RemoteData.clean` method."""