Skip to content

Commit

Permalink
refactor: create new 'pytest-taskgraph' module to house test fixtures
Browse files Browse the repository at this point in the history
These fixtures are useful for any project that wants to test Taskgraph
related transforms or scripts. By putting them in a package, we can
share them to any other repos that may need them.
  • Loading branch information
ahal committed Dec 11, 2024
1 parent 33803c5 commit 78810ee
Show file tree
Hide file tree
Showing 21 changed files with 738 additions and 27 deletions.
28 changes: 26 additions & 2 deletions .github/workflows/pypi-publish.yml
Original file line number Diff line number Diff line change
Expand Up @@ -3,8 +3,9 @@ on:
release:
types: [published]
jobs:
pypi-publish:
pypi-publish-taskcluster-taskgraph:
name: upload release to PyPI
if: ${{ ! startswith(github.ref, 'refs/tags/pytest-taskgraph') }}
runs-on: ubuntu-latest
environment: release
permissions:
Expand All @@ -16,9 +17,32 @@ jobs:
with:
python-version: '3.11'
cache: 'pip'
- name: Build package distributions
- name: Build taskcluster-taskgraph package distributions
run: |
pip install build
python -m build
- name: Publish package distributions to PyPI
uses: pypa/gh-action-pypi-publish@release/v1
pypi-publish-pytest-taskgraph:
name: upload release to PyPI
if: startswith(github.ref, 'refs/tags/pytest-taskgraph')
runs-on: ubuntu-latest
environment: release
permissions:
id-token: write
steps:
- name: Checkout sources
uses: actions/checkout@v4
- uses: actions/setup-python@v5
with:
python-version: '3.11'
cache: 'pip'
- name: Build pytest-taskgraph package distributions
working-directory: packages/pytest-taskgraph
run: |
pip install build
python -m build
- name: Publish package distributions to PyPI
uses: pypa/gh-action-pypi-publish@release/v1
with:
packages-dir: packages/pytest-taskgraph/dist
Empty file.
17 changes: 17 additions & 0 deletions packages/pytest-taskgraph/pyproject.toml
Original file line number Diff line number Diff line change
@@ -0,0 +1,17 @@
[project]
name = "pytest-taskgraph"
version = "0.1.0"
description = "Add your description here"
readme = "README.md"
authors = [
{ name = "Andrew Halberstadt", email = "[email protected]" }
]
requires-python = ">=3.8"
dependencies = ["pytest", "taskcluster-taskgraph>=12.1.0"]

[project.entry-points.pytest11]
pytest-taskgraph = "pytest_taskgraph"

[build-system]
requires = ["hatchling"]
build-backend = "hatchling.build"
2 changes: 2 additions & 0 deletions packages/pytest-taskgraph/src/pytest_taskgraph/__init__.py
Original file line number Diff line number Diff line change
@@ -0,0 +1,2 @@
from .fixtures.gen import * # noqa
from .fixtures.vcs import * # noqa
File renamed without changes.
File renamed without changes.
654 changes: 654 additions & 0 deletions packages/pytest-taskgraph/uv.lock

Large diffs are not rendered by default.

8 changes: 6 additions & 2 deletions pyproject.toml
Original file line number Diff line number Diff line change
Expand Up @@ -45,6 +45,9 @@ taskgraph = "taskgraph.main:main"
Repository = "https://github.com/taskcluster/taskgraph"
Issues = "https://github.com/taskcluster/taskgraph/issues"

[tool.uv.sources]
pytest-taskgraph = { path = "packages/pytest-taskgraph" }

