diff --git a/.github/workflows/pylint_check.yaml b/.github/workflows/pylint_check.yaml deleted file mode 100644 index 9d57037..0000000 --- a/.github/workflows/pylint_check.yaml +++ /dev/null @@ -1,76 +0,0 @@ -name: Enforcing pylint checks -on: - push: - branches: - - master - - develop - pull_request: - branches: - - master - - develop - tags: - - v* - workflow_dispatch: - -jobs: - update_python: - runs-on: ubuntu-latest - name: Running pylint checks - steps: - - name: Current python version - run: python3 --version || echo python3 not installed - - name: Install Python 3.7 - run: sudo apt-get install -y --no-install-recommends python3.7 python3-pip && sudo ln -sfn /usr/bin/python3.7 /usr/bin/python3 - id: install_python_3_7 - - name: Updated python version - run: python3 --version - - name: PYTHONPATH environment variable - run: echo ${PYTHONPATH} - - name: Update pip - run: python3 -m pip install --upgrade --no-cache-dir pip - id: pip-install - - name: Fetch/update setuptools - run: python3 -m pip install --upgrade --no-cache-dir setuptools - id: setuptools-install - - name: Fetch/update pylint - run: python3 -m pip install --upgrade --no-cache-dir pylint - id: pylint-install - - name: Fetch source code - uses: actions/checkout@v2 - id: fetch-source - - name: Finding files - run: find . -type f -name "*.py" > action_pylint_files.txt - id: find-python-files - - name: Install system requirements - shell: bash - run: 'sudo apt-get install -y python3-gdal gdal-bin libgdal-dev gcc g++ python3.7-dev' - id: install-gdal-other-reqs - - name: Install Python numpy - shell: bash - run: 'python3 -m pip install --upgrade --no-cache-dir numpy wheel terrautils' - id: install-python-numpy - - name: Install Python pygdal - shell: bash - run: 'sudo python3 -m pip install --no-cache-dir pygdal==2.2.3.5' - id: install-python-pygdal - - name: Install system requirements from source - shell: bash - run: '[ -s "packages.txt" ] && (cat packages.txt | sudo xargs apt-get install -y --no-install-recommends) || (echo "No addtional packages to install")' - id: install-system-reqs - - name: Install Python requirements from source - shell: bash - run: '[ -s "requirements.txt" ] && (python3 -m pip install --no-cache-dir -r requirements.txt) || (echo "No Python packages to install")' - id: install-python-reqs - - name: Run action pylint script - shell: bash - run: '[ -s ".github/workflows/action_pylint.sh" ] && (chmod +x ".github/workflows/action_pylint.sh" && ./.github/workflows/action_pylint.sh) || (echo "Error running shell script")' - id: run-special-action-script - - name: Fetching pylint.rc file - run: wget https://raw.githubusercontent.com/AgPipeline/Organization-info/master/pylint.rc - id: fetch_pylint_resource - - name: Listing - run: ls -la - - name: Files to be linted - run: cat action_pylint_files.txt - - name: Running pylint - run: cat action_pylint_files.txt | xargs python3 -m pylint --rcfile ./pylint.rc diff --git a/.github/workflows/testing_checks.yaml b/.github/workflows/testing_checks.yaml new file mode 100644 index 0000000..4433f21 --- /dev/null +++ b/.github/workflows/testing_checks.yaml @@ -0,0 +1,94 @@ +name: Enforcing testing checks +on: + push: + branches: + - master + - develop + pull_request: + branches: + - master + - develop + tags: + - v* + workflow_dispatch: + +jobs: + update_python: + runs-on: ubuntu-latest + name: Running test checks + strategy: + matrix: + app: [pylint, pytest] + include: + - app: pylint + pip_installs: pylint pytest + test_command: cat action_test_files.txt | xargs python3 -m pylint --rcfile ./pylint.rc + - app: pytest + pip_installs: pytest pytest-cov + test_command: python3 -m pytest --cov=. -rpP --cov-report=xml > coverage.txt + artifacts: coverage.txt + steps: + - name: Current python version + run: python3 --version || echo python3 not installed + - name: Install Python 3.7 + uses: actions/setup-python@v2 + with: + python-version: '3.7' + - name: Updated python version + run: python3 --version + - name: PYTHONPATH environment variable + run: echo "PYTHONPATH is ${PYTHONPATH}" + - name: Update pip + run: python3 -m pip install --upgrade --no-cache-dir pip + - name: Fetch/update setuptools + run: python3 -m pip install --upgrade --no-cache-dir setuptools + - name: Install python-apt + run: sudo apt-get install -y python-apt + - name: HACK to fix apt-get update problem w/ different python versions + run: 'cd /usr/lib/python3/dist-packages && sudo cp apt_pkg.cpython-36m-x86_64-linux-gnu.so apt_pkg.so' + - name: Update apt-get + run: sudo apt-get update + - name: Fetch/update testing pip installations + run: python3 -m pip install --upgrade --no-cache-dir ${{ matrix.pip_installs }} + - name: Fetch source code + uses: actions/checkout@v2 + - name: Finding files to process + run: find . -type f -name "*.py" > action_test_files.txt + - name: Install system requirements + shell: bash + run: 'sudo apt-get install -y python3-gdal gdal-bin libgdal-dev gcc g++ python3.7-dev' + - name: Install Python numpy + shell: bash + run: 'python3 -m pip install --upgrade --no-cache-dir numpy wheel' + - name: Install Python pygdal + shell: bash + run: 'python3 -m pip install --no-cache-dir pygdal==2.2.3.5' + - name: Install system requirements from source + shell: bash + run: '[ -s "packages.txt" ] && (cat packages.txt | sudo xargs apt-get install -y --no-install-recommends) || (echo "No additional packages to install")' + - name: Install Python requirements from source + shell: bash + run: '[ -s "requirements.txt" ] && (python3 -m pip install --no-cache-dir -r requirements.txt) || (echo "No Python requirements to install")' + - name: Run action pylint script + shell: bash + run: '[ -s ".github/workflows/action_pylint.sh" ] && (chmod +x ".github/workflows/action_pylint.sh" && ./.github/workflows/action_pylint.sh) || (echo "No action shell script found to run")' + - name: Fetching pylint.rc file + run: wget https://raw.githubusercontent.com/AgPipeline/Organization-info/master/pylint.rc + if: ${{ matrix.name }} == "pylint" + - name: Set execution permission for testing + run: chmod +x transformer.py + - name: Listing + run: ls -la + - name: Files to be tested + run: cat action_test_files.txt + - name: Running test + run: ${{ matrix.test_command }} + - name: Upload testing artifact + uses: actions/upload-artifact@v2 + with: + name: testing_artifacts + path: ${{ matrix.artifacts }} + if: ${{ matrix.artifacts }} + - name: Upload coverage to Codecov + uses: codecov/codecov-action@v1 + if: ${{ matrix.app == 'pytest' }} diff --git a/tests/test_transformer_simple.py b/tests/test_transformer_simple.py new file mode 100644 index 0000000..2b21d46 --- /dev/null +++ b/tests/test_transformer_simple.py @@ -0,0 +1,64 @@ +#!/usr/bin/env python3 +"""Tests plotclip.py +""" +import argparse +import os +import re +from subprocess import getstatusoutput + +from agpypeline.environment import Environment + +from configuration import ConfigurationInfo + +# The name of the source file to test and it's path +SOURCE_FILE = 'transformer.py' +SOURCE_PATH = os.path.abspath(os.path.join('.', SOURCE_FILE)) + +# Path relative to the current folder where the testing data files are +TESTING_JSON_FILE_PATH = './test_data' + + +def test_exists(): + """Asserts that the source file is available""" + assert os.path.isfile(SOURCE_PATH) + + +def test_usage(): + """Program prints a "usage" statement when requested""" + for flag in ['-h', '--help']: + ret_val, out = getstatusoutput(f'{SOURCE_PATH} {flag}') + assert re.match('usage', out, re.IGNORECASE) + assert ret_val == 0 + + +def test_add_parameters(): + """Checks that the add_parameters function is callable without error""" + # pylint: disable=import-outside-toplevel + from transformer import TemplateTransformer as tt + + new_tt = tt() + arg_parser = argparse.ArgumentParser() + new_tt.add_parameters(arg_parser) + + +def test_check_continue(): + """Checks that the check_continue function is callable without error""" + # pylint: disable=import-outside-toplevel + from transformer import TemplateTransformer as tt + + new_tt = tt() + ret_val = new_tt.check_continue(Environment(ConfigurationInfo()), {}, {}, []) + + assert ret_val == 0 + + +def test_perform_process(): + """Checks that the perform_process function is callable without error""" + # pylint: disable=import-outside-toplevel + from transformer import TemplateTransformer as tt + + new_tt = tt() + ret_val = new_tt.perform_process(Environment(ConfigurationInfo()), {}, {}, []) + + assert 'code' in ret_val + assert ret_val['code'] == 0 diff --git a/transformer.py b/transformer.py old mode 100644 new mode 100755 index ca22c1b..4dafabe --- a/transformer.py +++ b/transformer.py @@ -1,3 +1,4 @@ +#!/usr/bin/env python3 """My nifty transformer """