Drop PluginManager._api_versions, use picard.api_versions_tuple instead

- modify PluginManager._compatible_api_versions()
- add matching tests
This commit is contained in:
Laurent Monin
2019-04-04 18:01:16 +02:00
parent 45a6b20b85
commit 689fcdcc48
2 changed files with 63 additions and 2 deletions

View File

@@ -267,7 +267,6 @@ class PluginManager(QtCore.QObject):
def __init__(self):
super().__init__()
self.plugins = []
self._api_versions = set([version_from_string(v) for v in picard.api_versions])
self._available_plugins = None # None=never loaded, [] = empty
@property
@@ -384,7 +383,7 @@ class PluginManager(QtCore.QObject):
def _compatible_api_versions(self, api_versions):
versions = [version_from_string(v) for v in list(api_versions)]
return set(versions) & self._api_versions
return set(versions) & set(picard.api_versions_tuple)
def _get_existing_paths(self, plugin_name):
dirpath = os.path.join(USER_PLUGIN_DIR, plugin_name)

62
test/test_plugins.py Normal file
View File

@@ -0,0 +1,62 @@
# -*- coding: utf-8 -*-
#
# Picard, the next-generation MusicBrainz tagger
# Copyright (C) 2019 Laurent Monin
#
# This program is free software; you can redistribute it and/or
# modify it under the terms of the GNU General Public License
# as published by the Free Software Foundation; either version 2
# of the License, or (at your option) any later version.
#
# This program is distributed in the hope that it will be useful,
# but WITHOUT ANY WARRANTY; without even the implied warranty of
# MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
# GNU General Public License for more details.
#
# You should have received a copy of the GNU General Public License
# along with this program; if not, write to the Free Software
# Foundation, Inc., 51 Franklin Street, Fifth Floor, Boston, MA 02110-1301, USA.
import logging
from test.picardtestcase import PicardTestCase
import picard
from picard import (
VersionError,
version_from_string,
)
from picard.plugin import PluginManager
class TestPicardPluginsCommon(PicardTestCase):
def setUp(self):
super().setUp()
logging.disable(logging.ERROR)
def tearDown(self):
pass
class TestPicardPluginManager(TestPicardPluginsCommon):
def test_compatible_api_version(self):
pm = PluginManager()
# use first element from picard.api_versions, it should be compatible
api_versions = picard.api_versions[:1]
expected = set([version_from_string(v) for v in api_versions])
result = pm._compatible_api_versions(api_versions)
self.assertEqual(result, expected)
# pretty sure 0.0 isn't compatible
api_versions = ["0.0"]
expected = set()
result = pm._compatible_api_versions(api_versions)
self.assertEqual(result, expected)
# buggy version
api_versions = ["0.a"]
with self.assertRaises(VersionError):
result = pm._compatible_api_versions(api_versions)