1 2 3 4 5 6 7 8 9 10 11 12 13 14 15 16 17 18 19 20 21 22 23 24 25 26 27 28 29 30 31 32 33 34 35 36 37 38 39 40 41 42 43 44 45 46 47 48 49 50 51 52 53 54 55 56 57 58 59 60 61 62 63 64 65 66 67 68 69 70 71 72 73 74 75 76 77 78 79 80 81 82 83 84 85 86 87 88 89 90 91 92 93 94 95 96 97 98 99 100 101 102 103 104 105 106 107 108 109 110 111 112 113 114 115 116 117 118 119 120 121 122 123 124 125 126 127 128 129 130 131 132 133 134 135 136 137 138 139 140 141 142 143 144 145 146 147 148 149 150
|
import pytest
from mopidy.internal import playlists
BAD = b"foobarbaz"
EXTM3U = b"""#EXTM3U
#EXTINF:123, Sample artist - Sample title
file:///tmp/foo
#EXTINF:321,Example Artist - Example \xc5\xa7\xc5\x95
file:///tmp/bar
#EXTINF:213,Some Artist - Other title
file:///tmp/baz
"""
URILIST = b"""
file:///tmp/foo
# a comment \xc5\xa7\xc5\x95
file:///tmp/bar
file:///tmp/baz
"""
PLS = b"""[Playlist]
NumberOfEntries=3
File1="file:///tmp/foo"
Title1=Sample Title
Length1=123
Version=2
File2='file:///tmp/bar'
Title2=Example \xc5\xa7\xc5\x95
Length2=321
File3=file:///tmp/baz
Title3=Other title
Length3=213
Version=2
"""
ASX = b"""<ASX version="3.0">
<TITLE>Example</TITLE>
<ENTRY>
<TITLE>Sample Title</TITLE>
<REF href="file:///tmp/foo" />
</ENTRY>
<ENTRY>
<TITLE>Example \xc5\xa7\xc5\x95</TITLE>
<REF href="file:///tmp/bar" />
</ENTRY>
<ENTRY>
<TITLE>Other title</TITLE>
<REF href="file:///tmp/baz" />
</ENTRY>
</ASX>
"""
SIMPLE_ASX = b"""<ASX version="3.0">
<ENTRY href="file:///tmp/foo" />
<ENTRY href="file:///tmp/bar" />
<ENTRY href="file:///tmp/baz" />
</ASX>
"""
XSPF = b"""<?xml version="1.0" encoding="UTF-8"?>
<playlist version="1" xmlns="http://xspf.org/ns/0/">
<trackList>
<track>
<title>Sample Title</title>
<location>file:///tmp/foo</location>
</track>
<track>
<title>Example \xc5\xa7\xc5\x95</title>
<location>file:///tmp/bar</location>
</track>
<track>
<title>Other title</title>
<location>file:///tmp/baz</location>
</track>
</trackList>
</playlist>
"""
EXPECTED = ["file:///tmp/foo", "file:///tmp/bar", "file:///tmp/baz"]
@pytest.mark.parametrize(
"detect_fn, data",
[
(playlists.detect_extm3u_header, EXTM3U),
(playlists.detect_pls_header, PLS),
(playlists.detect_asx_header, ASX),
(playlists.detect_asx_header, SIMPLE_ASX),
(playlists.detect_xspf_header, XSPF),
],
)
def test_detect_from_valid_header(detect_fn, data):
assert detect_fn(data) is True
@pytest.mark.parametrize(
"detect_fn",
[
playlists.detect_extm3u_header,
playlists.detect_pls_header,
playlists.detect_asx_header,
playlists.detect_asx_header,
playlists.detect_xspf_header,
],
)
def test_detect_from_invalid_header(detect_fn):
assert detect_fn(BAD) is False
@pytest.mark.parametrize(
"parse_fn, data",
[
(playlists.parse_extm3u, EXTM3U),
(playlists.parse_pls, PLS),
(playlists.parse_asx, ASX),
(playlists.parse_asx, SIMPLE_ASX),
(playlists.parse_xspf, XSPF),
(playlists.parse_urilist, URILIST),
],
)
def test_parse_given_format_from_valid_data(parse_fn, data):
assert list(parse_fn(data)) == EXPECTED
@pytest.mark.parametrize(
"parse_fn",
[
playlists.parse_extm3u,
playlists.parse_pls,
playlists.parse_asx,
playlists.parse_xspf,
playlists.parse_urilist,
],
)
def test_parse_given_format_from_invalid_data(parse_fn):
assert list(parse_fn(BAD)) == []
@pytest.mark.parametrize("data", [URILIST, EXTM3U, PLS, ASX, SIMPLE_ASX, XSPF])
def test_parse_any_format_from_valid_data(data):
assert playlists.parse(data) == EXPECTED
def test_parse_from_invalid_data():
assert playlists.parse(BAD) == []
|