From 2e8fae99edaa139f570664f86c8f289a1674597d Mon Sep 17 00:00:00 2001 From: Keith Edmunds Date: Sat, 27 Apr 2024 19:33:35 +0100 Subject: [PATCH] Pull in recent V3 updates --- app/classes.py | 11 ++++++++--- app/dialogs.py | 14 ++++++-------- app/musicmuster.py | 10 +++++----- app/pipeclient.py | 6 +++--- app/playlistmodel.py | 2 +- tests/test_playlistmodel.py | 30 +++++++++++++++++++++++------- tests/test_playlists.py | 14 +++++++------- 7 files changed, 53 insertions(+), 34 deletions(-) diff --git a/app/classes.py b/app/classes.py index 83ead0d..2abf95c 100644 --- a/app/classes.py +++ b/app/classes.py @@ -183,14 +183,19 @@ class PlaylistTrack: Called when track starts playing """ - self.start_time = dt.datetime.now() + now = dt.datetime.now() + self.start_time = now if self.duration: self.end_time = self.start_time + dt.timedelta(milliseconds=self.duration) # Calculate time fade_graph should start updating if self.fade_at: - update_graph_at_ms = max(0, self.fade_at - Config.FADE_CURVE_MS_BEFORE_FADE - 1) - self.fade_graph_start_updates = now + timedelta(milliseconds=update_graph_at_ms) + update_graph_at_ms = max( + 0, self.fade_at - Config.FADE_CURVE_MS_BEFORE_FADE - 1 + ) + self.fade_graph_start_updates = now + dt.timedelta( + milliseconds=update_graph_at_ms + ) class AddFadeCurve(QObject): diff --git a/app/dialogs.py b/app/dialogs.py index 02b0ba2..3c195e1 100644 --- a/app/dialogs.py +++ b/app/dialogs.py @@ -1,17 +1,15 @@ # Standard library imports - -# PyQt imports - -# Third party imports - -# App imports from typing import Optional +# PyQt imports from PyQt6.QtCore import QEvent, Qt from PyQt6.QtWidgets import QDialog, QListWidgetItem +# Third party imports +from sqlalchemy.orm.session import Session + +# App imports from classes import MusicMusterSignals -from sqlalchemy.orm import scoped_session from helpers import ( ask_yes_no, get_relative_date, @@ -28,7 +26,7 @@ class TrackSelectDialog(QDialog): def __init__( self, - session: scoped_session, + session: Session, new_row_number: int, source_model: PlaylistModel, add_to_header: Optional[bool] = False, diff --git a/app/musicmuster.py b/app/musicmuster.py index b995b61..ea9f3f0 100755 --- a/app/musicmuster.py +++ b/app/musicmuster.py @@ -48,7 +48,7 @@ from PyQt6.QtWidgets import ( # Third party imports from pygame import mixer import pipeclient -from sqlalchemy.orm import scoped_session +from sqlalchemy.orm.session import Session import stackprinter # type: ignore # App imports @@ -562,7 +562,7 @@ class Window(QMainWindow, Ui_MainWindow): self.timer1000.timeout.connect(self.tick_1000ms) def create_playlist( - self, session: scoped_session, playlist_name: Optional[str] = None + self, session: Session, playlist_name: Optional[str] = None ) -> Optional[Playlists]: """Create new playlist""" @@ -1405,7 +1405,7 @@ class Window(QMainWindow, Ui_MainWindow): self.tabPlaylist.currentWidget().scroll_to_top(display_row) def solicit_playlist_name( - self, session: scoped_session, default: str = "" + self, session: Session, default: str = "" ) -> Optional[str]: """Get name of new playlist from user""" @@ -1508,7 +1508,7 @@ class Window(QMainWindow, Ui_MainWindow): # Update volume fade curve if ( track_sequence.now.fade_graph_start_updates is None - or track_sequence.now.fade_graph_start_updates > datetime.now() + or track_sequence.now.fade_graph_start_updates > dt.datetime.now() ): return @@ -1640,7 +1640,7 @@ class CartDialog(QDialog): """Edit cart details""" def __init__( - self, musicmuster: Window, session: scoped_session, cart: Carts, *args, **kwargs + self, musicmuster: Window, session: Session, cart: Carts, *args, **kwargs ) -> None: """ Manage carts diff --git a/app/pipeclient.py b/app/pipeclient.py index 9ef0c38..749ebac 100755 --- a/app/pipeclient.py +++ b/app/pipeclient.py @@ -160,7 +160,7 @@ class PipeClient: def _write_pipe_open(self) -> None: """Open _write_pipe.""" - self._write_pipe = open(WRITE_NAME, 'w') + self._write_pipe = open(WRITE_NAME, "w") def _read_thread_start(self) -> None: """Start read_pipe thread.""" @@ -204,8 +204,8 @@ class PipeClient: """Read FIFO in worker thread.""" # Thread will wait at this read until it connects. # Connection should occur as soon as _write_pipe has connected. - with open(READ_NAME, 'r') as read_pipe: - message = '' + with open(READ_NAME, "r") as read_pipe: + message = "" pipe_ok = True while pipe_ok: line = read_pipe.readline() diff --git a/app/playlistmodel.py b/app/playlistmodel.py index 3ae0a79..6938935 100644 --- a/app/playlistmodel.py +++ b/app/playlistmodel.py @@ -1569,7 +1569,7 @@ class PlaylistProxyModel(QSortFilterProxyModel): self, proposed_row_number: Optional[int], track_id: Optional[int] = None, - note: Optional[str] = None, + note: str = "", ) -> None: return self.source_model.insert_row(proposed_row_number, track_id, note) diff --git a/tests/test_playlistmodel.py b/tests/test_playlistmodel.py index 35e9242..d164750 100644 --- a/tests/test_playlistmodel.py +++ b/tests/test_playlistmodel.py @@ -79,12 +79,13 @@ class TestMMMiscTracks(unittest.TestCase): self.model.insert_row(proposed_row_number=END_ROW, note="-") prd = self.model.playlist_rows[START_ROW] - qv_value = self.model.display_role(START_ROW, playlistmodel.HEADER_NOTES_COLUMN, prd) + qv_value = self.model.display_role( + START_ROW, playlistmodel.HEADER_NOTES_COLUMN, prd + ) assert qv_value.value() == "start [1 tracks, 4:23 unplayed]" class TestMMMiscNoPlaylist(unittest.TestCase): - PLAYLIST_NAME = "tracks playlist" test_tracks = [ "testdata/isa.mp3", @@ -121,10 +122,13 @@ class TestMMMiscNoPlaylist(unittest.TestCase): _ = str(prd) assert ( - model.edit_role(model.rowCount() - 1, playlistmodel.Col.TITLE.value, prd) + model.edit_role( + model.rowCount() - 1, playlistmodel.Col.TITLE.value, prd + ) == metadata["title"] ) + class TestMMMiscRowMove(unittest.TestCase): PLAYLIST_NAME = "rowmove playlist" ROWS_TO_CREATE = 11 @@ -292,7 +296,6 @@ class TestMMMiscRowMove(unittest.TestCase): self.model.add_track_to_header(insert_row, prd.track_id) def test_reverse_row_groups_one_row(self): - rows_to_move = [3] result = self.model._reversed_contiguous_row_groups(rows_to_move) @@ -301,7 +304,6 @@ class TestMMMiscRowMove(unittest.TestCase): assert result[0] == [3] def test_reverse_row_groups_multiple_row(self): - rows_to_move = [2, 3, 4, 5, 7, 9, 10, 13, 17, 20, 21] result = self.model._reversed_contiguous_row_groups(rows_to_move) @@ -357,7 +359,6 @@ class TestMMMiscRowMove(unittest.TestCase): assert [int(a) for a in row_notes] == [0, 1, 3, 2, 3, 4, 5, 6, 7, 8, 9, 10] def test_move_multiple_rows_between_playlists_to_end(self): - from_rows = [1, 3, 4] to_row = 2 destination_playlist = "destination" @@ -382,7 +383,22 @@ class TestMMMiscRowMove(unittest.TestCase): assert len(model_src.playlist_rows) == self.ROWS_TO_CREATE - len(from_rows) assert len(model_dst.playlist_rows) == self.ROWS_TO_CREATE + len(from_rows) - assert [int(a) for a in row_notes] == [0, 1, 3, 4, 1, 2, 3, 4, 5, 6, 7, 8, 9, 10] + assert [int(a) for a in row_notes] == [ + 0, + 1, + 3, + 4, + 1, + 2, + 3, + 4, + 5, + 6, + 7, + 8, + 9, + 10, + ] # # def test_edit_header(monkeypatch, session): # edit header row in middle of playlist diff --git a/tests/test_playlists.py b/tests/test_playlists.py index 8962e91..ad4f80d 100644 --- a/tests/test_playlists.py +++ b/tests/test_playlists.py @@ -41,13 +41,14 @@ def qtbot_adapter(qapp, request): # Wrapper to handle setup/teardown operations def with_updown(function): def test_wrapper(self, *args, **kwargs): - if callable(getattr(self, 'up', None)): + if callable(getattr(self, "up", None)): self.up() try: function(self, *args, **kwargs) finally: - if callable(getattr(self, 'down', None)): + if callable(getattr(self, "down", None)): self.down() + test_wrapper.__doc__ = function.__doc__ return test_wrapper @@ -103,12 +104,11 @@ class MyTestCase(unittest.TestCase): # }, # ] - # for track in tracks: - # db_track = models.Tracks(session=session, **track) - # session.add(db_track) - - # session.commit() +# for track in tracks: +# db_track = models.Tracks(session=session, **track) +# session.add(db_track) +# session.commit() # def test_save_and_restore(qtbot, session):