Skip to content

Commit

Permalink
Improve tests and run tests on Windows (#58)
Browse files Browse the repository at this point in the history
* Run CI on Windows
* Use sakee
  • Loading branch information
michaelarnauts committed Jan 9, 2021
1 parent 10fd89b commit 391c0a6
Show file tree
Hide file tree
Showing 37 changed files with 232 additions and 1,267 deletions.
11 changes: 11 additions & 0 deletions .env.example
Original file line number Diff line number Diff line change
@@ -0,0 +1,11 @@
ADDON_USERNAME=
ADDON_PASSWORD=
ADDON_PROFILE=

KODI_HOME=tests/home
KODI_INTERACTIVE=0
KODI_STUB_VERBOSE=1
KODI_STUB_RPC_RESPONSES=tests/rpc

#HTTP_PROXY=
#HTTPS_PROXY=
1 change: 0 additions & 1 deletion .gitattributes
Original file line number Diff line number Diff line change
Expand Up @@ -5,4 +5,3 @@ tests/ export-ignore
.pylintrc export-ignore
Makefile export-ignore
requirements.txt export-ignore
tox.ini export-ignore
62 changes: 44 additions & 18 deletions .github/workflows/ci.yml
Original file line number Diff line number Diff line change
@@ -1,41 +1,67 @@
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
env:
PYTHONIOENCODING: utf-8
PYTHONPATH: ${{ github.workspace }}/resources/lib:${{ github.workspace }}/tests
runs-on: ${{ matrix.os }}
strategy:
fail-fast: false
matrix:
python-version: [2.7, 3.6, 3.7, 3.8, 3.9]
os: [ ubuntu-latest ]
python-version: [ 2.7, 3.5, 3.6, 3.7, 3.8, 3.9 ]
include:
# Kodi Leia on Windows uses a bundled Python 2.7.
- os: windows-latest
python-version: 2.7

# Kodi Matrix on Windows uses a bundled Python 3.8, but we test 3.9 also to be sure.
- os: windows-latest
python-version: 3.8
- os: windows-latest
python-version: 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
with:
python-version: ${{ matrix.python-version }}

- name: Install dependencies
run: |
sudo apt-get install gettext
sudo pip install coverage --install-option="--install-scripts=/usr/bin"
python -m pip install --upgrade pip
pip install -r requirements.txt
run: pip install -r requirements.txt

- name: Run pylint
run: make check-pylint
- name: Run tox
run: make check-tox

- name: Check translations
run: make check-translations
if: matrix.os == 'ubuntu-latest' && matrix.python-version == '3.9'
run: sudo apt-get install gettext && make check-translations

- name: Run unit tests
run: coverage run -m unittest discover
- name: Run addon service
run: coverage run -a service.py
env:
ADDON_USERNAME: ${{ secrets.ADDON_USERNAME }}
ADDON_PASSWORD: ${{ secrets.ADDON_PASSWORD }}
PYTHONIOENCODING: utf-8
KODI_HOME: ${{ github.workspace }}/tests/home
KODI_INTERACTIVE: 0
KODI_STUB_RPC_RESPONSES: ${{ github.workspace }}/tests/rpc
HTTP_PROXY: ${{ secrets.HTTP_PROXY }}
run: pytest -v --cov=./ --cov-report=xml tests

- name: Upload code coverage to CodeCov
uses: codecov/codecov-action@v1
continue-on-error: true
env:
OS: ${{ matrix.os }}
PYTHON: ${{ matrix.python-version }}
with:
flags: unittests
env_vars: OS,PYTHON
26 changes: 11 additions & 15 deletions .gitignore
Original file line number Diff line number Diff line change
@@ -1,25 +1,21 @@
# Temporary files
*.pyc
*.pyo
.DS*
Thumbs.db
*~
.cache

# Files related to development
.pylint_rc
/.idea
/.project
/.pydevproject
/.settings
/Pipfile
/Pipfile.lock

# Files related to testing
Thumbs.db
*~
.cache
.coverage
.tox/
coverage.xml

# Testing
tests/home/userdata/addon_data/service.iptv.manager/playlist.m3u8
tests/home/userdata/addon_data/service.iptv.manager/epg.xml
.env

# IPTV Manager output
tests/userdata/playlist.m3u8
tests/userdata/epg.xml
tests/userdata/channels.json
Pipfile
Pipfile.lock
23 changes: 12 additions & 11 deletions Makefile
Original file line number Diff line number Diff line change
@@ -1,7 +1,9 @@
export PYTHONPATH := $(CURDIR):$(CURDIR)/tests
export KODI_HOME := $(CURDIR)/tests/home
export KODI_INTERACTIVE := 0
PYTHON := python
KODI_PYTHON_ABIS := 3.0.0 2.26.0

# Collect information to build as sensible package name
name = $(shell xmllint --xpath 'string(/addon/@id)' addon.xml)
version = $(shell xmllint --xpath 'string(/addon/@version)' addon.xml)
git_branch = $(shell git rev-parse --abbrev-ref HEAD)
Expand All @@ -22,22 +24,18 @@ languages = $(filter-out en_gb, $(patsubst resources/language/resource.language.
all: check test build
zip: build

check: check-pylint check-tox check-translations
check: check-pylint check-translations

check-pylint:
@echo ">>> Running pylint checks"
@$(PYTHON) -m pylint *.py resources/lib/ tests/

check-tox:
@echo ">>> Running tox checks"
@$(PYTHON) -m tox -q

check-translations:
@echo ">>> Running translation checks"
@$(foreach lang,$(languages), \
msgcmp --use-untranslated resources/language/resource.language.$(lang)/strings.po resources/language/resource.language.en_gb/strings.po; \
)
@#@tests/check_for_unused_translations.py
@tests/check_for_unused_translations.py

check-addon: clean build
@echo ">>> Running addon checks"
Expand All @@ -46,16 +44,19 @@ check-addon: clean build
cd ${TMPDIR} && kodi-addon-checker --branch=leia
@rm -rf ${TMPDIR}

codefix:
@isort -l 160 resources/

test: test-unit

test-unit:
@echo ">>> Running unit tests"
@$(PYTHON) -m unittest discover -v -b -f
@$(PYTHON) -m pytest tests

clean:
@find . -name '*.py[cod]' -type f -delete
@find . -name '__pycache__' -type d -delete
@rm -rf .pytest_cache/ .tox/ tests/cdm tests/userdata/temp
@rm -rf .pytest_cache/ tests/cdm tests/userdata/temp
@rm -f *.log .coverage

build: clean
Expand All @@ -69,8 +70,8 @@ ifneq ($(release),)
@github_changelog_generator -u add-ons -p service.iptv.manager --no-issues --future-release v$(release);

@echo "cd /addon/@version\nset $$release\nsave\nbye" | xmllint --shell addon.xml; \
# date=$(shell date '+%Y-%m-%d'); \
# echo "cd /addon/extension[@point='xbmc.addon.metadata']/news\nset v$$release ($$date)\nsave\nbye" | xmllint --shell addon.xml; \
date=$(shell date '+%Y-%m-%d'); \
echo "cd /addon/extension[@point='xbmc.addon.metadata']/news\nset v$$release ($$date)\nsave\nbye" | xmllint --shell addon.xml; \

# Next steps to release:
# - Modify the news-section of addons.xml
Expand Down
9 changes: 6 additions & 3 deletions requirements.txt
Original file line number Diff line number Diff line change
@@ -1,7 +1,10 @@
coverage
lxml
polib
pylint
pytest
pytest-cov
pytest-timeout
python-dateutil
tox
mock
mock
#sakee
git+git://github.com/michaelarnauts/kodi.emulator.ascii.git@jsonrpc-addons#egg=sakee
3 changes: 2 additions & 1 deletion resources/lib/functions.py
Original file line number Diff line number Diff line change
Expand Up @@ -10,7 +10,6 @@
from resources.lib.modules.contextmenu import ContextMenu
from resources.lib.modules.iptvsimple import IptvSimple

kodilogging.config()
_LOGGER = logging.getLogger(__name__)


Expand Down Expand Up @@ -53,6 +52,8 @@ def open_settings():

def run(args):
"""Run the function"""
kodilogging.config()

function = args[1]
function_map = {
'setup-iptv-simple': setup_iptv_simple,
Expand Down
Loading

0 comments on commit 391c0a6

Please sign in to comment.