emmental/tests/playlist/test_factory.py

64 lines
2.5 KiB
Python

# Copyright 2023 (c) Anna Schumaker.
"""Test our Playlist Manager object."""
import io
import unittest.mock
import emmental.playlist
import tests.util
from gi.repository import GObject
@unittest.mock.patch("sys.stdout", new_callable=io.StringIO)
class TestFactory(tests.util.TestCase):
"""Test the Playlist Factory class."""
def setUp(self):
"""Set up common variables."""
super().setUp()
self.sql.playlists.load(now=True)
self.user_plist = self.sql.playlists.create("User Playlist")
self.factory = emmental.playlist.Factory(self.sql)
def test_init(self, mock_stdout: io.StringIO):
"""Check that the Playlist Factory is set up properly."""
self.assertIsInstance(self.factory, GObject.GObject)
self.assertEqual(self.factory.sql, self.sql)
def test_active(self, mock_stdout: io.StringIO):
"""Test the active playlist property."""
self.assertIsNone(self.factory.db_active)
self.sql.set_active_playlist(self.user_plist)
self.assertEqual(self.factory.db_active, self.user_plist)
self.assertRegex(mock_stdout.getvalue(),
"factory: active playlist is: User Playlist")
self.sql.set_active_playlist(None)
self.assertIsNone(self.factory.db_active)
self.assertRegex(mock_stdout.getvalue(), "active playlist is: <None>")
def test_previous(self, mock_stdout: io.StringIO):
"""Test the previous playlist property."""
self.assertIsNone(self.factory.db_previous)
self.factory.db_previous = self.sql.playlists.previous
self.assertEqual(self.factory.db_previous, self.sql.playlists.previous)
self.assertRegex(mock_stdout.getvalue(),
r"factory: previous playlist is: Previous Tracks")
self.factory.db_previous = None
self.assertRegex(mock_stdout.getvalue(),
"factory: previous playlist is: <None>")
def test_visible(self, mock_stdout: io.StringIO):
"""Test the visible playlist property."""
self.assertIsNone(self.factory.db_visible)
self.factory.db_visible = self.user_plist
self.assertEqual(self.factory.db_visible, self.user_plist)
self.assertRegex(mock_stdout.getvalue(),
"factory: visible playlist is: User Playlist")
self.factory.db_visible = None
self.assertRegex(mock_stdout.getvalue(),
"factory: visible playlist is: <None>")