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


Python thumbnails.ThumbnailsPlugin类代码示例

本文整理汇总了Python中beetsplug.thumbnails.ThumbnailsPlugin的典型用法代码示例。如果您正苦于以下问题:Python ThumbnailsPlugin类的具体用法?Python ThumbnailsPlugin怎么用?Python ThumbnailsPlugin使用的例子?那么恭喜您, 这里精选的类代码示例或许可以为您提供帮助。


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

示例1: test_add_tags

    def test_add_tags(self, mock_stat, _):
        plugin = ThumbnailsPlugin()
        plugin.write_metadata = Mock()
        plugin.get_uri = Mock(side_effect={b"/path/to/cover": "COVER_URI"}.__getitem__)
        album = Mock(artpath=b"/path/to/cover")
        mock_stat.return_value.st_mtime = 12345

        plugin.add_tags(album, b"/path/to/thumbnail")

        metadata = {"Thumb::URI": b"COVER_URI", "Thumb::MTime": "12345"}
        plugin.write_metadata.assert_called_once_with(b"/path/to/thumbnail", metadata)
        mock_stat.assert_called_once_with(album.artpath)
开发者ID:opatel99,项目名称:beets,代码行数:12,代码来源:test_thumbnails.py

示例2: test_invokations

    def test_invokations(self, mock_decargs, _):
        plugin = ThumbnailsPlugin()
        plugin.process_album = Mock()
        album = Mock()

        plugin.process_album.reset_mock()
        lib = Mock()
        album2 = Mock()
        lib.albums.return_value = [album, album2]
        plugin.process_query(lib, Mock(), None)
        lib.albums.assert_called_once_with(mock_decargs.return_value)
        plugin.process_album.has_calls([call(album), call(album2)], any_order=True)
开发者ID:opatel99,项目名称:beets,代码行数:12,代码来源:test_thumbnails.py

示例3: test_make_dolphin_cover_thumbnail

    def test_make_dolphin_cover_thumbnail(self, _):
        plugin = ThumbnailsPlugin()
        tmp = mkdtemp()
        album = Mock(path=tmp, artpath=os.path.join(tmp, b"cover.jpg"))
        plugin.make_dolphin_cover_thumbnail(album)
        with open(os.path.join(tmp, b".directory"), "rb") as f:
            self.assertEqual(f.read().splitlines(), [b"[Desktop Entry]", b"Icon=./cover.jpg"])

        # not rewritten when it already exists (yup that's a big limitation)
        album.artpath = b"/my/awesome/art.tiff"
        plugin.make_dolphin_cover_thumbnail(album)
        with open(os.path.join(tmp, b".directory"), "rb") as f:
            self.assertEqual(f.read().splitlines(), [b"[Desktop Entry]", b"Icon=./cover.jpg"])

        rmtree(tmp)
开发者ID:opatel99,项目名称:beets,代码行数:15,代码来源:test_thumbnails.py

示例4: test_check_local_ok

    def test_check_local_ok(self, mock_giouri, mock_pil, mock_im,
                            mock_artresizer, mock_os):
        # test local resizing capability
        mock_artresizer.shared.local = False
        plugin = ThumbnailsPlugin()
        self.assertFalse(plugin._check_local_ok())

        # test dirs creation
        mock_artresizer.shared.local = True

        def exists(path):
            if path == NORMAL_DIR:
                return False
            if path == LARGE_DIR:
                return True
            raise ValueError(u"unexpected path {0!r}".format(path))
        mock_os.path.exists = exists
        plugin = ThumbnailsPlugin()
        mock_os.makedirs.assert_called_once_with(NORMAL_DIR)
        self.assertTrue(plugin._check_local_ok())

        # test metadata writer function
        mock_os.path.exists = lambda _: True
        mock_pil.return_value = False
        mock_im.return_value = False
        with self.assertRaises(AssertionError):
            ThumbnailsPlugin()

        mock_pil.return_value = True
        self.assertEqual(ThumbnailsPlugin().write_metadata, write_metadata_pil)

        mock_im.return_value = True
        self.assertEqual(ThumbnailsPlugin().write_metadata, write_metadata_im)

        mock_pil.return_value = False
        self.assertEqual(ThumbnailsPlugin().write_metadata, write_metadata_im)

        self.assertTrue(ThumbnailsPlugin()._check_local_ok())

        # test URI getter function
        giouri_inst = mock_giouri.return_value
        giouri_inst.available = True
        self.assertEqual(ThumbnailsPlugin().get_uri, giouri_inst.uri)

        giouri_inst.available = False
        self.assertEqual(ThumbnailsPlugin().get_uri.__self__.__class__,
                         PathlibURI)
