Skip to content

Commit

Permalink
feat: minimal testing suite
Browse files Browse the repository at this point in the history
  • Loading branch information
d0choa committed Jul 4, 2024
1 parent 1a76b9d commit 5260969
Show file tree
Hide file tree
Showing 4 changed files with 99 additions and 0 deletions.
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
6 changes: 6 additions & 0 deletions pyproject.toml
Original file line number Diff line number Diff line change
Expand Up @@ -21,6 +21,12 @@ 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"

[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

0 comments on commit 5260969

Please sign in to comment.