From e979890dd8eb1928ea9d0dd46ebb041210cae48c Mon Sep 17 00:00:00 2001 From: Thomas Scholtes Date: Mon, 1 Apr 2024 15:23:13 +0200 Subject: [PATCH] wip --- test/cli_test.py | 22 ++++------------------ test/helper.py | 16 ++++++++++++++++ 2 files changed, 20 insertions(+), 18 deletions(-) diff --git a/test/cli_test.py b/test/cli_test.py index 0325adb..89494dc 100644 --- a/test/cli_test.py +++ b/test/cli_test.py @@ -8,7 +8,7 @@ from beets.ui import UserError from beets.util import bytestring_path, syspath from confuse import ConfigValueError -from helper import TestHelper, control_stdin +from helper import TestHelper, control_stdin, convert_command from mediafile import MediaFile from typeguard import check_type @@ -22,12 +22,7 @@ def test_external(self): external_dir = os.path.join(self.mkdtemp(), "myplayer") self.config["convert"]["formats"] = { "aac": { - "command": ( - 'powershell -Command "' - "Copy-Item -Path '$source' -Destination '$dest';" - "Add-Content -Path '$dest' -Value ISAAC" - '"' - ), + "command": convert_command("ISAAC"), "extension": "m4a", }, } @@ -470,14 +465,7 @@ class ExternalConvertTest(TestHelper): def setUp(self): super().setUp() external_dir = self.mkdtemp() - self.config["convert"]["formats"] = { - "ogg": ( - 'powershell -Command "' - "Copy-Item -Path '$source' -Destination '$dest';" - "Add-Content -Path '$dest' -Value ISOGG" - '"' - ) - } + self.config["convert"]["formats"] = {"ogg": convert_command("ISOGG")} self.config["alternatives"] = { "myexternal": { "directory": external_dir, @@ -542,9 +530,7 @@ def test_no_move_on_extension_change(self): item = self.add_track(myexternal="true", format="m4a") self.runcli("alt", "update", "myexternal") - self.config["convert"]["formats"] = { - "mp3": "bash -c \"cp '$source' '$dest';" + "printf ISMP3 >> '$dest'\"" - } + self.config["convert"]["formats"] = {"mp3": convert_command("MP3")} self.config["alternatives"]["myexternal"]["formats"] = "mp3" # Assert that this re-encodes instead of copying the ogg file diff --git a/test/helper.py b/test/helper.py index 2147162..6b9c582 100644 --- a/test/helper.py +++ b/test/helper.py @@ -1,4 +1,5 @@ import os +import platform import shutil import sys import tempfile @@ -324,3 +325,18 @@ def submit(self, *args, **kwargs): def shutdown(self, wait=True): pass + + +def convert_command(tag: str) -> str: + match platform.system(): + case "Windows": + return ( + 'powershell -Command "' + "Copy-Item -Path '$source' -Destination '$dest' -NoNewline;" + f"Add-Content -Path '$dest' -Value {tag}" + '"' + ) + case "Linux": + return f"bash -c\" cp '$source' '$dest'; printf {tag} >> '$dest' \"" + case system: + raise Exception(f"Unsupported system: {system}")