From 7f8ef422db260e38b5e0f480883639d5ea4cb192 Mon Sep 17 00:00:00 2001 From: conhumi Date: Fri, 7 Feb 2025 14:10:01 +0900 Subject: [PATCH 1/2] use tox to support multi versions of python --- Dockerfile | 19 ++++++++++++++++--- Makefile | 6 ++---- library/tests/__init__.py | 0 library/tox.ini | 17 +++++++++++++++++ 4 files changed, 35 insertions(+), 7 deletions(-) create mode 100644 library/tests/__init__.py create mode 100644 library/tox.ini diff --git a/Dockerfile b/Dockerfile index 70b55ab..8319435 100644 --- a/Dockerfile +++ b/Dockerfile @@ -1,3 +1,16 @@ -FROM python:2.7 -RUN pip install ansible coverage nose mock requests -WORKDIR /work +FROM 31z4/tox + +USER root + +RUN set -eux; \ + apt-get update; \ + DEBIAN_FRONTEND=noninteractive \ + apt-get install -y --no-install-recommends \ + python3.6 \ + python3.7 \ + python3.8 \ + python3.9 \ + python3.10; \ + rm -rf /var/lib/apt/lists/* + +USER tox diff --git a/Makefile b/Makefile index a4d844c..6f7fc0e 100644 --- a/Makefile +++ b/Makefile @@ -1,10 +1,8 @@ IMAGE_NAME := "nifcloud/ansible-role-nifcloud" - build: docker build -t ${IMAGE_NAME} . + test: make build - docker run --workdir /work/library --rm -ti -v $(PWD):/work ${IMAGE_NAME} bash -c " \ - nosetests --no-byte-compile --with-coverage && \ - coverage report --include=./nifcloud*.py" + docker run -u $(shell id -u):$(shell id -g) --workdir /work/library --rm -ti -v $(PWD):/work ${IMAGE_NAME} diff --git a/library/tests/__init__.py b/library/tests/__init__.py new file mode 100644 index 0000000..e69de29 diff --git a/library/tox.ini b/library/tox.ini new file mode 100644 index 0000000..a2c620a --- /dev/null +++ b/library/tox.ini @@ -0,0 +1,17 @@ +[tox] +env_list = + 3.9 + 3.10 + 3.11 + 3.12 + 3.13 + +[testenv] +deps = + pytest + coverage + mock + requests + pytest-cov + ansible +commands = coverage run --source='.' -m pytest tests/ From e85237e29ac0229bbda914a992c9bcbdef47a7ce Mon Sep 17 00:00:00 2001 From: conhumi Date: Fri, 7 Feb 2025 14:10:45 +0900 Subject: [PATCH 2/2] add python runtimes for ci --- .github/workflows/syntax-check.yaml | 2 +- .github/workflows/test-module.yaml | 6 +++--- 2 files changed, 4 insertions(+), 4 deletions(-) diff --git a/.github/workflows/syntax-check.yaml b/.github/workflows/syntax-check.yaml index 1dd7ac5..a012242 100644 --- a/.github/workflows/syntax-check.yaml +++ b/.github/workflows/syntax-check.yaml @@ -9,7 +9,7 @@ jobs: runs-on: ubuntu-20.04 strategy: matrix: - python-version: ["3.6.15"] + python-version: ["3.9", "3.10", "3.11", "3.12", "3.13"] steps: - uses: actions/checkout@v4 - name: Set up python diff --git a/.github/workflows/test-module.yaml b/.github/workflows/test-module.yaml index 3bf19a7..420163b 100644 --- a/.github/workflows/test-module.yaml +++ b/.github/workflows/test-module.yaml @@ -9,7 +9,7 @@ jobs: runs-on: ubuntu-20.04 strategy: matrix: - python-version: ["3.6.15"] + python-version: ["3.9", "3.10", "3.11", "3.12", "3.13"] steps: - uses: actions/checkout@v4 - name: Set up python @@ -18,11 +18,11 @@ jobs: python-version: ${{ matrix.python-version }} - name: Install dependences from pip shell: bash - run: pip install ansible nose coveralls mock requests coverage + run: pip install ansible pytest coveralls mock requests coverage - name: NIFCLOUD modules check shell: bash run: | - nosetests --no-byte-compile --with-coverage --cover-package=library/ --where=library/ + coverage run --source=library -m pytest library/tests/ coverage xml - name: Coveralls uses: coverallsapp/github-action@v2