Exemplo n.º 1
0
    def test_get_post_0330(self, mocked_get_version):
        """Test to get media player for version of mpv newer than 0.33.0
        """
        mocked_get_version.return_value = Version("0.33.0")

        self.assertIs(MediaPlayerMpv.get_class_from_version(),
                      MediaPlayerMpvPost0330)
Exemplo n.º 2
0
    def test_get_old(self, mocked_get_version):
        """Test to get media player for old version of mpv
        """
        mocked_get_version.return_value = Version("0.27.0")

        self.assertIs(MediaPlayerMpv.get_class_from_version(),
                      MediaPlayerMpvOld)
Exemplo n.º 3
0
    def get_instance(self, config=None, check_error=True):
        """Get an instance of MediaPlayerMpv for the available version

        This method is a context manager that automatically stops the player on
        exit.

        Args:
            config (dict): Configuration passed to the constructor.
            check_error (bool): If true, check if the player stop event is not
                set and the error queue is empty at the end.

        Yields:
            tuple: Containing the following elements:
                MediaPlayerMpv: Instance;
                path.Path: Path of the temporary directory;
                unittest.case._LoggingWatcher: Captured output.
                """
        if not config:
            config = {
                "kara_folder": self.kara_folder,
                "fullscreen": self.fullscreen,
                "mpv": {
                    "vo": "null",
                    "ao": "null"
                },
            }

        with TempDir() as temp:
            try:
                with ExitStack() as stack:
                    mpv_player = stack.enter_context(
                        MediaPlayerMpv.from_version(Event(),
                                                    Queue(),
                                                    config,
                                                    temp,
                                                    warn_long_exit=False))
                    output = stack.enter_context(
                        self.assertLogs("dakara_player.media_player.mpv",
                                        "DEBUG"))
                    mpv_player.load()

                    yield mpv_player, temp, output

                    if check_error:
                        # display errors in queue if any
                        if not mpv_player.errors.empty():
                            _, error, traceback = mpv_player.errors.get(5)
                            error.with_traceback(traceback)
                            raise error

                        # assert no errors to fail test if any
                        self.assertFalse(mpv_player.stop.is_set())

            except OSError:
                # silence closing errors of mpv
                pass

            # sleep to allow slow systems to correctly clean up
            sleep(self.DELAY)
Exemplo n.º 4
0
    def test_instanciate(self, mocked_get_class_from_version):
        """Test to instanciate media player mpv class
        """
        class Dummy:
            def __init__(self, *args, **kwargs):
                self.args = args
                self.kwargs = kwargs

        mocked_get_class_from_version.return_value = Dummy

        instance = MediaPlayerMpv.from_version(1, 2, v3=3, v4=4)
        self.assertIsInstance(instance, Dummy)
        self.assertEqual(instance.args, (1, 2))
        self.assertEqual(instance.kwargs, {"v3": 3, "v4": 4})
Exemplo n.º 5
0
 def test_is_available_ng(self, mocked_mpv_class):
     """Test to get inavailability
     """
     mocked_mpv_class.side_effect = FileNotFoundError()
     self.assertFalse(MediaPlayerMpv.is_available())
Exemplo n.º 6
0
 def test_is_available_ng_no_module(self):
     """Test to get inavailability if mpv module cannot be loaded
     """
     self.assertFalse(MediaPlayerMpv.is_available())
Exemplo n.º 7
0
 def test_is_available_ok_indirect(self, mocked_mpv_class):
     """Test to get availability indirectly
     """
     mocked_mpv_class.side_effect = [FileNotFoundError(), MagicMock()]
     self.assertTrue(MediaPlayerMpv.is_available())
Exemplo n.º 8
0
 def test_is_available_ok_direct(self, mocked_mpv_class):
     """Test to get availability directly
     """
     self.assertTrue(MediaPlayerMpv.is_available())
Exemplo n.º 9
0
from unittest.mock import MagicMock

from func_timeout import func_set_timeout
from path import TempDir

from dakara_player.media_player.mpv import MediaPlayerMpv
from dakara_player.media_player.base import (
    IDLE_BG_NAME,
    IDLE_TEXT_NAME,
    TRANSITION_BG_NAME,
    TRANSITION_TEXT_NAME,
)
from tests.integration.base import TestCasePollerKara


@skipUnless(MediaPlayerMpv.is_available(), "mpv not installed")
class MediaPlayerMpvIntegrationTestCase(TestCasePollerKara):
    """Test the mpv player class in real conditions
    """

    TIMEOUT = 30
    DELAY = 0.2

    def setUp(self):
        super().setUp()

        # create fullscreen flag
        self.fullscreen = True

        # create transition duration
        self.transition_duration = 1