当前位置: 首页>>代码示例>>Python>>正文


Python ThumbnailsPlugin.config["force"]方法代码示例

本文整理汇总了Python中beetsplug.thumbnails.ThumbnailsPlugin.config["force"]方法的典型用法代码示例。如果您正苦于以下问题:Python ThumbnailsPlugin.config["force"]方法的具体用法?Python ThumbnailsPlugin.config["force"]怎么用?Python ThumbnailsPlugin.config["force"]使用的例子?那么恭喜您, 这里精选的方法代码示例或许可以为您提供帮助。您也可以进一步了解该方法所在beetsplug.thumbnails.ThumbnailsPlugin的用法示例。


在下文中一共展示了ThumbnailsPlugin.config["force"]方法的1个代码示例,这些例子默认根据受欢迎程度排序。您可以为喜欢或者感觉有用的代码点赞,您的评价将有助于系统推荐出更棒的Python代码示例。

示例1: test_make_cover_thumbnail

# 需要导入模块: from beetsplug.thumbnails import ThumbnailsPlugin [as 别名]
# 或者: from beetsplug.thumbnails.ThumbnailsPlugin import config["force"] [as 别名]
    def test_make_cover_thumbnail(self, mock_shutils, mock_os, mock_util, mock_artresizer, _):
        thumbnail_dir = os.path.normpath(b"/thumbnail/dir")
        md5_file = os.path.join(thumbnail_dir, b"md5")
        path_to_art = os.path.normpath(b"/path/to/art")

        mock_os.path.join = os.path.join  # don't mock that function
        plugin = ThumbnailsPlugin()
        plugin.add_tags = Mock()

        album = Mock(artpath=path_to_art)
        mock_util.syspath.side_effect = lambda x: x
        plugin.thumbnail_file_name = Mock(return_value="md5")
        mock_os.path.exists.return_value = False

        def os_stat(target):
            if target == md5_file:
                return Mock(st_mtime=1)
            elif target == path_to_art:
                return Mock(st_mtime=2)
            else:
                raise ValueError("invalid target {0}".format(target))

        mock_os.stat.side_effect = os_stat

        plugin.make_cover_thumbnail(album, 12345, thumbnail_dir)

        mock_os.path.exists.assert_called_once_with(md5_file)
        mock_os.stat.has_calls([call(md5_file), call(path_to_art)], any_order=True)

        resize = mock_artresizer.shared.resize
        resize.assert_called_once_with(12345, path_to_art, md5_file)
        plugin.add_tags.assert_called_once_with(album, resize.return_value)
        mock_shutils.move.assert_called_once_with(resize.return_value, md5_file)

        # now test with recent thumbnail & with force
        mock_os.path.exists.return_value = True
        plugin.force = False
        resize.reset_mock()

        def os_stat(target):
            if target == md5_file:
                return Mock(st_mtime=3)
            elif target == path_to_art:
                return Mock(st_mtime=2)
            else:
                raise ValueError("invalid target {0}".format(target))

        mock_os.stat.side_effect = os_stat

        plugin.make_cover_thumbnail(album, 12345, thumbnail_dir)
        self.assertEqual(resize.call_count, 0)

        # and with force
        plugin.config["force"] = True
        plugin.make_cover_thumbnail(album, 12345, thumbnail_dir)
        resize.assert_called_once_with(12345, path_to_art, md5_file)
开发者ID:opatel99,项目名称:beets,代码行数:58,代码来源:test_thumbnails.py


注:本文中的beetsplug.thumbnails.ThumbnailsPlugin.config["force"]方法示例由纯净天空整理自Github/MSDocs等开源代码及文档管理平台,相关代码片段筛选自各路编程大神贡献的开源项目,源码版权归原作者所有,传播和使用请参考对应项目的License;未经允许,请勿转载。