Skip to content

Commit

Permalink
TST: fix PEP8 errors
Browse files Browse the repository at this point in the history
  • Loading branch information
frankenjoe committed Jan 19, 2024
1 parent 07b289c commit 585550b
Show file tree
Hide file tree
Showing 8 changed files with 94 additions and 34 deletions.
2 changes: 1 addition & 1 deletion audbackend/core/api.py
Original file line number Diff line number Diff line change
Expand Up @@ -2,9 +2,9 @@

from audbackend.core import utils
from audbackend.core.backend import Backend
from audbackend.core.filesystem import FileSystem
from audbackend.core.interface import Unversioned
from audbackend.core.interface import Versioned
from audbackend.core.filesystem import FileSystem


backends = {}
Expand Down
4 changes: 2 additions & 2 deletions audbackend/core/backend.py
Original file line number Diff line number Diff line change
Expand Up @@ -436,7 +436,8 @@ def ls(

if pattern:
paths = [
p for p in paths if fnmatch.fnmatch(os.path.basename(p), pattern)
p for p in paths
if fnmatch.fnmatch(os.path.basename(p), pattern)
]

return paths
Expand Down Expand Up @@ -556,7 +557,6 @@ def put_file(
):
r"""Put file on backend.
The operation is silently skipped,
if a file with the same checksum
already exists on the backend.
Expand Down
14 changes: 12 additions & 2 deletions audbackend/core/conftest.py
Original file line number Diff line number Diff line change
Expand Up @@ -50,15 +50,25 @@ def prepare_docstring_tests(doctest_namespace):

# unversioned interface

unversioned = audbackend.create('file-system', 'host', 'unversioned', versioned=False)
unversioned = audbackend.create(
'file-system',
'host',
'unversioned',
versioned=False,
)
unversioned.put_archive('.', '/a.zip', files=[file])
unversioned.put_file(file, '/a/b.ext')
unversioned.put_file(file, '/f.ext')
doctest_namespace['unversioned'] = unversioned

# versioned interface

versioned = audbackend.create('file-system', 'host', 'versioned', versioned=True)
versioned = audbackend.create(
'file-system',
'host',
'versioned',
versioned=True,
)
versioned.put_archive('.', '/a.zip', '1.0.0', files=[file])
versioned.put_file(file, '/a/b.ext', '1.0.0')
for version in ['1.0.0', '2.0.0']:
Expand Down
71 changes: 59 additions & 12 deletions audbackend/core/interface.py
Original file line number Diff line number Diff line change
@@ -1,6 +1,5 @@
import os
import re
import tempfile
import typing

import audeer
Expand Down Expand Up @@ -214,7 +213,10 @@ def exists(
True
"""
return self.backend.exists(path, suppress_backend_errors=suppress_backend_errors)
return self.backend.exists(
path,
suppress_backend_errors=suppress_backend_errors,
)

def get_archive(
self,
Expand Down Expand Up @@ -259,7 +261,12 @@ def get_archive(
['src.pth']
"""
return self.backend.get_archive(src_path, dst_root, tmp_root=tmp_root, verbose=verbose)
return self.backend.get_archive(
src_path,
dst_root,
tmp_root=tmp_root,
verbose=verbose,
)

def get_file(
self,
Expand Down Expand Up @@ -369,7 +376,11 @@ def ls(
['/a/b.ext']
""" # noqa: E501
return self.backend.ls(path, pattern=pattern, suppress_backend_errors=suppress_backend_errors)
return self.backend.ls(
path,
pattern=pattern,
suppress_backend_errors=suppress_backend_errors,
)

def owner(
self,
Expand Down Expand Up @@ -451,7 +462,13 @@ def put_archive(
True
"""
self.backend.put_archive(src_root, dst_path, files=files, tmp_root=tmp_root, verbose=verbose)
self.backend.put_archive(
src_root,
dst_path,
files=files,
tmp_root=tmp_root,
verbose=verbose,
)

def put_file(
self,
Expand Down Expand Up @@ -634,7 +651,10 @@ def exists(
"""
path_with_version = self._path_with_version(path, version)
return self.backend.exists(path_with_version, suppress_backend_errors=suppress_backend_errors)
return self.backend.exists(
path_with_version,
suppress_backend_errors=suppress_backend_errors,
)

def get_archive(
self,
Expand Down Expand Up @@ -684,7 +704,12 @@ def get_archive(
"""
src_path_with_version = self._path_with_version(src_path, version)
return self.backend.get_archive(src_path_with_version, dst_root, tmp_root=tmp_root, verbose=verbose)
return self.backend.get_archive(
src_path_with_version,
dst_root,
tmp_root=tmp_root,
verbose=verbose,
)

def get_file(
self,
Expand Down Expand Up @@ -739,7 +764,11 @@ def get_file(
"""
src_path_with_version = self._path_with_version(src_path, version)
return self.backend.get_file(src_path_with_version, dst_path, verbose=verbose)
return self.backend.get_file(
src_path_with_version,
dst_path,
verbose=verbose,
)

def latest_version(
self,
Expand Down Expand Up @@ -832,13 +861,21 @@ def ls(
""" # noqa: E501
if path.endswith('/'): # find files under sub-path

paths = self.backend.ls(path, pattern=pattern, suppress_backend_errors=suppress_backend_errors)
paths = self.backend.ls(
path,
pattern=pattern,
suppress_backend_errors=suppress_backend_errors,
)

else: # find versions of path

root, file = self.split(path)

paths = self.backend.ls(root, pattern=pattern, suppress_backend_errors=suppress_backend_errors)
paths = self.backend.ls(
root,
pattern=pattern,
suppress_backend_errors=suppress_backend_errors,
)

# filter for '/root/version/file'
if self._legacy_file_structure:
Expand Down Expand Up @@ -1005,7 +1042,13 @@ def put_archive(
"""
dst_path_with_version = self._path_with_version(dst_path, version)
self.backend.put_archive(src_root, dst_path_with_version, files=files, tmp_root=tmp_root, verbose=verbose)
self.backend.put_archive(
src_root,
dst_path_with_version,
files=files,
tmp_root=tmp_root,
verbose=verbose,
)

def put_file(
self,
Expand Down Expand Up @@ -1048,7 +1091,11 @@ def put_file(
"""
dst_path_with_version = self._path_with_version(dst_path, version)
return self.backend.put_file(src_path, dst_path_with_version, verbose=verbose)
return self.backend.put_file(
src_path,
dst_path_with_version,
verbose=verbose,
)

def remove_file(
self,
Expand Down
5 changes: 4 additions & 1 deletion tests/test_artifactory.py
Original file line number Diff line number Diff line change
Expand Up @@ -212,6 +212,9 @@ def test_legacy_file_structure(tmpdir, interface, file, version, extensions,
interface.put_file(src_path, file, version)

url = f'{str(interface.backend._repo.path)}{expected}'
assert interface.backend._expand(interface._path_with_version(file, version)) == url
url_expected = interface.backend._expand(
interface._path_with_version(file, version),
)
assert url_expected == url
assert interface.ls(file) == [(file, version)]
assert interface.ls() == [(file, version)]
5 changes: 4 additions & 1 deletion tests/test_filesystem.py
Original file line number Diff line number Diff line change
Expand Up @@ -138,6 +138,9 @@ def test_legacy_file_structure(tmpdir, interface, file, version, extensions,
interface.put_file(src_path, file, version)

path = os.path.join(interface.backend._root, expected)
assert interface.backend._expand(interface._path_with_version(file, version)) == path
path_expected = interface.backend._expand(
interface._path_with_version(file, version),
)
assert path_expected == path
assert interface.ls(file) == [(file, version)]
assert interface.ls() == [(file, version)]
13 changes: 0 additions & 13 deletions tests/test_unversioned.py
Original file line number Diff line number Diff line change
Expand Up @@ -463,31 +463,18 @@ def test_ls(tmpdir, interface):
'/file.bar',
'/file.foo',
]
root_latest = [
'/file.bar',
'/file.foo',
]
root_foo = [
'/file.foo',
]
root_bar = [
'/file.bar',
]
root_bar_latest = [
'/file.bar',
]
sub = [
'/sub/file.foo',
]
sub_latest = [
'/sub/file.foo',
]
hidden = [
'/.sub/.file.foo',
]
hidden_latest = [
'/.sub/.file.foo',
]

# create content

Expand Down
14 changes: 12 additions & 2 deletions tests/test_versioned.py
Original file line number Diff line number Diff line change
Expand Up @@ -260,7 +260,12 @@ def test_errors(tmpdir, interface):
else:
error_msg = "No such file or directory: 'non-existing/..."
with pytest.raises(FileNotFoundError, match=error_msg):
interface.get_archive(archive, tmpdir, version, tmp_root='non-existing')
interface.get_archive(
archive,
tmpdir,
version,
tmp_root='non-existing',
)
# extension of `src_path` is not supported
error_msg = 'You can only extract ZIP and TAR.GZ files, ...'
interface.put_file(
Expand Down Expand Up @@ -394,7 +399,12 @@ def test_errors(tmpdir, interface):
# extension of `dst_path` is not supported
error_msg = 'You can only create a ZIP or TAR.GZ archive, not ...'
with pytest.raises(RuntimeError, match=error_msg):
interface.put_archive(tmpdir, '/archive.bad', version, files=local_file)
interface.put_archive(
tmpdir,
'/archive.bad',
version,
files=local_file,
)

# --- put_file ---
# `src_path` does not exists
Expand Down

0 comments on commit 585550b

Please sign in to comment.