Skip to content

Commit

Permalink
Linter fixes
Browse files Browse the repository at this point in the history
  • Loading branch information
kmontag committed Jul 1, 2024
1 parent bc7d608 commit 258e7f0
Show file tree
Hide file tree
Showing 2 changed files with 17 additions and 37 deletions.
20 changes: 5 additions & 15 deletions src/alpacks/__init__.py
Original file line number Diff line number Diff line change
Expand Up @@ -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)

Expand Down Expand Up @@ -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:
Expand All @@ -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(
Expand All @@ -296,9 +290,7 @@ async def _write_xmp_file(self) -> None:
<rdf:Bag>
"""
).lstrip("\n")
+ "\n".join(
[f" <rdf:li>{rdf_item}</rdf:li>" for rdf_item in rdf_items]
)
+ "\n".join([f" <rdf:li>{rdf_item}</rdf:li>" for rdf_item in rdf_items])
+ textwrap.dedent(
"""
</rdf:Bag>
Expand Down Expand Up @@ -335,9 +327,7 @@ async def _write_xmp_file(self) -> None:
</x:xmpmeta>
"""
).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")
Expand Down
34 changes: 12 additions & 22 deletions tests/test_alpacks.py
Original file line number Diff line number Diff line change
@@ -1,5 +1,5 @@
import os
import asyncio
import os
import tempfile

import alpacks
Expand All @@ -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
Expand All @@ -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"<ablFR:packUniqueId>{unique_id}</ablFR:packUniqueId>" in xmp_content
)
assert f"<ablFR:packUniqueId>{unique_id}</ablFR:packUniqueId>" in xmp_content
assert "<ablFR:packVersion>2.3.4</ablFR:packVersion>" in xmp_content
assert "<rdf:li>Tag Name|Tag Value|Subtag Value</rdf:li>" 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"

0 comments on commit 258e7f0

Please sign in to comment.