[tool.uv]
dev-dependencies = [
"coverage",
Expand All @@ -53,6 +56,7 @@ dev-dependencies = [
"pyright",
"pytest",
"pytest-mock",
"pytest-taskgraph",
"responses",
"sphinx",
"sphinx-autobuild",
Expand All @@ -79,7 +83,7 @@ xfail_strict = true

[tool.coverage.run]
branch = true
source = ["src/taskgraph/", "src/taskgraph/run-task/", "test"]
source = ["src/taskgraph/", "src/taskgraph/run-task/", "packages", "test"]

### Lint and Format
[tool.ruff]
Expand All @@ -103,7 +107,7 @@ ignore = [
]

[tool.ruff.lint.isort]
known-first-party = ["taskgraph"]
known-first-party = ["pytest-taskgraph", "taskgraph"]

[tool.pyright]
include = ["src"]
Expand Down
1 change: 1 addition & 0 deletions taskcluster/docker/decision/Dockerfile
Original file line number Diff line number Diff line change
Expand Up @@ -4,6 +4,7 @@ LABEL maintainer="Release Engineering <[email protected]>"
ENV UV_PROJECT_ENVIRONMENT=/setup/taskgraph

# %include src
# %include packages
# %include .hatch_build.py
# %include README.rst
# %include pyproject.toml
Expand Down
5 changes: 2 additions & 3 deletions test/conftest.py
Original file line number Diff line number Diff line change
Expand Up @@ -4,11 +4,10 @@
import pytest
from responses import RequestsMock

from .fixtures.gen import * # noqa
from .fixtures.vcs import * # noqa

here = Path(__file__).parent

pytest_plugins = ("pytest-taskgraph",)

# Disable as much system/user level configuration as we can to avoid
# interference with tests.
# This ignores ~/.hgrc
Expand Down
3 changes: 1 addition & 2 deletions test/test_actions_rebuild_cached_tasks.py
Original file line number Diff line number Diff line change
Expand Up @@ -3,13 +3,12 @@
"""

import pytest
from pytest_taskgraph import make_graph, make_task

from taskgraph import create
from taskgraph.actions import trigger_action_callback
from taskgraph.util import taskcluster as tc_util

from .conftest import make_graph, make_task


@pytest.fixture
def run_action(capsys, mocker, monkeypatch, parameters, graph_config):
Expand Down
3 changes: 1 addition & 2 deletions test/test_generator.py
Original file line number Diff line number Diff line change
Expand Up @@ -4,13 +4,12 @@


import pytest
from pytest_taskgraph import FakeKind, WithFakeKind, fake_load_graph_config

from taskgraph import generator, graph
from taskgraph.generator import Kind, load_tasks_for_kind
from taskgraph.loader.default import loader as default_loader

from .conftest import FakeKind, WithFakeKind, fake_load_graph_config


def test_kind_ordering(maketgg):
"When task kinds depend on each other, they are loaded in postorder"
Expand Down
3 changes: 1 addition & 2 deletions test/test_optimize.py
Original file line number Diff line number Diff line change
Expand Up @@ -6,6 +6,7 @@
from functools import partial

import pytest
from pytest_taskgraph import make_graph, make_task

from taskgraph.graph import Graph
from taskgraph.optimize import base as optimize_mod
Expand All @@ -19,8 +20,6 @@
from taskgraph.task import Task
from taskgraph.taskgraph import TaskGraph

from .conftest import make_graph, make_task


class Remove(OptimizationStrategy):
def should_remove_task(self, task, params, arg):
Expand Down
2 changes: 1 addition & 1 deletion test/test_optimize_strategies.py
Original file line number Diff line number Diff line change
Expand Up @@ -7,9 +7,9 @@
from time import mktime

import pytest
from pytest_taskgraph import make_task

from taskgraph.optimize.strategies import IndexSearch, SkipUnlessChanged
from test.fixtures.gen import make_task


@pytest.fixture
Expand Down
4 changes: 2 additions & 2 deletions test/test_transform_task_context.py
Original file line number Diff line number Diff line change
Expand Up @@ -6,11 +6,11 @@
from copy import deepcopy
from pprint import pprint

from pytest_taskgraph import FakeParameters

from taskgraph.transforms import task_context
from taskgraph.transforms.base import TransformConfig

from .conftest import FakeParameters

here = os.path.abspath(os.path.dirname(__file__))

TASK_DEFAULTS = {
Expand Down
3 changes: 1 addition & 2 deletions test/test_transforms_cached_tasks.py
Original file line number Diff line number Diff line change
Expand Up @@ -2,11 +2,10 @@
from pprint import pprint

import pytest
from pytest_taskgraph import make_task

from taskgraph.transforms import cached_tasks

from .conftest import make_task


def handle_exception(obj, exc=None):
if exc:
Expand Down
3 changes: 1 addition & 2 deletions test/test_transforms_from_deps.py
Original file line number Diff line number Diff line change
Expand Up @@ -5,11 +5,10 @@
from pprint import pprint

import pytest
from pytest_taskgraph import make_task

from taskgraph.transforms import from_deps

from .conftest import make_task


def handle_exception(obj, exc=None):
if exc:
Expand Down
3 changes: 1 addition & 2 deletions test/test_transforms_task.py
Original file line number Diff line number Diff line change
Expand Up @@ -8,12 +8,11 @@
from pprint import pprint

import pytest
from pytest_taskgraph import FakeParameters

from taskgraph.transforms import task
from taskgraph.transforms.base import TransformConfig

from .conftest import FakeParameters

TASK_DEFAULTS = {
"description": "fake description",
"name": "fake-task-name",
Expand Down
4 changes: 2 additions & 2 deletions test/test_util_dependencies.py
Original file line number Diff line number Diff line change
@@ -1,6 +1,6 @@
from taskgraph.util.dependencies import get_dependencies, get_primary_dependency
from pytest_taskgraph import make_task

from .conftest import make_task
from taskgraph.util.dependencies import get_dependencies, get_primary_dependency


def test_get_dependencies(make_transform_config):
Expand Down
3 changes: 1 addition & 2 deletions test/test_util_verify.py
Original file line number Diff line number Diff line change
Expand Up @@ -6,6 +6,7 @@
from itertools import chain

import pytest
from pytest_taskgraph import make_graph, make_task

from taskgraph.task import Task
from taskgraph.util.treeherder import split_symbol
Expand All @@ -16,8 +17,6 @@
verifications,
)

from .conftest import make_graph, make_task


def get_graph():
tasks = [
Expand Down
19 changes: 18 additions & 1 deletion uv.lock

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

0 comments on commit 78810ee

Please sign in to comment.