diff --git a/.github/workflows/python-app.yml b/.github/workflows/python-app.yml new file mode 100644 index 0000000..69e4d75 --- /dev/null +++ b/.github/workflows/python-app.yml @@ -0,0 +1,38 @@ +# This workflow will install Python dependencies, run tests and lint with a variety of Python versions +# For more information see: https://help.github.com/actions/language-and-framework-guides/using-python-with-github-actions + +name: Python package + +on: + push: + branches: [ master ] + pull_request: + branches: [ master ] + +jobs: + build: + + runs-on: ubuntu-latest + strategy: + matrix: + python-version: [3.6, 3.7, 3.8, 3.9] + + steps: + - uses: actions/checkout@v2 + - name: Set up Python ${{ matrix.python-version }} + uses: actions/setup-python@v2 + with: + python-version: ${{ matrix.python-version }} + - name: Install dependencies + run: | + python -m pip install --upgrade pip + python setup.py install + python -m pip install -r test-requirements.txt + - name: Lint with flake8 + run: | + # stop the build if there are Python syntax errors or undefined names + # Code style checks disabled until the style of the project is set. + ./run_tests.sh lint + - name: Test with pytest + run: | + ./run_tests.sh test diff --git a/.travis.yml b/.travis.yml deleted file mode 100644 index 300ef21..0000000 --- a/.travis.yml +++ /dev/null @@ -1,11 +0,0 @@ -language: python -python: - - "3.5" - - "3.6" - - "3.7" - - "3.8" - - "3.9" -install: - - pip install -r requirements.txt - - pip install -r test-requirements.txt -script: python run_tests.py --fail-on-error diff --git a/README.md b/README.md index b8836d6..526a2bb 100644 --- a/README.md +++ b/README.md @@ -86,6 +86,28 @@ def register_pandora_vocab(emitter): for match in m.groups(): register_vocab('Pandora Station', match) ``` + +Development +=========== + +Glad you'd like to help! + +To install test and development requirements run + +``` +pip install -r test-requirements.txt +``` + +This will install the test-requirements as well as the runtime requirements for adapt. + +To test any changes before submitting them run + +``` +./run_tests.sh +``` + +This will run the same checks as the Github actions and verify that your code should pass with flying colours. + Learn More ======== diff --git a/run_tests.py b/run_tests.py deleted file mode 100644 index 8c460ea..0000000 --- a/run_tests.py +++ /dev/null @@ -1,13 +0,0 @@ -import unittest - -from xmlrunner import XMLTestRunner -import os -import sys - -loader = unittest.TestLoader() -tests = loader.discover(os.path.dirname(os.path.realpath(__file__)), pattern="*Test.py") -fail_on_error = "--fail-on-error" in sys.argv -runner = XMLTestRunner() -result = runner.run(tests) -if fail_on_error and len(result.failures + result.errors) > 0: - sys.exit(1) diff --git a/run_tests.sh b/run_tests.sh new file mode 100755 index 0000000..11a99b6 --- /dev/null +++ b/run_tests.sh @@ -0,0 +1,40 @@ +#! /bin/bash + +ADAPT_DIR=$(dirname $0) + +do_lint () { + flake8 "${ADAPT_DIR}/adapt" --select=E9,F63,F7,F82 --show-source && \ + flake8 "${ADAPT_DIR}/test" --select=E9,F63,F7,F82 --show-source +} + +do_test () { + pytest "${ADAPT_DIR}/test/"* +} + +show_help () { + echo "Tests for adapt." + echo "If no arguments are given, both test and linting is performed." + echo "Otherwise the argument will determine which part is performed." + echo "" + echo " Usage: $0 [test/lint]" + echo "" + echo "Arguments:" + echo " test: Only run the tests." + echo " lint: Only perform codestyle and static analysis." +} + +if [[ $# == 0 ]]; then + do_lint || exit $? # Exit on failure + do_test || exit $? # Exit on failure +elif [[ $# == 1 ]]; then + if [[ $1 == "lint" ]]; then + do_lint + elif [[ $1 == "test" ]]; then + do_test + else + show_help + fi +else + show_help +fi + diff --git a/test-requirements.txt b/test-requirements.txt index dfe4a1c..19f6206 100644 --- a/test-requirements.txt +++ b/test-requirements.txt @@ -1 +1,3 @@ -xmlrunner==1.7.7 +flake8 +pytest +-r requirements.txt