v0.58.0: the library search filters the sidebar's playlists
- Typing in the library search now also narrows the playlist list to names containing every word; folders stay when they or something inside match, open while filtering, and clearing puts back the folders you had open. - AirPlay: an unreadable /info reply no longer fails the stream (pyatv died on shairport-sync's).
This commit is contained in:
@@ -0,0 +1,112 @@
|
||||
"""Round 89: the library search filters the sidebar's playlists too, and
|
||||
AirPlay survives a receiver whose /info isn't a plist (shairport-sync)."""
|
||||
|
||||
import asyncio
|
||||
from types import SimpleNamespace
|
||||
|
||||
from lintunes.gui.sidebar import PID_ROLE, PlaylistTree
|
||||
from lintunes.library_manager import LibraryManager
|
||||
from lintunes.models import Playlist, PlaylistType
|
||||
from lintunes.models.library import Library
|
||||
|
||||
|
||||
def _tree(qapp, tmp_path):
|
||||
library = Library()
|
||||
def add(pid, name, parent="", folder=False):
|
||||
library.playlists[pid] = Playlist(
|
||||
persistent_id=pid, name=name, parent_persistent_id=parent,
|
||||
playlist_type=PlaylistType.FOLDER if folder else PlaylistType.REGULAR)
|
||||
add("f0000001", "Summer", folder=True)
|
||||
add("p0000001", "Beach Day", parent="f0000001")
|
||||
add("p0000002", "Night Drive", parent="f0000001")
|
||||
add("f0000002", "Jazz", folder=True)
|
||||
add("p0000003", "Late Jazz Night", parent="f0000002")
|
||||
add("p0000004", "Road Trip")
|
||||
add("p0000005", "Gallery Night")
|
||||
return PlaylistTree(LibraryManager(library, tmp_path))
|
||||
|
||||
|
||||
def _shown(tree) -> set[str]:
|
||||
out, stack = set(), [tree.topLevelItem(i) for i in range(tree.topLevelItemCount())]
|
||||
while stack:
|
||||
item = stack.pop()
|
||||
if not item.isHidden():
|
||||
out.add(item.text(0))
|
||||
stack.extend(item.child(i) for i in range(item.childCount()))
|
||||
return out
|
||||
|
||||
|
||||
def _item(tree, pid):
|
||||
return tree._find_item(pid)
|
||||
|
||||
|
||||
class TestPlaylistFilter:
|
||||
def test_matches_names_and_keeps_their_folders(self, qapp, tmp_path):
|
||||
tree = _tree(qapp, tmp_path)
|
||||
tree.set_filter("night")
|
||||
assert _shown(tree) == {"Summer", "Night Drive", "Jazz",
|
||||
"Late Jazz Night", "Gallery Night"}
|
||||
assert _item(tree, "f0000001").isExpanded()
|
||||
|
||||
def test_every_word_case_folded(self, qapp, tmp_path):
|
||||
tree = _tree(qapp, tmp_path)
|
||||
tree.set_filter("NIGHT jazz")
|
||||
assert _shown(tree) == {"Jazz", "Late Jazz Night"}
|
||||
|
||||
def test_a_matching_folder_shows_everything_in_it(self, qapp, tmp_path):
|
||||
tree = _tree(qapp, tmp_path)
|
||||
tree.set_filter("summer")
|
||||
assert _shown(tree) == {"Summer", "Beach Day", "Night Drive"}
|
||||
|
||||
def test_clearing_restores_all_and_the_old_folder_state(self, qapp, tmp_path):
|
||||
tree = _tree(qapp, tmp_path)
|
||||
_item(tree, "f0000002").setExpanded(True) # Jazz open, Summer shut
|
||||
tree.set_filter("beach")
|
||||
assert _item(tree, "f0000001").isExpanded()
|
||||
tree.set_filter("")
|
||||
assert len(_shown(tree)) == 7
|
||||
assert not _item(tree, "f0000001").isExpanded()
|
||||
assert _item(tree, "f0000002").isExpanded()
|
||||
|
||||
def test_a_rebuild_while_filtering_stays_filtered(self, qapp, tmp_path):
|
||||
tree = _tree(qapp, tmp_path)
|
||||
tree.set_filter("road")
|
||||
tree.rebuild()
|
||||
assert _shown(tree) == {"Road Trip"}
|
||||
tree.set_filter("")
|
||||
assert not _item(tree, "f0000001").isExpanded() # never opened by hand
|
||||
|
||||
def test_the_library_search_drives_it(self, qapp, tmp_path):
|
||||
from lintunes.gui.main_window import MainWindow
|
||||
from lintunes.preferences import Preferences
|
||||
library = Library()
|
||||
library.playlists["p0000001"] = Playlist(persistent_id="p0000001",
|
||||
name="Road Trip")
|
||||
library.playlists["p0000002"] = Playlist(persistent_id="p0000002",
|
||||
name="Gallery")
|
||||
window = MainWindow(LibraryManager(library, tmp_path), Preferences(tmp_path))
|
||||
try:
|
||||
view = window._library_view
|
||||
view._search.setText("gall")
|
||||
view._apply_search()
|
||||
assert _shown(window._sidebar.tree) == {"Gallery"}
|
||||
view._search.setText("")
|
||||
view._apply_search()
|
||||
assert _shown(window._sidebar.tree) == {"Road Trip", "Gallery"}
|
||||
finally:
|
||||
window.close()
|
||||
|
||||
|
||||
class TestInfoTolerance:
|
||||
def test_an_unreadable_info_is_no_info(self):
|
||||
from pyatv.support import rtsp
|
||||
from lintunes.airplay.stream import install_shim
|
||||
install_shim()
|
||||
|
||||
async def exchange(self, *a, **kw):
|
||||
return SimpleNamespace(code=200, headers={}, body=b"not a plist")
|
||||
|
||||
session = rtsp.RtspSession(SimpleNamespace(remote_ip="1.2.3.4",
|
||||
local_ip="1.2.3.5"))
|
||||
session.exchange = exchange.__get__(session)
|
||||
assert asyncio.run(session.info()) == {}
|
||||
Reference in New Issue
Block a user