Skip to content

Commit

Permalink
Merge pull request #7 from artshumrc/django-5
Browse files Browse the repository at this point in the history
Conditionally import ZoneInfo; use GHA matrix strategy
  • Loading branch information
ColeDCrawford authored Jun 5, 2024
2 parents 4059d96 + 43f3972 commit b3e440d
Show file tree
Hide file tree
Showing 6 changed files with 28 additions and 30 deletions.
16 changes: 12 additions & 4 deletions .github/workflows/ci-pytest.yml
Original file line number Diff line number Diff line change
Expand Up @@ -11,17 +11,25 @@ env:
jobs:
tests:
runs-on: ubuntu-latest
strategy:
matrix:
python-version: ["3.8", "3.9", "3.10", "3.11", "3.12"]

steps:
- uses: actions/checkout@v3
- uses: actions/checkout@v4

- name: Build Docker images
run: |
docker compose -f docker-compose-test.yml build
PYTHON_VERSION=${{ matrix.python-version }} docker compose -f docker-compose-test.yml build
- name: Run Docker Compose containers
run: |
docker compose -f docker-compose-test.yml up -d
PYTHON_VERSION=${{ matrix.python-version }} docker compose -f docker-compose-test.yml up -d
- name: Run Pytest unit tests within Compose
run: |
docker compose -f docker-compose-test.yml exec web bash -c "tox"
docker compose -f docker-compose-test.yml exec web pytest
- name: Stop Docker Compose containers
if: always()
run: docker compose -f docker-compose.yml down
8 changes: 4 additions & 4 deletions README.rst
Original file line number Diff line number Diff line change
Expand Up @@ -162,10 +162,10 @@ tests are located under each Django app:
Github Actions CI
---------------
Github Actions is configured to run unit tests on every new PR. The tests are configured in
``.github/workflows/ci-pytest.yml``. The workflow is configured to run tests on Python3.8-3.12 using
``tox``.

---eop
``.github/workflows/ci-pytest.yml``. The workflow is configured to run tests on Python 3.8-3.12
(currently supported versions) using `pytest` and a parallelized Github Actions matrix strategy which passes
the Python version as a build argument to the Dockerfile. `tox` is configured for local developmment
tests if that is preferred over `act`.


.. _W3C Web Annotation Data Model: https://www.w3.org/TR/annotation-model/
Expand Down
2 changes: 1 addition & 1 deletion catchpy/__init__.py
Original file line number Diff line number Diff line change
@@ -1,3 +1,3 @@
# important to use single quotes in version string
# for post-commit tagging
__version__ = '2.9.0'
__version__ = '2.9.1'
6 changes: 4 additions & 2 deletions catchpy/consumer/tests/test_middleware.py
Original file line number Diff line number Diff line change
@@ -1,9 +1,11 @@
from datetime import datetime, timedelta
from zoneinfo import ZoneInfo

import pytest
from django.http import HttpResponse
from django.test import RequestFactory
try:
from zoneinfo import ZoneInfo
except ImportError:
from backports.zoneinfo import ZoneInfo

from ..catchjwt import decode_token, encode_catchjwt, validate_token
from ..jwt_middleware import (
Expand Down
2 changes: 2 additions & 0 deletions docker-compose-test.yml
Original file line number Diff line number Diff line change
Expand Up @@ -12,6 +12,8 @@ services:
build:
context: .
dockerfile: test.Dockerfile
args:
PYTHON_VERSION: ${PYTHON_VERSION}
image: hx/catchpy:test
command: ["./wait-for-it.sh", "db:5432", "--", "python", "manage.py", "runserver", "0.0.0.0:8000"]
volumes:
Expand Down
24 changes: 5 additions & 19 deletions test.Dockerfile
Original file line number Diff line number Diff line change
@@ -1,27 +1,13 @@
FROM python:3.11
# pass in Python version as build arg to allow for tests to be run on multiple versions of Python
ARG PYTHON_VERSION=3.11
FROM python:${PYTHON_VERSION}
ENV PYTHONUNBUFFERED 1
ENV PYTHONUNBUFFERED 1

RUN apt-get update

# Include fortune library for quote generation for text annotations
RUN apt-get install fortune-mod -y
RUN apt-get update && apt-get install -y fortune-mod
ENV PATH "$PATH:/usr/games"

# Install all other versions of Python we want to test with tox
RUN git clone https://github.com/pyenv/pyenv /root/.pyenv
RUN for PYTHON_VERSION in 3.8.19 3.9.19 3.10.14 3.11.9 3.12.3; do \
set -ex \
&& /root/.pyenv/bin/pyenv install ${PYTHON_VERSION} \
&& /root/.pyenv/versions/${PYTHON_VERSION}/bin/python -m pip install --upgrade pip \
; done

# Add to PATH, in order of lowest precedence to highest.
ENV PATH /root/.pyenv/versions/3.8.19/bin:${PATH}
ENV PATH /root/.pyenv/versions/3.9.19/bin:${PATH}
ENV PATH /root/.pyenv/versions/3.10.14/bin:${PATH}
ENV PATH /root/.pyenv/versions/3.12.3/bin:${PATH}
ENV PATH /root/.pyenv/versions/3.11.9/bin:${PATH}

RUN mkdir /code
WORKDIR /code
ADD . /code
Expand Down

0 comments on commit b3e440d

Please sign in to comment.