From 9bf1ab29a88ad0ac298c8678eadfe7eccf97a125 Mon Sep 17 00:00:00 2001 From: Keith Edmunds Date: Sun, 9 Mar 2025 16:41:28 +0000 Subject: [PATCH] Fixup tests after data() return type fixups --- tests/test_models.py | 34 +++++++++++++++++++++++++++++----- tests/test_playlistmodel.py | 14 +++++++------- 2 files changed, 36 insertions(+), 12 deletions(-) diff --git a/tests/test_models.py b/tests/test_models.py index 20deaee..2893aad 100644 --- a/tests/test_models.py +++ b/tests/test_models.py @@ -21,7 +21,9 @@ from app.models import ( class TestMMModels(unittest.TestCase): def setUp(self): + """Runs before each test""" db.create_all() + NoteColours.invalidate_cache() with db.Session() as session: track1_path = "testdata/isa.mp3" @@ -31,6 +33,7 @@ class TestMMModels(unittest.TestCase): self.track2 = Tracks(session, **helpers.get_all_track_metadata(track2_path)) def tearDown(self): + """Runs after each test""" db.drop_all() def test_track_repr(self): @@ -70,7 +73,7 @@ class TestMMModels(unittest.TestCase): NoteColours(session, substring="substring", colour=note_colour) result = NoteColours.get_colour(session, "xyz") - assert result is None + assert result == "" def test_notecolours_get_colour_match(self): note_colour = "#4bcdef" @@ -200,7 +203,7 @@ class TestMMModels(unittest.TestCase): nc = NoteColours(session, substring="x", colour="x") _ = str(nc) - def test_get_colour(self): + def test_get_colour_1(self): """Test for errors in execution""" GOOD_STRING = "cantelope" @@ -213,22 +216,42 @@ class TestMMModels(unittest.TestCase): session, substring=SUBSTR, colour=COLOUR, is_casesensitive=True ) + session.commit() _ = nc1.get_colour(session, "") colour = nc1.get_colour(session, GOOD_STRING) assert colour == COLOUR colour = nc1.get_colour(session, BAD_STRING) - assert colour is None + assert colour == "" + def test_get_colour_2(self): + """Test for errors in execution""" + + GOOD_STRING = "cantelope" + BAD_STRING = "ericTheBee" + SUBSTR = "ant" + COLOUR = "blue" + + with db.Session() as session: nc2 = NoteColours( session, substring=".*" + SUBSTR, colour=COLOUR, is_regex=True ) + session.commit() colour = nc2.get_colour(session, GOOD_STRING) assert colour == COLOUR colour = nc2.get_colour(session, BAD_STRING) - assert colour is None + assert colour == "" + def test_get_colour_3(self): + """Test for errors in execution""" + + GOOD_STRING = "cantelope" + BAD_STRING = "ericTheBee" + SUBSTR = "ant" + COLOUR = "blue" + + with db.Session() as session: nc3 = NoteColours( session, substring=".*" + SUBSTR, @@ -236,12 +259,13 @@ class TestMMModels(unittest.TestCase): is_regex=True, is_casesensitive=True, ) + session.commit() colour = nc3.get_colour(session, GOOD_STRING) assert colour == COLOUR colour = nc3.get_colour(session, BAD_STRING) - assert colour is None + assert colour == "" def test_name_available(self): PLAYLIST_NAME = "a name" diff --git a/tests/test_playlistmodel.py b/tests/test_playlistmodel.py index 4791d2c..3590b1a 100644 --- a/tests/test_playlistmodel.py +++ b/tests/test_playlistmodel.py @@ -66,10 +66,10 @@ 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( + qv_value = self.model._display_role( START_ROW, playlistmodel.HEADER_NOTES_COLUMN, prd ) - assert qv_value.value() == "start [1 tracks, 4:23 unplayed]" + assert qv_value == "start [1 tracks, 4:23 unplayed]" class TestMMMiscNoPlaylist(unittest.TestCase): @@ -109,7 +109,7 @@ class TestMMMiscNoPlaylist(unittest.TestCase): _ = str(prd) assert ( - model.edit_role( + model._edit_role( model.rowCount() - 1, playlistmodel.Col.TITLE.value, prd ) == metadata["title"] @@ -262,7 +262,7 @@ class TestMMMiscRowMove(unittest.TestCase): # Test against edit_role because display_role for headers is # handled differently (sets up row span) assert ( - self.model.edit_role( + self.model._edit_role( self.model.rowCount() - 1, playlistmodel.Col.NOTE.value, prd ) == note_text @@ -280,7 +280,7 @@ class TestMMMiscRowMove(unittest.TestCase): # Test against edit_role because display_role for headers is # handled differently (sets up row span) assert ( - self.model.edit_role( + self.model._edit_role( self.model.rowCount() - 1, playlistmodel.Col.NOTE.value, prd ) == note_text @@ -353,7 +353,7 @@ class TestMMMiscRowMove(unittest.TestCase): index = model_dst.index( row_number, playlistmodel.Col.TITLE.value, QModelIndex() ) - row_notes.append(model_dst.data(index, Qt.ItemDataRole.EditRole).value()) + row_notes.append(model_dst.data(index, Qt.ItemDataRole.EditRole)) 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) @@ -380,7 +380,7 @@ class TestMMMiscRowMove(unittest.TestCase): index = model_dst.index( row_number, playlistmodel.Col.TITLE.value, QModelIndex() ) - row_notes.append(model_dst.data(index, Qt.ItemDataRole.EditRole).value()) + row_notes.append(model_dst.data(index, Qt.ItemDataRole.EditRole)) 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)