From 0682d0d0301fd11f47031e2812ee1043cbeabb9e Mon Sep 17 00:00:00 2001 From: =?UTF-8?q?=C5=A0ar=C5=ABnas=20Nejus?= Date: Tue, 2 Jul 2024 02:08:31 +0100 Subject: [PATCH] test_play: Remove files generated by play plugin --- beetsplug/play.py | 16 ++++++++-------- test/plugins/test_play.py | 7 +++++-- 2 files changed, 13 insertions(+), 10 deletions(-) diff --git a/beetsplug/play.py b/beetsplug/play.py index 4884bc8be..3476e5824 100644 --- a/beetsplug/play.py +++ b/beetsplug/play.py @@ -18,12 +18,12 @@ import shlex import subprocess from os.path import relpath -from tempfile import NamedTemporaryFile from beets import config, ui, util from beets.plugins import BeetsPlugin from beets.ui import Subcommand from beets.ui.commands import PromptChoice +from beets.util import get_temp_filename # Indicate where arguments should be inserted into the command string. # If this is missing, they're placed at the end. @@ -194,15 +194,15 @@ class PlayPlugin(BeetsPlugin): def _create_tmp_playlist(self, paths_list): """Create a temporary .m3u file. Return the filename.""" utf8_bom = config["play"]["bom"].get(bool) - m3u = NamedTemporaryFile("wb", suffix=".m3u", delete=False) + filename = get_temp_filename(__name__, suffix=".m3u") + with open(filename, "wb") as m3u: + if utf8_bom: + m3u.write(b"\xEF\xBB\xBF") - if utf8_bom: - m3u.write(b"\xEF\xBB\xBF") + for item in paths_list: + m3u.write(item + b"\n") - for item in paths_list: - m3u.write(item + b"\n") - m3u.close() - return m3u.name + return filename def before_choose_candidate_listener(self, session, task): """Append a "Play" choice to the interactive importer prompt.""" diff --git a/test/plugins/test_play.py b/test/plugins/test_play.py index cb99f6b43..ac60e8281 100644 --- a/test/plugins/test_play.py +++ b/test/plugins/test_play.py @@ -20,13 +20,16 @@ import sys import unittest from unittest.mock import ANY, patch -from beets.test.helper import TestHelper, control_stdin +from beets.test.helper import CleanupModulesMixin, TestHelper, control_stdin from beets.ui import UserError from beets.util import open_anything +from beetsplug.play import PlayPlugin @patch("beetsplug.play.util.interactive_open") -class PlayPluginTest(unittest.TestCase, TestHelper): +class PlayPluginTest(CleanupModulesMixin, unittest.TestCase, TestHelper): + modules = (PlayPlugin.__module__,) + def setUp(self): self.setup_beets() self.load_plugins("play")