From a66fa26efa960085dd4b3530434e4fe95d7c72b5 Mon Sep 17 00:00:00 2001 From: Kenneth Hoste Date: Thu, 27 Oct 2022 20:00:10 +0200 Subject: [PATCH] add test for mkdir function + CI workflow to run tests with Python 3.6 - 3.11 --- .github/workflows/tests.yaml | 26 ++++++++++++++++++++++++++ test.sh | 11 +++++++++++ tests/__init__.py | 0 tests/test_task_build.py | 34 ++++++++++++++++++++++++++++++++++ 4 files changed, 71 insertions(+) create mode 100644 .github/workflows/tests.yaml create mode 100755 test.sh create mode 100644 tests/__init__.py create mode 100644 tests/test_task_build.py diff --git a/.github/workflows/tests.yaml b/.github/workflows/tests.yaml new file mode 100644 index 00000000..5e13f1dc --- /dev/null +++ b/.github/workflows/tests.yaml @@ -0,0 +1,26 @@ +name: Run tests +on: [push, pull_request] +jobs: + test: + runs-on: ubuntu-latest + strategy: + matrix: + python: [3.6, 3.7, 3.8, 3.9, '3.10', '3.11'] + fail-fast: false + steps: + - name: Check out repository code + uses: actions/checkout@v3 + + - name: Setup Python + uses: actions/setup-python@v3 + with: + python-version: ${{matrix.python}} + + - name: Install required Python packages + pytest + run: | + python -m pip install -r requirements.txt + python -m pip install pytest + + - name: Run test suite + run: | + ./test.sh diff --git a/test.sh b/test.sh new file mode 100755 index 00000000..d5a98ae7 --- /dev/null +++ b/test.sh @@ -0,0 +1,11 @@ +#!/bin/bash +# +# This file is part of PyGHee (pronounced as "piggy"), the GitHub Event Executor, +# is a GitHub App to process GitHub events, implemented in Python; +# see https://github.com/boegel/pyghee +# +# author: Kenneth Hoste (@boegel) +# +# license: GPLv2 +# +PYTHONPATH=$PWD:$PYTHONPATH pytest -v -s diff --git a/tests/__init__.py b/tests/__init__.py new file mode 100644 index 00000000..e69de29b diff --git a/tests/test_task_build.py b/tests/test_task_build.py new file mode 100644 index 00000000..19af2731 --- /dev/null +++ b/tests/test_task_build.py @@ -0,0 +1,34 @@ +# Tests for 'build' task of the EESSI build-and-deploy bot, +# see https://github.com/EESSI/eessi-bot-software-layer +# +# author: Kenneth Hoste (@boegel) +# +# license: GPLv2 +# +import os + +from tasks.build import mkdir + + +def test_mkdir(tmpdir): + """Tests for mkdir function.""" + test_dir = os.path.join(tmpdir, 'test') + mkdir(test_dir) + assert os.path.isdir(test_dir) + + # parent directories are created if needed + deep_test_dir = os.path.join(tmpdir, 'one', 'two', 'three') + assert not os.path.exists(os.path.dirname(os.path.dirname(deep_test_dir))) + mkdir(deep_test_dir) + assert os.path.isdir(deep_test_dir) + + # calling mkdir on an existing path is fine (even if that path is a file?!) + mkdir(test_dir) + assert os.path.isdir(test_dir) + + test_file = os.path.join(tmpdir, 'test.txt') + with open(test_file, 'w') as fp: + fp.write('') + + mkdir(test_file) + assert os.path.isfile(test_file)