开发者ID:bryan-snyder,项目名称:beets,代码行数:47,代码来源:test_thumbnails.py

示例5: test_thumbnail_file_name

 def test_thumbnail_file_name(self, mock_basedir):
     plug = ThumbnailsPlugin()
     plug.get_uri = Mock(return_value="file:///my/uri")
     self.assertEqual(plug.thumbnail_file_name("idontcare"),
                      b"9488f5797fbe12ffb316d607dfd93d04.png")
开发者ID:15502119602,项目名称:beets,代码行数:5,代码来源:test_thumbnails.py

示例6: test_process_album

    def test_process_album(self, mock_artresizer, _):
        get_size = mock_artresizer.shared.get_size

        plugin = ThumbnailsPlugin()
        make_cover = plugin.make_cover_thumbnail = Mock(return_value=True)
        make_dolphin = plugin.make_dolphin_cover_thumbnail = Mock()

        # no art
        album = Mock(artpath=None)
        plugin.process_album(album)
        self.assertEqual(get_size.call_count, 0)
        self.assertEqual(make_dolphin.call_count, 0)

        # cannot get art size
        album.artpath = b"/path/to/art"
        get_size.return_value = None
        plugin.process_album(album)
        get_size.assert_called_once_with(b"/path/to/art")
        self.assertEqual(make_cover.call_count, 0)

        # dolphin tests
        plugin.config['dolphin'] = False
        plugin.process_album(album)
        self.assertEqual(make_dolphin.call_count, 0)

        plugin.config['dolphin'] = True
        plugin.process_album(album)
        make_dolphin.assert_called_once_with(album)

        # small art
        get_size.return_value = 200, 200
        plugin.process_album(album)
        make_cover.assert_called_once_with(album, 128, NORMAL_DIR)

        # big art
        make_cover.reset_mock()
        get_size.return_value = 500, 500
        plugin.process_album(album)
        make_cover.has_calls([call(album, 128, NORMAL_DIR),
                              call(album, 256, LARGE_DIR)], any_order=True)
开发者ID:15502119602,项目名称:beets,代码行数:40,代码来源:test_thumbnails.py

示例7: test_make_cover_thumbnail

    def test_make_cover_thumbnail(self, mock_shutils, mock_os, mock_util,
                                  mock_artresizer, _):
        mock_os.path.join = os.path.join  # don't mock that function
        plugin = ThumbnailsPlugin()
        plugin.add_tags = Mock()

        album = Mock(artpath=b"/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 == b"/thumbnail/dir/md5":
                return Mock(st_mtime=1)
            elif target == b"/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, b"/thumbnail/dir")

        mock_os.path.exists.assert_called_once_with(b"/thumbnail/dir/md5")
        mock_os.stat.has_calls([call(b"/thumbnail/dir/md5"),
                                call(b"/path/to/art")], any_order=True)

        resize = mock_artresizer.shared.resize
        resize.assert_called_once_with(12345, b"/path/to/art",
                                       b"/thumbnail/dir/md5")
        plugin.add_tags.assert_called_once_with(album, resize.return_value)
        mock_shutils.move.assert_called_once_with(resize.return_value,
                                                  b"/thumbnail/dir/md5")

        # 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 == b"/thumbnail/dir/md5":
                return Mock(st_mtime=3)
            elif target == b"/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, b"/thumbnail/dir")
        self.assertEqual(resize.call_count, 0)

        # and with force
        plugin.config['force'] = True
        plugin.make_cover_thumbnail(album, 12345, b"/thumbnail/dir")
        resize.assert_called_once_with(12345, b"/path/to/art",
                                       b"/thumbnail/dir/md5")
开发者ID:15502119602,项目名称:beets,代码行数:55,代码来源:test_thumbnails.py


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