Example #1
0
    def test_check_template_default(self, mocked_get_environment_loaders):
        """Test to find a default template
        """
        mocked_loader_custom = MagicMock()
        mocked_loader_custom.list_templates.return_value = []
        mocked_loader_default = MagicMock()
        mocked_loader_default.list_templates.return_value = ["idle.ass"]

        mocked_get_environment_loaders.return_value = [
            mocked_loader_custom,
            mocked_loader_default,
        ]

        with self.assertLogs("dakara_player.text_generator",
                             "DEBUG") as logger:
            text_generator = TextGenerator("package",
                                           filenames={"idle": "idle.ass"})
            text_generator.check_template("idle", "idle.ass")

        self.assertListEqual(
            logger.output,
            [
                "DEBUG:dakara_player.text_generator:Loading default idle "
                "text template file 'idle.ass'"
            ],
        )
Example #2
0
    def test_check_template_not_found(self, mocked_get_environment_loaders):
        """Test to find an unaccessible template
        """
        mocked_loader_custom = MagicMock()
        mocked_loader_custom.list_templates.return_value = []
        mocked_loader_default = MagicMock()
        mocked_loader_default.list_templates.return_value = []

        mocked_get_environment_loaders.return_value = [
            mocked_loader_custom,
            mocked_loader_default,
        ]

        with self.assertRaisesRegex(
                TemplateNotFoundError,
                "No idle text template file found for 'idle.ass'"):
            text_generator = TextGenerator("package",
                                           filenames={"idle": "idle.ass"})
            text_generator.check_template("idle", "idle.ass")