From 258e7f0bc70c8a10e363189ca50806a534d60e42 Mon Sep 17 00:00:00 2001 From: Kevin Montag Date: Mon, 1 Jul 2024 18:45:33 +0200 Subject: [PATCH] Linter fixes --- src/alpacks/__init__.py | 20 +++++--------------- tests/test_alpacks.py | 34 ++++++++++++---------------------- 2 files changed, 17 insertions(+), 37 deletions(-) diff --git a/src/alpacks/__init__.py b/src/alpacks/__init__.py index 8f2b66f..a23b9ea 100644 --- a/src/alpacks/__init__.py +++ b/src/alpacks/__init__.py @@ -206,9 +206,7 @@ def __init__(self, output_dir: str, **k: Unpack[PackProperties]): # If the output dir exists and is non-empty (or is not a # directory), raise an error. - if os.path.exists(output_dir) and ( - not os.path.isdir(output_dir) or os.listdir(output_dir) - ): + if os.path.exists(output_dir) and (not os.path.isdir(output_dir) or os.listdir(output_dir)): msg = f"Output directory '{output_dir}' exists and is not empty." raise ValueError(msg) @@ -269,9 +267,7 @@ async def _write_properties_file(self) -> None: """ ).lstrip() - await self._write_to_path( - os.path.join(FOLDER_INFO_DIR, PROPERTIES_FILE), text.encode("utf-8") - ) + await self._write_to_path(os.path.join(FOLDER_INFO_DIR, PROPERTIES_FILE), text.encode("utf-8")) # Write pack metadata, e.g. tags. async def _write_xmp_file(self) -> None: @@ -282,9 +278,7 @@ async def _write_xmp_file(self) -> None: if len(tag_values) == 0: msg = f"Tag `{tag_name}` is empty for path `{path}`" raise ValueError(msg) - rdf_items.append( - "|".join(escape(val) for val in [tag_name, *tag_values]) - ) + rdf_items.append("|".join(escape(val) for val in [tag_name, *tag_values])) rdf_indent = " " tags_text += textwrap.indent( @@ -296,9 +290,7 @@ async def _write_xmp_file(self) -> None: """ ).lstrip("\n") - + "\n".join( - [f" {rdf_item}" for rdf_item in rdf_items] - ) + + "\n".join([f" {rdf_item}" for rdf_item in rdf_items]) + textwrap.dedent( """ @@ -335,9 +327,7 @@ async def _write_xmp_file(self) -> None: """ ).lstrip() - await self._write_to_path( - os.path.join(FOLDER_INFO_DIR, XMP_FILE), xmp_text.encode("utf-8") - ) + await self._write_to_path(os.path.join(FOLDER_INFO_DIR, XMP_FILE), xmp_text.encode("utf-8")) def _preview_path(self, path: str) -> str: return os.path.join(FOLDER_INFO_DIR, "Previews", f"{path}.ogg") diff --git a/tests/test_alpacks.py b/tests/test_alpacks.py index 6070582..a16c6a0 100644 --- a/tests/test_alpacks.py +++ b/tests/test_alpacks.py @@ -1,5 +1,5 @@ -import os import asyncio +import os import tempfile import alpacks @@ -25,14 +25,10 @@ def test_directory() -> None: with open(os.path.join(output_dir, path)) as f: assert f.read() == "test-content" - with open( - os.path.join(output_dir, "Ableton Folder Info", "Previews", f"{path}.ogg") - ) as f: + with open(os.path.join(output_dir, "Ableton Folder Info", "Previews", f"{path}.ogg")) as f: assert f.read() == "test-preview-content" - with open( - os.path.join(output_dir, "Ableton Folder Info", "Properties.cfg") - ) as f: + with open(os.path.join(output_dir, "Ableton Folder Info", "Properties.cfg")) as f: properties_text = f.read() assert f'String PackUniqueID = "{unique_id}";' in properties_text assert f'String PackDisplayName = "{name}";' in properties_text @@ -44,33 +40,27 @@ def test_directory() -> None: assert f"Int {field} = {value};" in properties_text xmp_files = [ - file - for file in os.listdir(os.path.join(output_dir, "Ableton Folder Info")) - if file.endswith(".xmp") + file for file in os.listdir(os.path.join(output_dir, "Ableton Folder Info")) if file.endswith(".xmp") ] assert len(xmp_files) == 1 xmp_file_path = os.path.join(output_dir, "Ableton Folder Info", xmp_files[0]) with open(xmp_file_path) as xmp_file: xmp_content = xmp_file.read() - assert ( - f"{unique_id}" in xmp_content - ) + assert f"{unique_id}" in xmp_content assert "2.3.4" in xmp_content assert "Tag Name|Tag Value|Subtag Value" in xmp_content def test_simple_directory_async() -> None: - async def run() -> None: - with tempfile.TemporaryDirectory() as output_dir: - async with alpacks.DirectoryPackWriterAsync( - output_dir, name="Test", unique_id="test.id" - ) as pack_writer: + with tempfile.TemporaryDirectory() as output_dir: + + async def run() -> None: + async with alpacks.DirectoryPackWriterAsync(output_dir, name="Test", unique_id="test.id") as pack_writer: # Simple test, just make sure the write can happen # without errors. await pack_writer.set_file_content("path.adg", b"content") - with open(os.path.join(output_dir, "path.adg")) as f: - assert f.read() == "content" - - asyncio.run(run()) + asyncio.run(run()) + with open(os.path.join(output_dir, "path.adg")) as f: + assert f.read() == "content"