From c97af2116594a8b372920d614122f9acb4b1bbd9 Mon Sep 17 00:00:00 2001 From: mediaminister <45148099+mediaminister@users.noreply.github.com> Date: Sun, 6 Feb 2022 16:05:09 +0100 Subject: [PATCH] Fix tests (#483) --- .github/workflows/ci.yml | 20 ++++++++++++++------ .pylintrc | 1 + lib/inputstreamhelper/__init__.py | 2 +- lib/inputstreamhelper/utils.py | 2 +- tests/checkchromeos.py | 18 +++++++++++++----- 5 files changed, 30 insertions(+), 13 deletions(-) diff --git a/.github/workflows/ci.yml b/.github/workflows/ci.yml index 44f596d8..2a9e5089 100644 --- a/.github/workflows/ci.yml +++ b/.github/workflows/ci.yml @@ -1,24 +1,32 @@ name: CI on: -- pull_request -- push + # Run action when pushed to master, or for commits in a pull request. + push: + branches: + - master + pull_request: + branches: + - master jobs: tests: name: Add-on testing - runs-on: ubuntu-latest + runs-on: ${{ matrix.os }} env: PYTHONIOENCODING: utf-8 PYTHONPATH: ${{ github.workspace }}/lib:${{ github.workspace }}/tests strategy: fail-fast: false + # Set max-parallel to avoid ConnectionRefusedError from Google servers + max-parallel: 2 matrix: -# max-parallel: 2 - python-version: [ 2.7, 3.5, 3.6, 3.7, 3.8 ] + os: [ ubuntu-latest ] + python-version: [ 2.7, 3.5, 3.6, 3.7, 3.8, 3.9 ] steps: - 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 diff --git a/.pylintrc b/.pylintrc index 2bf4259f..a25d9303 100644 --- a/.pylintrc +++ b/.pylintrc @@ -1,6 +1,7 @@ [MESSAGES CONTROL] disable= bad-option-value, + consider-using-f-string, duplicate-code, # Integration tests tend to test similar things fixme, # Allow FIXMEs in code is a useful practice import-outside-toplevel, # Done on purpose to reduce overhead at startup diff --git a/lib/inputstreamhelper/__init__.py b/lib/inputstreamhelper/__init__.py index c58a6e9e..c5c9e92b 100644 --- a/lib/inputstreamhelper/__init__.py +++ b/lib/inputstreamhelper/__init__.py @@ -9,7 +9,7 @@ from .kodiutils import (addon_version, delete, exists, get_proxies, get_setting, get_setting_bool, get_setting_float, get_setting_int, jsonrpc, kodi_to_ascii, kodi_version, listdir, localize, log, notification, ok_dialog, progress_dialog, select_dialog, set_setting, set_setting_bool, textviewer, translate_path, yesno_dialog) -from .utils import arch, http_download, remove_tree, run_cmd, store, system_os, temp_path, unzip +from .utils import arch, http_download, remove_tree, store, system_os, temp_path, unzip from .widevine.arm import install_widevine_arm from .widevine.widevine import (backup_path, has_widevinecdm, ia_cdm_path, install_cdm_from_backup, latest_available_widevine_from_repo, latest_widevine_version, load_widevine_config, missing_widevine_libs, widevine_config_path, widevine_eula, widevinecdm_path) diff --git a/lib/inputstreamhelper/utils.py b/lib/inputstreamhelper/utils.py index 21a9cf65..0d179750 100644 --- a/lib/inputstreamhelper/utils.py +++ b/lib/inputstreamhelper/utils.py @@ -51,7 +51,7 @@ def _http_request(url, headers=None, time_out=10): req = urlopen(request, timeout=time_out) log(0, 'Response code: {code}', code=req.getcode()) if 400 <= req.getcode() < 600: - raise HTTPError('HTTP %s Error for url: %s' % (req.getcode(), url), response=req) + raise HTTPError('HTTP {} Error for url: {}'.format(req.getcode(), url), response=req) except (HTTPError, URLError) as err: log(2, 'Download failed with error {}'.format(err)) if yesno_dialog(localize(30004), '{line1}\n{line2}'.format(line1=localize(30063), line2=localize(30065))): # Internet down, try again? diff --git a/tests/checkchromeos.py b/tests/checkchromeos.py index ed4a79f8..730ab444 100644 --- a/tests/checkchromeos.py +++ b/tests/checkchromeos.py @@ -6,6 +6,7 @@ import requests from lib.inputstreamhelper.config import CHROMEOS_RECOVERY_ARM_HWIDS + def get_devices(): """Get Chrome OS devices as json object""" url = 'https://www.chromium.org/chromium-os/developer-information-for-chrome-os-devices' @@ -30,6 +31,7 @@ def get_devices(): devices.append(device) return devices + def get_arm_devices(): """Get Chrome OS ARM devices as json object""" devices = get_devices() @@ -39,6 +41,7 @@ def get_arm_devices(): arm_devices.append(device) return arm_devices + def get_serves(): """Get Chrome OS serving updates as json object""" url = 'https://cros-updates-serving.appspot.com/csv' @@ -54,6 +57,7 @@ def get_serves(): serves.append(serve) return serves + def get_recoveries(): """Get Chrome OS recovery items as json object""" url = 'https://dl.google.com/dl/edgedl/chromeos/recovery/recovery.json' @@ -62,6 +66,7 @@ def get_recoveries(): recoveries = response.json() return recoveries + def get_compatibles(): """Get compatible Chrome OS recovery items""" arm_devices = get_arm_devices() @@ -86,6 +91,7 @@ def get_compatibles(): compatibles.append(recovery) return compatibles + def get_smallest(): """Get the Chrome OS recovery item with the smallest filesize""" compatibles = get_compatibles() @@ -93,8 +99,8 @@ def get_smallest(): for item in compatibles: if smallest is None: smallest = item - if (int(item.get('filesize')) + int(item.get('zipfilesize')) < - int(smallest.get('filesize')) + int(smallest.get('zipfilesize'))): + if (int(item.get('filesize')) + int(item.get('zipfilesize')) + < int(smallest.get('filesize')) + int(smallest.get('zipfilesize'))): smallest = item return smallest @@ -111,20 +117,22 @@ def check_hwids(): for item in CHROMEOS_RECOVERY_ARM_HWIDS: if item not in hwids: - messages.append('%s is not available, please remove it from inputstreamhelper config' % item) + messages.append('{} is end-of-life, consider removing it from inputstreamhelper config'.format(item)) for item in hwids: if item not in CHROMEOS_RECOVERY_ARM_HWIDS: - messages.append('%s is missing, please add it to inputstreamhelper config' % item) + messages.append('{} is missing, please add it to inputstreamhelper config'.format(item)) if messages: raise Exception(messages) smallest = get_smallest() hwid = smallest.get('hwidmatch').strip('^.*-').split(' ')[0] - print('Chrome OS hardware id\'s are up to date, current smallest recovery image is %s' % hwid) + print('Chrome OS hardware id\'s are up to date, current smallest recovery image is {}'.format(hwid)) + def run(): """Main function""" check_hwids() + if __name__ == '__main__': run()