Compare commits

...

3 Commits

Author SHA1 Message Date
Keith Edmunds
35438f59fb Update tests 2024-04-27 20:36:04 +01:00
Keith Edmunds
189efb379f Fixup replace_files for Alchemical 2024-04-27 20:25:22 +01:00
Keith Edmunds
134961abfd Pull in recent V3 updates 2024-04-27 19:33:35 +01:00
11 changed files with 150 additions and 125 deletions

View File

@ -116,6 +116,7 @@ class PlaylistTrack:
self.end_time: Optional[dt.datetime] = None
self.fade_at: Optional[int] = None
self.fade_graph: Optional[FadeCurve] = None
self.fade_graph_start_updates: Optional[dt.datetime] = None
self.fade_length: Optional[int] = None
self.path: Optional[str] = None
self.playlist_id: Optional[int] = None
@ -182,10 +183,20 @@ 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 + dt.timedelta(
milliseconds=update_graph_at_ms
)
class AddFadeCurve(QObject):
"""

View File

@ -1,13 +1,11 @@
# Standard library imports
import os
import sys
from typing import List, Optional
import datetime as dt
# PyQt imports
# Third party imports
from alchemical import Alchemical, Model # type: ignore
from alchemical import Model # type: ignore
from sqlalchemy import (
Boolean,
DateTime,

View File

@ -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,

View File

@ -44,7 +44,7 @@ class FadeTrack(QRunnable):
sleep(1 / Config.FADEOUT_STEPS_PER_SECOND)
self.player.stop()
log.error(f"Releasing player {self.player=}")
log.debug(f"Releasing player {self.player=}")
self.player.release()

View File

@ -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"""
@ -1140,34 +1140,25 @@ class Window(QMainWindow, Ui_MainWindow):
break
sleep(0.1)
# TODO: remove sleep() calls - used to try to isolate bug #223
# Show closing volume graph
sleep(1)
if track_sequence.now.fade_graph:
track_sequence.now.fade_graph.plot()
else:
log.error("No fade_graph")
# Note that track is playing
sleep(1)
log.error("set track_sequence")
log.debug("set track_sequence")
track_sequence.now.start()
self.playing = True
# Disable play next controls
sleep(1)
log.error("catch return key")
self.catch_return_key = True
self.show_status_message("Play controls: Disabled", 0)
# Notify model
sleep(1)
log.error("active_proxy_model().current_track_started()")
self.active_proxy_model().current_track_started()
# Update headers
sleep(1)
log.error("update headers")
self.update_headers()
def preview(self) -> None:
@ -1413,7 +1404,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"""
@ -1514,6 +1505,12 @@ 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 > dt.datetime.now()
):
return
if (
track_sequence.now.track_id
and track_sequence.now.fade_graph
@ -1642,7 +1639,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

View File

@ -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()

View File

@ -279,21 +279,16 @@ class PlaylistModel(QAbstractTableModel):
)
return
# TODO: remove sleep/log calls, used to debug #223
# Check for OBS scene change
sleep(1)
log.error("Call OBS scene change")
log.debug("Call OBS scene change")
self.obs_scene_change(row_number)
with db.Session() as session:
# Update Playdates in database
sleep(1)
log.error("update playdates")
log.debug("update playdates")
Playdates(session, track_sequence.now.track_id)
# Mark track as played in playlist
sleep(1)
log.error("Mark track as played")
log.debug("Mark track as played")
plr = session.get(PlaylistRows, track_sequence.now.plr_id)
if plr:
plr.played = True
@ -302,8 +297,7 @@ class PlaylistModel(QAbstractTableModel):
log.error(f"Can't retrieve plr, {track_sequence.now.plr_id=}")
# Update track times
sleep(1)
log.error("Update track times")
log.debug("Update track times")
if prd:
prd.start_time = track_sequence.now.start_time
prd.end_time = track_sequence.now.end_time
@ -320,8 +314,7 @@ class PlaylistModel(QAbstractTableModel):
# Find next track
# Get all unplayed track rows
sleep(1)
log.error("Find next track")
log.debug("Find next track")
next_row = None
unplayed_rows = self.get_unplayed_rows()
if unplayed_rows:
@ -1222,7 +1215,7 @@ class PlaylistModel(QAbstractTableModel):
self.signals.next_track_changed_signal.emit()
return
# Update playing_track
# Update track_sequence
with db.Session() as session:
track_sequence.next = PlaylistTrack()
try:
@ -1576,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)

View File

@ -4,20 +4,25 @@
# the current directory contains a "better" version of the file than the
# parent (eg, bettet bitrate).
# Standard library imports
import os
import pydymenu # type: ignore
import shutil
import sys
from typing import List
# PyQt imports
# Third party imports
import pydymenu # type: ignore
from sqlalchemy.exc import IntegrityError
from sqlalchemy.orm.session import Session
# App imports
from helpers import (
get_tags,
set_track_metadata,
)
from models import Tracks
from dbconfig import Session
from sqlalchemy.exc import IntegrityError
from typing import List
from models import db, Tracks
# ###################### SETTINGS #########################
process_name_and_tags_matches = True
@ -42,7 +47,7 @@ def main():
# We only want to run this against the production database because
# we will affect files in the common pool of tracks used by all
# databases
if "musicmuster_prod" not in os.environ.get("MM_DB"):
if "musicmuster_prod" not in os.environ.get("ALCHEMICAL_DATABASE_URI"):
response = input("Not on production database - c to continue: ")
if response != "c":
sys.exit(0)
@ -51,7 +56,7 @@ def main():
assert source_dir != parent_dir
# Scan parent directory
with Session() as session:
with db.Session() as session:
all_tracks = Tracks.get_all(session)
parent_tracks = [a for a in all_tracks if parent_dir in a.path]
parent_fnames = [os.path.basename(a.path) for a in parent_tracks]
@ -239,7 +244,7 @@ def process_track(src, dst, title, artist, bitrate):
if not do_processing:
return
with Session() as session:
with db.Session() as session:
track = Tracks.get_by_path(session, dst)
if track:
# Update path, but workaround MariaDB bug

View File

@ -59,7 +59,7 @@ explicit_package_bases = true
[tool.pytest.ini_options]
addopts = "--exitfirst --showlocals --capture=no"
pythonpath = [".", "app"]
filterwarnings = "ignore:'audioop' is deprecated"
filterwarnings = ["ignore:'audioop' is deprecated", "ignore:pkg_resources"]
[tool.vulture]
exclude = ["migrations", "app/ui", "archive"]

View File

@ -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

View File

@ -18,6 +18,7 @@ DB_FILE = "/tmp/mm.db"
if os.path.exists(DB_FILE):
os.unlink(DB_FILE)
os.environ["ALCHEMICAL_DATABASE_URI"] = "sqlite:///" + DB_FILE
from app import playlistmodel, utilities
from app.models import ( # noqa: E402
db,
Carts,
@ -41,13 +42,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
@ -58,7 +60,41 @@ class MyTestCase(unittest.TestCase):
def up(self):
db.create_all()
self.widget = musicmuster.Window()
self.widget.show()
# self.widget.show()
# Add two tracks to database
self.tracks = {
1: {
"path": "testdata/isa.mp3",
"title": "I'm so afraid",
"artist": "Fleetwood Mac",
"bitrate": 64,
"duration": 263000,
"start_gap": 60,
"fade_at": 236263,
"silence_at": 260343,
"mtime": 371900000,
},
2: {
"path": "testdata/mom.mp3",
"title": "Man of Mystery",
"artist": "The Shadows",
"bitrate": 64,
"duration": 120000,
"start_gap": 70,
"fade_at": 115000,
"silence_at": 118000,
"mtime": 1642760000,
},
}
with db.Session() as session:
for track in self.tracks.values():
db_track = Tracks(session=session, **track)
session.add(db_track)
track['id'] = db_track.id
session.commit()
def down(self):
db.drop_all()
@ -67,81 +103,52 @@ class MyTestCase(unittest.TestCase):
def test_init(self):
"""Just check we can create a playlist_tab"""
with db.Session() as session:
playlist = Playlists(session, "test playlist")
# playlist_tab = playlists.PlaylistTab(self.widget, playlist.id)
playlist_name = "test_init playlist"
with db.Session() as session:
playlist = Playlists(session, playlist_name)
self.widget.create_playlist_tab(playlist)
with self.qtbot.waitExposed(self.widget):
# window.show()
# with self.qtbot.waitSignal(self.widget.my_signal, timeout=300):
# with qtbot.waitExposed(window):
self.widget.show()
@with_updown
def test_save_and_restore(self):
"""Playlist with one track, one note, save and restore"""
# def seed2tracks(session):
# tracks = [
# {
# "path": "testdata/isa.mp3",
# "title": "I'm so afraid",
# "artist": "Fleetwood Mac",
# "duration": 263000,
# "start_gap": 60,
# "fade_at": 236263,
# "silence_at": 260343,
# "mtime": 371900000,
# },
# {
# "path": "testdata/mom.mp3",
# "title": "Man of Mystery",
# "artist": "The Shadows",
# "duration": 120000,
# "start_gap": 70,
# "fade_at": 115000,
# "silence_at": 118000,
# "mtime": 1642760000,
# },
# ]
note_text = "my note"
playlist_name = "test_save_and_restore playlist"
# for track in tracks:
# db_track = models.Tracks(session=session, **track)
# session.add(db_track)
with db.Session() as session:
playlist = Playlists(session, playlist_name)
model = playlistmodel.PlaylistModel(playlist.id)
# session.commit()
# Add a track with a note
model.insert_row(proposed_row_number=0, track_id=self.tracks[1]['id'], note=note_text)
# We need to commit the session before re-querying
session.commit()
# Retrieve playlist
all_playlists = Playlists.get_all(session)
assert len(all_playlists) == 1
retrieved_playlist = all_playlists[0]
assert len(retrieved_playlist.rows) == 1
paths = [a.track.path for a in retrieved_playlist.rows]
assert self.tracks[1]['path'] in paths
notes = [a.note for a in retrieved_playlist.rows]
assert note_text in notes
# def test_save_and_restore(qtbot, session):
# """Playlist with one track, one note, save and restore"""
@with_updown
def test_utilities(self):
"""Test check_db utility"""
# # Create playlist
# playlist = models.Playlists(session, "my playlist")
# playlist_tab = playlists.PlaylistTab(None, session, playlist.id)
from config import Config
# # Insert a note
# note_text = "my note"
# note_row = 7
# note = models.Notes(session, playlist.id, note_row, note_text)
# playlist_tab._insert_note(session, note)
# # Add a track
# track_path = "/a/b/c"
# track = models.Tracks(session, track_path)
# # Inserting the track will also save the playlist
# playlist_tab.insert_track(session, track)
# # We need to commit the session before re-querying
# session.commit()
# # Retrieve playlist
# all_playlists = playlists.Playlists.get_open(session)
# assert len(all_playlists) == 1
# retrieved_playlist = all_playlists[0]
# paths = [a.path for a in retrieved_playlist.tracks.values()]
# assert track_path in paths
# notes = [a.note for a in retrieved_playlist.notes]
# assert note_text in notes
Config.ROOT = os.path.join(os.path.dirname(__file__), 'testdata')
with db.Session() as session:
utilities.check_db(session)
utilities.update_bitrates(session)
# def test_meta_all_clear(qtbot, session):
# # Create playlist