From 13ff9e84d4e615d366a820c65c3797edebfc91fd Mon Sep 17 00:00:00 2001 From: Dev Mehta Date: Mon, 27 Oct 2025 16:31:04 -0700 Subject: [PATCH] added test cases and change log --- test/plugins/test_convert.py | 39 ++++++++++++++++++++++++++++++++++++ 1 file changed, 39 insertions(+) diff --git a/test/plugins/test_convert.py b/test/plugins/test_convert.py index 1452686a7..76b8ced91 100644 --- a/test/plugins/test_convert.py +++ b/test/plugins/test_convert.py @@ -260,6 +260,45 @@ class ConvertCliTest(ConvertTestCase, ConvertCommand): self.run_convert("--playlist", "playlist.m3u8", "--pretend") assert not (self.convert_dest / "playlist.m3u8").exists() + def test_playlist_generation_with_fallback_and_unicode(tmp_path, library, convert_plugin): + # Setup items with one having no path (to trigger fallback), one with Unicode filename + item_with_path = library.add_item(path=str(tmp_path / "song1.mp3")) + item_with_path.path = str(tmp_path / "song1.mp3") + item_missing_path = library.add_item(path=str(tmp_path / "song\u2603.mp3")) + item_missing_path.path = "" # empty path to force fallback + + # Destination directory + dest = tmp_path / "dest" + dest.mkdir() + + playlist_path = tmp_path / "test_playlist.m3u" + + # Manually call playlist generation code from convert_func + items = [item_with_path, item_missing_path] + pl_normpath = str(playlist_path) + pl_dir = str(playlist_path.parent) + + items_paths = [] + for item in items: + path = item.path if item.path else item.destination(basedir=str(dest)) + rel_path = os.path.relpath(path, pl_dir) + # Ensure UTF-8 string + if isinstance(rel_path, bytes): + rel_path = rel_path.decode("utf-8", errors="replace") + items_paths.append(rel_path) + + m3ufile = convert_plugin.M3UFile(playlist_path) + m3ufile.set_contents(items_paths) + m3ufile.write() + + # Assert playlist was created and contains expected content + assert playlist_path.exists() + content = playlist_path.read_text(encoding="utf-8") + assert "song1.mp3" in content + assert "\u2603" in content # snowman unicode char + + + @_common.slow_test() class NeverConvertLossyFilesTest(ConvertTestCase, ConvertCommand):