Skip to content
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

feat: minimal testing suite #2

Merged
Merged
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension


Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
42 changes: 42 additions & 0 deletions .github/workflows/pr.yaml
Original file line number Diff line number Diff line change
@@ -0,0 +1,42 @@
name: Checks

"on":
pull_request:

env:
PYTHON_VERSION_DEFAULT: "3.10.8"

jobs:
test:
runs-on: ubuntu-latest
steps:
- uses: actions/checkout@v4
with:
fetch-depth: 1
- name: Set up Python
uses: actions/setup-python@v5
with:
python-version: 3.10.8
- name: Install and configure Poetry
uses: snok/install-poetry@v1
with:
virtualenvs-create: true
virtualenvs-in-project: true
installer-parallel: true
- name: Load cached venv
id: cached-poetry-dependencies
uses: actions/cache@v4
with:
path: .venv
key: venv-${{ runner.os }}-${{ env.PYTHON_VERSION_DEFAULT }}-${{ hashFiles('**/poetry.lock') }}
- name: Validate project dependencies
run: poetry check
- name: Install dependencies
if: steps.cached-poetry-dependencies.outputs.cache-hit != 'true'
run: poetry install --no-interaction --no-root
- name: Install library
run: poetry install --no-interaction
- name: Check dependencies
run: poetry run deptry .
- name: Run tests
run: poetry run pytest
167 changes: 164 additions & 3 deletions poetry.lock

Some generated files are not rendered by default. Learn more about how customized files appear on GitHub.

7 changes: 7 additions & 0 deletions pyproject.toml
Original file line number Diff line number Diff line change
Expand Up @@ -21,6 +21,13 @@ pytest = "^8.2.2"
mypy = "^1.10.0"
pre-commit = "^3.7.1"


[tool.poetry.group.test.dependencies]
pytest-cov = "^5.0.0"
pytest-sugar = "^1.0.0"
pytest-xdist = "^3.6.1"
deptry = "^0.16.1"

[build-system]
requires = ["poetry-core"]
build-backend = "poetry.core.masonry.api"
Expand Down
12 changes: 12 additions & 0 deletions tests/conftest.py
Original file line number Diff line number Diff line change
@@ -0,0 +1,12 @@
"""Unit test configuration for the project."""

from __future__ import annotations

import pytest
from airflow.models import DagBag


@pytest.fixture(params=["orchestration/dags"])
def dag_bag(request: pytest.FixtureRequest) -> DagBag:
"""Return a DAG bag for testing."""
return DagBag(dag_folder=request.param, include_examples=False)
39 changes: 39 additions & 0 deletions tests/orchestration/dags/test_dag_validation.py
Original file line number Diff line number Diff line change
@@ -0,0 +1,39 @@
from airflow.models import DagBag


def test_no_import_errors(dag_bag: DagBag) -> None:
"""Test for import errors."""
assert (
not dag_bag.import_errors
), f"DAG import failures. Errors: {dag_bag.import_errors}"


def test_requires_tags(dag_bag: DagBag) -> None:
"""Tags should be defined for each DAG."""
for _, dag in dag_bag.dags.items():
assert dag.tags


def test_owner_len_greater_than_five(dag_bag: DagBag) -> None:
"""Owner should be defined for each DAG and be longer than 5 characters."""
for _, dag in dag_bag.dags.items():
assert len(dag.owner) > 5


def test_desc_len_greater_than_fifteen(dag_bag: DagBag) -> None:
"""Description should be defined for each DAG and be longer than 30 characters."""
for _, dag in dag_bag.dags.items():
if isinstance(dag.description, str):
assert len(dag.description) > 30


def test_owner_not_airflow(dag_bag: DagBag) -> None:
"""Owner should not be 'airflow'."""
for _, dag in dag_bag.dags.items():
assert str.lower(dag.owner) != "airflow"


def test_three_or_less_retries(dag_bag: DagBag) -> None:
"""Retries should be 3 or less."""
for _, dag in dag_bag.dags.items():
assert dag.default_args["retries"] <= 3
Loading