"""Round 79: per-track volume, Get Info tidy-up, Preferences headings, and the laser rig diagram. 1. (Retired in Round 131: the per-track volume adjustment, which could never play past full volume; Boost Volume amplifies the file instead.) 2. Get Info has no dead Previous/Next buttons. 3. Preferences section headings are bold and 2 px larger than the text. 4. The laser page draws the rig, labelling distance, angles and dot size in place of those sliders' own numbers. """ import pytest from PyQt6.QtCore import QObject, pyqtSignal from PyQt6.QtGui import QFontInfo from PyQt6.QtWidgets import QApplication, QLabel, QPushButton from lintunes.preferences import Preferences # -------------------------------------------------------------------------- # 2. Get Info # -------------------------------------------------------------------------- @pytest.fixture def manager(tmp_path): from lintunes.library_manager import LibraryManager from lintunes.models import Library, Track library = Library() for tid, adj in ((1, 0), (2, 51), (3, 51)): library.tracks[tid] = Track(track_id=tid, name=f"Song {tid}", volume_adjustment=adj) return LibraryManager(library, tmp_path) def _info(manager, ids): from lintunes.gui.info_dialog import InfoDialog return InfoDialog(manager, ids) class TestInfoDialog: def test_no_previous_or_next(self, qapp, manager): for ids in ([1], [1, 2]): texts = {b.text() for b in _info(manager, ids).findChildren(QPushButton)} assert not texts & {"Previous", "Next"} # -------------------------------------------------------------------------- # 3 & 4. Preferences # -------------------------------------------------------------------------- class _LastFm(QObject): login_finished = pyqtSignal(bool, str) status_message = pyqtSignal(str) def is_logged_in(self): return False def _prefs_dialog(prefs): from lintunes.gui.preferences_dialog import PreferencesDialog return PreferencesDialog(prefs, _LastFm()) class TestHeadings: def test_bold_and_two_px_larger(self, qapp, tmp_path): from lintunes import theme prefs = Preferences(tmp_path) theme.apply_theme(QApplication.instance(), prefs) # as the app runs dialog = _prefs_dialog(prefs) dialog.show() text_px = QFontInfo(QApplication.font()).pixelSize() headings = dialog.findChildren(QLabel, "prefs-heading") assert {h.text() for h in headings} >= {"Interface", "Visualizer", "Colors", "Last.fm"} for heading in headings: assert heading.font().bold() assert QFontInfo(heading.font()).pixelSize() == text_px + 2 dialog.close() def test_the_boxes_contents_stay_plain(self, qapp, tmp_path): dialog = _prefs_dialog(Preferences(tmp_path)) assert not dialog._glow.font().bold() # -------------------------------------------------------------------------- # 5. Copying songs gives other apps a song list # -------------------------------------------------------------------------- def _table(tracks, playlist_mode=True): from lintunes.gui.track_table import TrackTableView table = TrackTableView(playlist_mode=playlist_mode) table.set_source_playlist("PID") table.set_tracks(tracks) return table def _songs(): from lintunes.models import Track return [Track(track_id=1, name="Low Tide", artist="The Wheelhouse"), Track(track_id=2, name="Café Noir", artist="Marguerite Vaux"), Track(track_id=3, name="Orphan Take", artist="")] class TestCopyAsText: def test_select_all_copy_pastes_as_a_list(self, qapp): from lintunes.gui.track_table import parse_tracks_mime table = _table(_songs()) table.selectAll() table.copy_selection() mime = QApplication.clipboard().mimeData() assert mime.text() == ("The Wheelhouse - Low Tide\n" "Marguerite Vaux - Café Noir\n" "Orphan Take") # …and pasting into a playlist still reads the songs themselves. assert parse_tracks_mime(mime)["track_ids"] == [1, 2, 3] def test_the_list_follows_the_order_shown(self, qapp): from PyQt6.QtCore import Qt table = _table(_songs(), playlist_mode=False) name = table.model_.fields.index("name") table.sortByColumn(name, Qt.SortOrder.AscendingOrder) table.selectAll() table.copy_selection() assert QApplication.clipboard().text().splitlines() == [ "Marguerite Vaux - Café Noir", "The Wheelhouse - Low Tide", "Orphan Take"] def test_cut_carries_the_list_too(self, qapp): table = _table(_songs()) table.selectRow(0) table.cut_selection() assert QApplication.clipboard().text() == "The Wheelhouse - Low Tide" def test_untitled_song(self, qapp): from lintunes.gui.track_table import song_line from lintunes.models import Track assert song_line(Track(track_id=9, name="", artist="X")) == "X - Untitled" class TestAfterimageBox: def test_steps_by_a_twentieth_and_reads_off_at_zero(self, qapp, tmp_path): prefs = Preferences(tmp_path) box = _prefs_dialog(prefs)._laser_fade_box assert box.value() == pytest.approx(0.1) # the default box.stepUp() assert prefs.get("visualizer_laser_afterimage") == pytest.approx(0.15) box.setValue(0) assert box.text() == "Off" box.setValue(99) # past the top assert box.value() == 3.0