124 lines
4.5 KiB
Python
124 lines
4.5 KiB
Python
"""Round 102: the ✕ that cancels a deck's vocals split."""
|
|
import threading
|
|
import time
|
|
|
|
from PyQt6.QtWidgets import QApplication
|
|
|
|
from lintunes.dj import stems
|
|
from tests.test_round93 import _clicks, _loaded, shelf # noqa: F401 — fixture
|
|
|
|
|
|
def _wait(predicate, seconds=3.0):
|
|
end = time.monotonic() + seconds
|
|
while time.monotonic() < end:
|
|
QApplication.processEvents()
|
|
if predicate():
|
|
return True
|
|
time.sleep(0.01)
|
|
return False
|
|
|
|
|
|
def test_cancelling_the_running_split_stops_demucs(qapp, monkeypatch):
|
|
started = threading.Event()
|
|
|
|
def fake_split(path, model, gentle, progress=None, cancel=None):
|
|
started.set()
|
|
while not cancel.wait(0.01):
|
|
pass
|
|
raise stems.Cancelled()
|
|
|
|
monkeypatch.setattr(stems, "cached", lambda path, model=None: None)
|
|
monkeypatch.setattr(stems, "split", fake_split)
|
|
splitter = stems.StemSplitter()
|
|
called_off, done = [], []
|
|
splitter.cancelled.connect(called_off.append)
|
|
splitter.finished.connect(lambda p, f: done.append(p))
|
|
splitter.request("/a.mp3")
|
|
assert started.wait(2)
|
|
splitter.cancel("/a.mp3")
|
|
assert _wait(lambda: called_off == ["/a.mp3"])
|
|
assert done == []
|
|
|
|
|
|
def test_cancelling_a_queued_song_takes_it_out(qapp, monkeypatch):
|
|
release = threading.Event()
|
|
ran = []
|
|
|
|
def fake_split(path, model, gentle, progress=None, cancel=None):
|
|
ran.append(path)
|
|
release.wait(2)
|
|
return {}
|
|
|
|
monkeypatch.setattr(stems, "cached", lambda path, model=None: None)
|
|
monkeypatch.setattr(stems, "split", fake_split)
|
|
splitter = stems.StemSplitter()
|
|
called_off = []
|
|
splitter.cancelled.connect(called_off.append)
|
|
splitter.request("/a.mp3")
|
|
assert _wait(lambda: ran == ["/a.mp3"])
|
|
splitter.request("/b.mp3")
|
|
assert _wait(lambda: "/b.mp3" in splitter._queue)
|
|
splitter.cancel("/b.mp3")
|
|
assert called_off == ["/b.mp3"] and "/b.mp3" not in splitter._queue
|
|
release.set()
|
|
time.sleep(0.1)
|
|
assert ran == ["/a.mp3"]
|
|
|
|
|
|
def test_the_x_shows_while_splitting_and_the_slider_retries(shelf, monkeypatch):
|
|
from tests.test_round93 import RATE # noqa: F401
|
|
asked, cancelled = [], []
|
|
monkeypatch.setattr(stems, "available", lambda: True)
|
|
monkeypatch.setattr(shelf._splitter, "request", asked.append)
|
|
monkeypatch.setattr(shelf._splitter, "cancel", cancelled.append)
|
|
a, _ = shelf.views
|
|
_loaded(shelf, a, shelf.tracks[0], _clicks(124, 0.1, 5), 124.0, 0.1)
|
|
x = shelf.stem_cancel["A"]
|
|
assert asked == ["/x.mp3"]
|
|
assert not x.isHidden() and x.toolTip() == "cancel vocals split"
|
|
assert not shelf.vocal_sliders["A"].isEnabled()
|
|
x.click()
|
|
assert cancelled == ["/x.mp3"]
|
|
shelf._on_stem_cancelled("/x.mp3") # what the splitter answers
|
|
assert x.isHidden()
|
|
assert "cancelled" in shelf.stem_labels["A"].text()
|
|
slider = shelf.vocal_sliders["A"]
|
|
assert slider.isEnabled()
|
|
slider.sliderPressed.emit()
|
|
assert asked == ["/x.mp3", "/x.mp3"]
|
|
assert not x.isHidden()
|
|
slider.sliderPressed.emit() # already splitting: no second ask
|
|
assert asked == ["/x.mp3", "/x.mp3"]
|
|
|
|
|
|
def test_view_menu_dark_mode_toggles_and_follows(qapp, tmp_path):
|
|
from tests.test_round69 import _window
|
|
from lintunes import theme
|
|
from lintunes.preferences import Preferences
|
|
window = _window(qapp, tmp_path)
|
|
action = window._dark_action
|
|
assert action.shortcut().toString() == "Ctrl+Shift+D"
|
|
action.trigger()
|
|
assert window._prefs.get("dark_mode") is True
|
|
window._prefs.set("dark_mode", False) # e.g. the toolbar button
|
|
assert not action.isChecked()
|
|
theme.apply_theme(qapp, Preferences(tmp_path / "light"))
|
|
|
|
|
|
def test_visualizer_has_its_own_page_sized_to_the_style_shown(qapp, tmp_path):
|
|
from lintunes.gui.preferences_dialog import PreferencesDialog
|
|
from lintunes.preferences import Preferences
|
|
from tests.test_round40 import _FakeLastFm
|
|
PreferencesDialog._last_page = 0
|
|
dialog = PreferencesDialog(Preferences(tmp_path), _FakeLastFm())
|
|
names = [dialog.pages_list.item(i).text() for i in range(dialog.pages_list.count())]
|
|
assert names.index("Visualizer") == names.index("Appearance") + 1
|
|
stack = dialog._viz_pages
|
|
dialog._viz_radios["laser"].setChecked(True)
|
|
laser = stack.sizeHint().height()
|
|
dialog._viz_radios["radial"].setChecked(True)
|
|
radial = stack.sizeHint().height()
|
|
assert radial < laser - 100 # no laser-sized gap under radial
|
|
assert abs(radial - stack.currentWidget().sizeHint().height()) <= 2
|
|
dialog.deleteLater()
|