plugin.video.viervijfzes/tests/xbmcaddon.py

77 lines
3.3 KiB
Python
Raw Normal View History

2020-03-19 16:45:31 +01:00
# -*- coding: utf-8 -*-
# Copyright: (c) 2019, Dag Wieers (@dagwieers) <dag@wieers.com>
# GNU General Public License v3.0 (see COPYING or https://www.gnu.org/licenses/gpl-3.0.txt)
2020-03-20 13:32:55 +01:00
"""This file implements the Kodi xbmcaddon module, either using stubs or alternative functionality"""
2020-03-19 16:45:31 +01:00
# pylint: disable=invalid-name
from __future__ import absolute_import, division, print_function, unicode_literals
from xbmc import getLocalizedString
2020-03-20 13:32:55 +01:00
from xbmcextra import ADDON_ID, ADDON_INFO, addon_settings
2020-03-19 16:45:31 +01:00
2020-03-20 13:32:55 +01:00
# Ensure the addon settings are retained (as we don't write to disk)
ADDON_SETTINGS = addon_settings(ADDON_ID)
2020-03-19 16:45:31 +01:00
class Addon:
2020-03-20 13:32:55 +01:00
"""A reimplementation of the xbmcaddon Addon class"""
2020-03-19 16:45:31 +01:00
def __init__(self, id=ADDON_ID): # pylint: disable=redefined-builtin
2020-03-20 13:32:55 +01:00
"""A stub constructor for the xbmcaddon Addon class"""
2020-03-19 16:45:31 +01:00
self.id = id
2020-03-20 13:32:55 +01:00
if id == ADDON_ID:
self.settings = ADDON_SETTINGS
else:
self.settings = addon_settings(id)
2020-03-19 16:45:31 +01:00
def getAddonInfo(self, key):
2020-03-20 13:32:55 +01:00
"""A working implementation for the xbmcaddon Addon class getAddonInfo() method"""
2020-03-19 16:45:31 +01:00
stub_info = dict(id=self.id, name=self.id, version='2.3.4', type='kodi.inputstream', profile='special://userdata', path='special://userdata')
# Add stub_info values to ADDON_INFO when missing (e.g. path and profile)
addon_info = dict(stub_info, **ADDON_INFO)
return addon_info.get(self.id, stub_info).get(key)
@staticmethod
def getLocalizedString(msgctxt):
2020-03-20 13:32:55 +01:00
"""A working implementation for the xbmcaddon Addon class getLocalizedString() method"""
2020-03-19 16:45:31 +01:00
return getLocalizedString(msgctxt)
def getSetting(self, key):
2020-03-20 13:32:55 +01:00
"""A working implementation for the xbmcaddon Addon class getSetting() method"""
return self.settings.get(key, '')
def getSettingBool(self, key):
"""A working implementation for the xbmcaddon Addon class getSettingBool() method"""
return bool(self.settings.get(key, False))
def getSettingInt(self, key):
"""A working implementation for the xbmcaddon Addon class getSettingInt() method"""
return int(self.settings.get(key, 0))
def getSettingNumber(self, key):
"""A working implementation for the xbmcaddon Addon class getSettingNumber() method"""
return float(self.settings.get(key, 0.0))
2020-03-19 16:45:31 +01:00
@staticmethod
def openSettings():
2020-03-20 13:32:55 +01:00
"""A stub implementation for the xbmcaddon Addon class openSettings() method"""
2020-03-19 16:45:31 +01:00
def setSetting(self, key, value):
2020-03-20 13:32:55 +01:00
"""A stub implementation for the xbmcaddon Addon class setSetting() method"""
self.settings[key] = value
2020-03-19 16:45:31 +01:00
# NOTE: Disable actual writing as it is no longer needed for testing
# with open('tests/userdata/addon_settings.json', 'w') as fd:
2020-03-19 16:45:31 +01:00
# json.dump(filtered_settings, fd, sort_keys=True, indent=4)
2020-03-20 13:32:55 +01:00
def setSettingBool(self, key, value):
"""A stub implementation for the xbmcaddon Addon class setSettingBool() method"""
self.settings[key] = value
def setSettingInt(self, key, value):
"""A stub implementation for the xbmcaddon Addon class setSettingInt() method"""
self.settings[key] = value
def setSettingNumber(self, key, value):
"""A stub implementation for the xbmcaddon Addon class setSettingNumber() method"""
self.settings[key] = value