Skip to content

Commit

Permalink
[pre-commit.ci] auto fixes from pre-commit.com hooks
Browse files Browse the repository at this point in the history
for more information, see https://pre-commit.ci
  • Loading branch information
pre-commit-ci[bot] authored and GeigerJ2 committed Nov 21, 2024
1 parent e568e2a commit e0be575
Show file tree
Hide file tree
Showing 2 changed files with 13 additions and 12 deletions.
14 changes: 6 additions & 8 deletions src/aiida/orm/nodes/data/remote/base.py
Original file line number Diff line number Diff line change
Expand Up @@ -10,8 +10,8 @@

from __future__ import annotations

import os
import logging
import os
from pathlib import Path

from aiida.orm import AuthInfo
Expand Down Expand Up @@ -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)

Expand All @@ -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
Expand Down
11 changes: 7 additions & 4 deletions tests/orm/nodes/data/test_remote.py
Original file line number Diff line number Diff line change
Expand Up @@ -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."""
Expand All @@ -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."""

Expand All @@ -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."""

Expand All @@ -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."""

Expand All @@ -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."""

Expand Down

0 comments on commit e0be575

Please sign in to comment.