-
Notifications
You must be signed in to change notification settings - Fork 1
New issue
Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.
By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.
Already on GitHub? Sign in to your account
ci: test plugin and rdmo setup #2
Changes from all commits
File filter
Filter by extension
Conversations
Jump to
Diff view
Diff view
There are no files selected for viewing
Original file line number | Diff line number | Diff line change |
---|---|---|
|
@@ -9,6 +9,8 @@ on: | |
paths: | ||
- '.github/workflows/**' | ||
- 'rdmo_radar/**' | ||
- 'testing/**' | ||
- 'tests/**' | ||
- .pre-commit-config.yaml | ||
- pyproject.toml | ||
|
||
|
@@ -18,53 +20,55 @@ concurrency: | |
cancel-in-progress: true | ||
|
||
env: | ||
PYTHONDONTWRITEBYTECODE: 1 | ||
FORCE_COLOR: 1 # colored output by pytest etc. | ||
CLICOLOR_FORCE: 1 # colored output by ruff | ||
|
||
jobs: | ||
|
||
lint: | ||
name: Lint | ||
runs-on: ubuntu-22.04 | ||
steps: | ||
- uses: actions/checkout@v4 | ||
- uses: actions/setup-python@v4 | ||
with: | ||
python-version: "3.12" | ||
cache: pip | ||
- run: python -m pip install --upgrade pip setuptools wheel | ||
- run: python -m pip install -e .[dev] | ||
- name: Set up pre-commit cache | ||
uses: actions/cache@v3 | ||
with: | ||
path: ~/.cache/pre-commit | ||
key: lint-${{ hashFiles('.pre-commit-config.yaml') }} | ||
- name: Run linters via pre-commit (ruff, eslint) | ||
run: pre-commit run --all-files --color=always | ||
uses: rdmorganiser/.github/.github/workflows/_lint.yml@main | ||
|
||
dev-setup: | ||
# Ref: structlog (MIT licensed) <https://github.com/hynek/structlog/blob/main/.github/workflows/ci.yml> | ||
name: "Test dev setup on ${{ matrix.os }}" | ||
runs-on: ${{ matrix.os }} | ||
strategy: | ||
matrix: | ||
os: [ubuntu-latest, windows-latest, macos-latest] | ||
test: | ||
runs-on: ubuntu-24.04 | ||
steps: | ||
- uses: actions/checkout@v4 | ||
- uses: actions/setup-python@v4 | ||
- name: Checkout "testing" directory rdmo repository | ||
uses: actions/checkout@v4 | ||
with: | ||
repository: rdmorganiser/rdmo | ||
sparse-checkout: testing | ||
path: rdmo | ||
- name: Merge rdmo/testing with plugin testing directory | ||
run: cp -r rdmo/testing/* testing && rm -r rdmo | ||
- uses: actions/setup-python@v5 | ||
with: | ||
python-version: "3.12" | ||
cache: pip | ||
- run: python -Im pip install -e .[dev] | ||
- run: python -Ic 'import rdmo_radar; print(rdmo_radar.__version__)' | ||
- run: python -m pip install --editable ".[dev]" | ||
- run: python -m pip list | ||
- run: pytest -s | ||
|
||
# dev-setup: | ||
There was a problem hiding this comment. Choose a reason for hiding this commentThe reason will be displayed to describe this comment to others. Learn more. Uncommented for now to save some time when working on this PR. |
||
# # Ref: structlog (MIT licensed) <https://github.com/hynek/structlog/blob/main/.github/workflows/ci.yml> | ||
# name: "Test dev setup on ${{ matrix.os }}" | ||
# runs-on: ${{ matrix.os }} | ||
# strategy: | ||
# matrix: | ||
# os: [ubuntu-latest, windows-latest, macos-latest] | ||
# steps: | ||
# - uses: actions/checkout@v4 | ||
# - uses: actions/setup-python@v4 | ||
# with: | ||
# python-version: "3.12" | ||
# cache: pip | ||
# - run: python -Im pip install -e .[dev] | ||
# - run: python -Ic 'import rdmo_radar; print(rdmo_radar.__version__)' | ||
|
||
required-checks-pass: | ||
if: always() | ||
needs: | ||
- lint | ||
- dev-setup | ||
runs-on: ubuntu-22.04 | ||
# - dev-setup | ||
runs-on: ubuntu-24.04 | ||
steps: | ||
- uses: re-actors/alls-green@release/v1 | ||
with: | ||
|
Original file line number | Diff line number | Diff line change |
---|---|---|
|
@@ -13,3 +13,6 @@ __pycache__/ | |
/build | ||
/dist | ||
/*.egg-info | ||
|
||
.ruff_cache | ||
.pytest_cache |
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,9 @@ | ||
# ruff: noqa: F821 | ||
There was a problem hiding this comment. Choose a reason for hiding this commentThe reason will be displayed to describe this comment to others. Learn more. Is this sufficient? Do we need to put rdmo-plugins-radar into |
||
|
||
PROJECT_IMPORTS += [ | ||
('radar', _('from RADAR XML'), 'rdmo_radar.imports.RadarImport'), | ||
] | ||
PROJECT_EXPORTS += [ | ||
('radar-xml', _('as RADAR XML'), 'rdmo_radar.exports.RadarExport'), | ||
('radar', _('directly to RADAR'), 'rdmo_radar.exports.RadarExportProvider'), | ||
] |
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,39 @@ | ||
from pathlib import Path | ||
There was a problem hiding this comment. Choose a reason for hiding this commentThe reason will be displayed to describe this comment to others. Learn more. I copied these fixtures from the rdmo repo. We can of course pull this file from the rdmo during ci. |
||
|
||
import pytest | ||
|
||
from django.conf import settings | ||
from django.core.management import call_command | ||
|
||
from rdmo.accounts.utils import set_group_permissions | ||
|
||
|
||
@pytest.fixture(scope="session") | ||
def fixtures(): | ||
allowed_file_stems = { | ||
"accounts", | ||
"conditions", | ||
"domain", | ||
"groups", | ||
"options", | ||
"overlays", | ||
"projects", | ||
"questions", | ||
"sites", | ||
"tasks", | ||
"users", | ||
"views", | ||
} | ||
fixtures = [] | ||
for fixture_dir in settings.FIXTURE_DIRS: | ||
filenames = [filename for filename in Path(fixture_dir).iterdir() if filename.stem in allowed_file_stems] | ||
fixtures.extend(filenames) | ||
return fixtures | ||
|
||
|
||
@pytest.fixture(scope="session") | ||
def django_db_setup(django_db_setup, django_db_blocker, fixtures): # noqa: PT004 - pytest-django requires this name "django_db_setup" | ||
"""Populate database with test data from fixtures directories.""" | ||
with django_db_blocker.unblock(): | ||
call_command("loaddata", *fixtures) | ||
set_group_permissions() |
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,20 @@ | ||
import pytest | ||
There was a problem hiding this comment. Choose a reason for hiding this commentThe reason will be displayed to describe this comment to others. Learn more. These are only dummy tests. |
||
|
||
from django.conf import settings | ||
from django.contrib.auth import get_user_model | ||
from django.utils.translation import gettext_lazy as _ | ||
|
||
from rdmo.projects.models import Project | ||
|
||
|
||
def test_settings(): | ||
assert ("radar", _("from RADAR XML"), "rdmo_radar.imports.RadarImport") in settings.PROJECT_IMPORTS | ||
|
||
|
||
@pytest.mark.django_db | ||
def test_fixtures_are_available(): | ||
num_users = get_user_model().objects.count() | ||
assert num_users > 0 | ||
|
||
num_projects = Project.objects.count() | ||
assert num_projects > 0 |
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
Proposal to use the job from the central
.github
repo.