From d85635148f466d4eef89f2e20e9e8960d830bcdd Mon Sep 17 00:00:00 2001 From: MoojMidge <56883549+MoojMidge@users.noreply.github.com> Date: Mon, 8 Aug 2022 01:11:40 +1000 Subject: [PATCH] Fix CI workflow git clone needs https url Update actions Disable pylint consider-using-f-string to maintain python2 compatibilty Use dict literal Fix unspecified-encoding pylint complaints Also update xbmcvfs.File test stub --- .github/workflows/ci.yml | 4 ++-- .pylintrc | 1 + requirements.txt | 2 +- resources/lib/api.py | 2 +- tests/xbmcaddon.py | 2 +- tests/xbmcextra.py | 5 +++-- tests/xbmcvfs.py | 47 ++++++++++++++++++++++++++++++++++++++-- 7 files changed, 54 insertions(+), 9 deletions(-) diff --git a/.github/workflows/ci.yml b/.github/workflows/ci.yml index d4e658dc..30db6a91 100644 --- a/.github/workflows/ci.yml +++ b/.github/workflows/ci.yml @@ -17,7 +17,7 @@ jobs: - name: Check out ${{ github.sha }} from repository ${{ github.repository }} uses: actions/checkout@v2 - name: Set up Python ${{ matrix.python-version }} - uses: actions/setup-python@v1 + uses: actions/setup-python@v2 with: python-version: ${{ matrix.python-version }} - name: Install dependencies @@ -45,7 +45,7 @@ jobs: run: coverage run -a resources/lib/service_entry.py & if: always() - name: Upload code coverage to CodeCov - uses: codecov/codecov-action@v1 + uses: codecov/codecov-action@v3 continue-on-error: true - name: Analyze with SonarCloud uses: SonarSource/sonarcloud-github-action@v1.4 diff --git a/.pylintrc b/.pylintrc index 25dbc91f..4c4917f5 100644 --- a/.pylintrc +++ b/.pylintrc @@ -16,3 +16,4 @@ disable= too-many-return-statements, too-many-statements, useless-super-delegation, + consider-using-f-string, diff --git a/requirements.txt b/requirements.txt index c0e9a9fd..c99336e7 100644 --- a/requirements.txt +++ b/requirements.txt @@ -1,4 +1,4 @@ -git+git://github.com/ruuk/script.module.addon.signals.git@master#egg=AddonSignals +git+https://github.com/ruuk/script.module.addon.signals.git@master#egg=AddonSignals codecov kodi-addon-checker; python_version >= '3.5' polib diff --git a/resources/lib/api.py b/resources/lib/api.py index 1f7adde7..5e2b0ff2 100644 --- a/resources/lib/api.py +++ b/resources/lib/api.py @@ -209,7 +209,7 @@ def notification_time(self, total_time=None): def get_now_playing(self): # Seems to work too fast loop whilst waiting for it to become active - result = dict() + result = {} while not result.get('result'): result = jsonrpc(method='Player.GetActivePlayers') self.log('Got active player %s' % result, 2) diff --git a/tests/xbmcaddon.py b/tests/xbmcaddon.py index 6ea2a7e4..7b914e9d 100644 --- a/tests/xbmcaddon.py +++ b/tests/xbmcaddon.py @@ -44,7 +44,7 @@ def openSettings(): def setSetting(self, key, value): ''' A stub implementation for the xbmcaddon Addon class setSetting() method ''' if not ADDON_SETTINGS.get(self.id): - ADDON_SETTINGS[self.id] = dict() + ADDON_SETTINGS[self.id] = {} ADDON_SETTINGS[self.id][key] = value # NOTE: Disable actual writing as it is no longer needed for testing # with open('tests/userdata/addon_settings.json', 'w') as fd: diff --git a/tests/xbmcextra.py b/tests/xbmcextra.py index 9ff0dd1d..fd89ee83 100644 --- a/tests/xbmcextra.py +++ b/tests/xbmcextra.py @@ -6,6 +6,7 @@ # pylint: disable=invalid-name from __future__ import absolute_import, division, print_function, unicode_literals +import io import os import xml.etree.ElementTree as ET import polib @@ -74,7 +75,7 @@ def global_settings(): ''' Use the global_settings file ''' import json try: - with open('tests/userdata/global_settings.json') as f: + with io.open('tests/userdata/global_settings.json', mode='r', encoding='utf-8') as f: settings = json.load(f) except OSError as e: print("Error: Cannot use 'tests/userdata/global_settings.json' : %s" % e) @@ -104,7 +105,7 @@ def addon_settings(): ''' Use the addon_settings file ''' import json try: - with open('tests/userdata/addon_settings.json') as f: + with io.open('tests/userdata/addon_settings.json', mode='r', encoding='utf-8') as f: settings = json.load(f) except OSError as e: print("Error: Cannot use 'tests/userdata/addon_settings.json' : %s" % e) diff --git a/tests/xbmcvfs.py b/tests/xbmcvfs.py index 8b38b2d9..09f837ad 100644 --- a/tests/xbmcvfs.py +++ b/tests/xbmcvfs.py @@ -6,12 +6,55 @@ # pylint: disable=invalid-name from __future__ import absolute_import, division, print_function, unicode_literals +import io import os -def File(path, flags='r'): +class File: ''' A reimplementation of the xbmcvfs File() function ''' - return open(path, flags) # pylint: disable=consider-using-with + def __init__(self, path, mode=None): + if mode == 'w': + mode = 'r+b' + else: + mode = 'rb' + + self._file = io.open(path, mode=mode, encoding='utf-8') # pylint: disable=consider-using-with + + def __enter__(self): + return self + + def __exit__(self, exc_type, exc_value, traceback): + self._file.close() + + def close(self): + self._file.close() + + def read(self, numbytes=None): + bytestring = self._file.read(numbytes) + return bytestring.decode('utf-8', 'ignore') + + def readBytes(self, numbytes=None): + return self._file.read(numbytes) + + def seek(self, seekBytes, iWhence=os.SEEK_SET): + return self._file.seek(seekBytes, iWhence) + + def size(self): + current_position = self.tell() + self.seek(0, os.SEEK_END) + size = self.tell() + self.seek(current_position) + return size + + def tell(self): + return self._file.tell() + + def write(self, data): + try: + self._file.write(data) + return True + except (IOError, OSError, TypeError, ValueError): + return False def Stat(path):