mirror of
https://github.com/beetbox/beets.git
synced 2025-12-06 08:39:17 +01:00
convert: playlist: Add test_m3ufile and fixtures
Add several tests checking loading and saving unicode and regular ascii text playlist files.
This commit is contained in:
parent
ba3740c8fe
commit
0cbf91e4d8
3 changed files with 87 additions and 0 deletions
3
test/rsrc/playlist.m3u
Normal file
3
test/rsrc/playlist.m3u
Normal file
|
|
@ -0,0 +1,3 @@
|
|||
#EXTM3U
|
||||
/This/is/a/path/to_a_file.mp3
|
||||
/This/is/another/path/to_a_file.mp3
|
||||
3
test/rsrc/playlist.m3u8
Normal file
3
test/rsrc/playlist.m3u8
Normal file
|
|
@ -0,0 +1,3 @@
|
|||
#EXTM3U
|
||||
/This/is/å/path/to_a_file.mp3
|
||||
/This/is/another/path/tö_a_file.mp3
|
||||
81
test/test_m3ufile.py
Normal file
81
test/test_m3ufile.py
Normal file
|
|
@ -0,0 +1,81 @@
|
|||
# This file is part of beets.
|
||||
# Copyright 2016, Johannes Tiefenbacher.
|
||||
#
|
||||
# Permission is hereby granted, free of charge, to any person obtaining
|
||||
# a copy of this software and associated documentation files (the
|
||||
# "Software"), to deal in the Software without restriction, including
|
||||
# without limitation the rights to use, copy, modify, merge, publish,
|
||||
# distribute, sublicense, and/or sell copies of the Software, and to
|
||||
# permit persons to whom the Software is furnished to do so, subject to
|
||||
# the following conditions:
|
||||
#
|
||||
# The above copyright notice and this permission notice shall be
|
||||
# included in all copies or substantial portions of the Software.
|
||||
|
||||
|
||||
from os import path, remove
|
||||
from tempfile import mkdtemp
|
||||
from shutil import rmtree
|
||||
import unittest
|
||||
|
||||
# from unittest.mock import Mock, MagicMock
|
||||
|
||||
from beets.util import M3UFile
|
||||
from beets.util import syspath, bytestring_path, py3_path, CHAR_REPLACE
|
||||
from test._common import RSRC
|
||||
|
||||
|
||||
class M3UFileTest(unittest.TestCase):
|
||||
def test_playlist_write_empty(self):
|
||||
tempdir = bytestring_path(mkdtemp())
|
||||
the_playlist_file = path.join(tempdir, b'playlist.m3u8')
|
||||
m3ufile = M3UFile(the_playlist_file)
|
||||
m3ufile.write()
|
||||
self.assertFalse(path.exists(the_playlist_file))
|
||||
rmtree(tempdir)
|
||||
|
||||
def test_playlist_write(self):
|
||||
tempdir = bytestring_path(mkdtemp())
|
||||
the_playlist_file = path.join(tempdir, b'playlist.m3u')
|
||||
m3ufile = M3UFile(the_playlist_file)
|
||||
m3ufile.set_contents([
|
||||
'/This/is/a/path/to_a_file.mp3',
|
||||
'/This/is/another/path/to_a_file.mp3',
|
||||
])
|
||||
m3ufile.write()
|
||||
self.assertTrue(path.exists(the_playlist_file))
|
||||
rmtree(tempdir)
|
||||
|
||||
def test_playlist_write_unicode(self):
|
||||
tempdir = bytestring_path(mkdtemp())
|
||||
the_playlist_file = path.join(tempdir, b'playlist.m3u8')
|
||||
m3ufile = M3UFile(the_playlist_file)
|
||||
m3ufile.set_contents([
|
||||
'/This/is/å/path/to_a_file.mp3',
|
||||
'/This/is/another/path/tö_a_file.mp3',
|
||||
])
|
||||
m3ufile.write()
|
||||
self.assertTrue(path.exists(the_playlist_file))
|
||||
rmtree(tempdir)
|
||||
|
||||
def test_playlist_load_ascii(self):
|
||||
the_playlist_file = path.join(RSRC, b'playlist.m3u')
|
||||
m3ufile = M3UFile(the_playlist_file)
|
||||
m3ufile.load()
|
||||
self.assertEqual(m3ufile.media_list[0],
|
||||
'/This/is/a/path/to_a_file.mp3\n')
|
||||
|
||||
def test_playlist_load_unicode(self):
|
||||
the_playlist_file = path.join(RSRC, b'playlist.m3u8')
|
||||
m3ufile = M3UFile(the_playlist_file)
|
||||
m3ufile.load()
|
||||
self.assertEqual(m3ufile.media_list[0],
|
||||
'/This/is/å/path/to_a_file.mp3\n')
|
||||
|
||||
|
||||
def suite():
|
||||
return unittest.TestLoader().loadTestsFromName(__name__)
|
||||
|
||||
|
||||
if __name__ == '__main__':
|
||||
unittest.main(defaultTest='suite')
|
||||
Loading…
Reference in a new issue