PMGR: Finalize extraction of is_os_compatible into octoprint.util.platform
This commit is contained in:
1 parent
66b501cfaa
commit
62120affae
3 files changed
+26
-68
No files matched your search
@@ -875,30 +875,6 @@ class PluginManagerPlugin(octoprint.plugin.SimpleApiPlugin,
|
||||
self._notices = notices
|
||||
return True
|
||||
|
||||
@staticmethod
|
||||
def _is_os_compatible(current_os, compatibility_entries):
|
||||
"""
|
||||
Tests if the ``current_os`` or ``sys.platform`` are blacklisted or whitelisted in ``compatibility_entries``
|
||||
"""
|
||||
if len(compatibility_entries) == 0:
|
||||
# shortcut - no compatibility info means we are compatible
|
||||
return True
|
||||
|
||||
negative_entries = map(lambda x: x[1:], filter(lambda x: x.startswith("!"), compatibility_entries))
|
||||
positive_entries = filter(lambda x: not x.startswith("!"), compatibility_entries)
|
||||
|
||||
negative_match = False
|
||||
if negative_entries:
|
||||
# check if we are blacklisted
|
||||
negative_match = current_os in negative_entries or any(map(lambda x: sys.platform.startswith(x), negative_entries))
|
||||
|
||||
positive_match = True
|
||||
if positive_entries:
|
||||
# check if we are whitelisted
|
||||
positive_match = current_os in positive_entries or any(map(lambda x: sys.platform.startswith(x), positive_entries))
|
||||
|
||||
return positive_match and not negative_match
|
||||
|
||||
@property
|
||||
def _reconnect_hooks(self):
|
||||
reconnect_hooks = self.__class__.RECONNECT_HOOKS
|
||||
|
||||
@@ -1,44 +0,0 @@
|
||||
# coding=utf-8
|
||||
"""
|
||||
Unit tests for bundled plugin "PluginManager".
|
||||
"""
|
||||
|
||||
from __future__ import absolute_import
|
||||
|
||||
__author__ = "Gina Häußge <osd@foosel.net>"
|
||||
__license__ = 'GNU Affero General Public License http://www.gnu.org/licenses/agpl.html'
|
||||
__copyright__ = "Copyright (C) 2017 The OctoPrint Project - Released under terms of the AGPLv3 License"
|
||||
|
||||
import unittest
|
||||
import mock
|
||||
import ddt
|
||||
|
||||
from octoprint.plugins.pluginmanager import PluginManagerPlugin
|
||||
|
||||
@ddt.ddt
|
||||
class PluginManagerPluginTests(unittest.TestCase):
|
||||
|
||||
@ddt.data(
|
||||
("linux", "linux2", [], True),
|
||||
("linux", "linux2", ["linux", "freebsd"], True),
|
||||
("windows", "win32", ["linux", "freebsd"], False),
|
||||
("linux", "linux2", ["!windows"], True),
|
||||
("windows", "win32", ["!windows"], False),
|
||||
("unmapped", "os2", [], True),
|
||||
("unmapped", "os2", ["linux", "freebsd"], False),
|
||||
("unmapped", "os2", ["!os2"], False),
|
||||
("unmapped", "sunos5", ["linux", "freebsd", "sunos"], True),
|
||||
("unmapped", "sunos5", ["!sunos", "!os2"], False),
|
||||
|
||||
# both black and white listing at the same time usually doesn't
|
||||
# make a whole lot of sense, but let's test it anyhow
|
||||
("linux", "linux2", ["!windows", "linux", "freebsd"], True),
|
||||
("linux", "linux2", ["!windows", "freebsd"], False),
|
||||
("windows", "win32", ["!windows", "linux", "freebsd"], False),
|
||||
("unmapped", "sunos5", ["!windows", "linux", "freebsd"], False)
|
||||
)
|
||||
@ddt.unpack
|
||||
def test_is_os_compatible(self, current_os, sys_platform, entries, expected):
|
||||
with mock.patch("sys.platform", sys_platform):
|
||||
actual = PluginManagerPlugin._is_os_compatible(current_os, entries)
|
||||
self.assertEqual(actual, expected)
|
||||
@@ -28,3 +28,29 @@ class PlatformUtilTest(unittest.TestCase):
|
||||
from octoprint.util.platform import get_os
|
||||
actual = get_os()
|
||||
self.assertEqual(actual, expected)
|
||||
|
||||
@ddt.data(
|
||||
("linux", "linux2", [], True),
|
||||
("linux", "linux2", ["linux", "freebsd"], True),
|
||||
("windows", "win32", ["linux", "freebsd"], False),
|
||||
("linux", "linux2", ["!windows"], True),
|
||||
("windows", "win32", ["!windows"], False),
|
||||
("unmapped", "os2", [], True),
|
||||
("unmapped", "os2", ["linux", "freebsd"], False),
|
||||
("unmapped", "os2", ["!os2"], False),
|
||||
("unmapped", "sunos5", ["linux", "freebsd", "sunos"], True),
|
||||
("unmapped", "sunos5", ["!sunos", "!os2"], False),
|
||||
|
||||
# both black and white listing at the same time usually doesn't
|
||||
# make a whole lot of sense, but let's test it anyhow
|
||||
("linux", "linux2", ["!windows", "linux", "freebsd"], True),
|
||||
("linux", "linux2", ["!windows", "freebsd"], False),
|
||||
("windows", "win32", ["!windows", "linux", "freebsd"], False),
|
||||
("unmapped", "sunos5", ["!windows", "linux", "freebsd"], False)
|
||||
)
|
||||
@ddt.unpack
|
||||
def test_is_os_compatible(self, current_os, sys_platform, entries, expected):
|
||||
with mock.patch("sys.platform", sys_platform):
|
||||
from octoprint.util.platform import is_os_compatible
|
||||
actual = is_os_compatible(entries, current_os=current_os)
|
||||
self.assertEqual(actual, expected)
|
||||
Reference in new issue
Block a user