tests.conftest module¶

Shared pytest fixtures and cross-file test helpers.

tests.conftest.PROJECT_ROOT = PosixPath('/home/runner/work/repomatic/repomatic')¶

Root of the repository.

tests.conftest.IN_GIT_CHECKOUT = True¶

Whether the suite runs from a git checkout, not from an sdist or a tag tarball.

A packager’s source carries no git history, holds a release’s frozen workflows, and, for an sdist, a pyproject.toml rewritten and symlinks dereferenced by the build backend. The tests marked repo_maintenance check those properties of a development checkout, so pytest_collection_modifyitems() skips them everywhere else.

tests.conftest.PACKAGE_DIR = PosixPath('/home/runner/work/repomatic/repomatic/repomatic')¶

Root of the package whose sources the conformance tests scan.

tests.conftest.PACKAGE_FILES = [PosixPath('/home/runner/work/repomatic/repomatic/repomatic/__init__.py'), PosixPath('/home/runner/work/repomatic/repomatic/repomatic/__main__.py'), PosixPath('/home/runner/work/repomatic/repomatic/repomatic/awesome_toc.py'), PosixPath('/home/runner/work/repomatic/repomatic/repomatic/broken_links.py'), PosixPath('/home/runner/work/repomatic/repomatic/repomatic/bundle.py'), PosixPath('/home/runner/work/repomatic/repomatic/repomatic/cache.py'), PosixPath('/home/runner/work/repomatic/repomatic/repomatic/changelog.py'), PosixPath('/home/runner/work/repomatic/repomatic/repomatic/checks.py'), PosixPath('/home/runner/work/repomatic/repomatic/repomatic/claude_plugin.py'), PosixPath('/home/runner/work/repomatic/repomatic/repomatic/cli/__init__.py'), PosixPath('/home/runner/work/repomatic/repomatic/repomatic/cli/ci.py'), PosixPath('/home/runner/work/repomatic/repomatic/repomatic/cli/deps.py'), PosixPath('/home/runner/work/repomatic/repomatic/repomatic/cli/github.py'), PosixPath('/home/runner/work/repomatic/repomatic/repomatic/cli/main.py'), PosixPath('/home/runner/work/repomatic/repomatic/repomatic/cli/release.py'), PosixPath('/home/runner/work/repomatic/repomatic/repomatic/cli/repo.py'), PosixPath('/home/runner/work/repomatic/repomatic/repomatic/cli/site.py'), PosixPath('/home/runner/work/repomatic/repomatic/repomatic/cli/tools.py'), PosixPath('/home/runner/work/repomatic/repomatic/repomatic/cloudflare/__init__.py'), PosixPath('/home/runner/work/repomatic/repomatic/repomatic/cloudflare/api.py'), PosixPath('/home/runner/work/repomatic/repomatic/repomatic/cloudflare/pages.py'), PosixPath('/home/runner/work/repomatic/repomatic/repomatic/cloudflare/r2.py'), PosixPath('/home/runner/work/repomatic/repomatic/repomatic/cloudflare/redirects.py'), PosixPath('/home/runner/work/repomatic/repomatic/repomatic/components.py'), PosixPath('/home/runner/work/repomatic/repomatic/repomatic/config.py'), PosixPath('/home/runner/work/repomatic/repomatic/repomatic/data/__init__.py'), PosixPath('/home/runner/work/repomatic/repomatic/repomatic/data/awesome_template/__init__.py'), PosixPath('/home/runner/work/repomatic/repomatic/repomatic/deps/__init__.py'), PosixPath('/home/runner/work/repomatic/repomatic/repomatic/deps/audit.py'), PosixPath('/home/runner/work/repomatic/repomatic/repomatic/deps/cooldown.py'), PosixPath('/home/runner/work/repomatic/repomatic/repomatic/deps/graph.py'), PosixPath('/home/runner/work/repomatic/repomatic/repomatic/deps/lockfile.py'), PosixPath('/home/runner/work/repomatic/repomatic/repomatic/deps/pins.py'), PosixPath('/home/runner/work/repomatic/repomatic/repomatic/deps/policy.py'), PosixPath('/home/runner/work/repomatic/repomatic/repomatic/deps/provenance.py'), PosixPath('/home/runner/work/repomatic/repomatic/repomatic/deps/report.py'), PosixPath('/home/runner/work/repomatic/repomatic/repomatic/deps/requirements.py'), PosixPath('/home/runner/work/repomatic/repomatic/repomatic/deps/shippable.py'), PosixPath('/home/runner/work/repomatic/repomatic/repomatic/deps/sources.py'), PosixPath('/home/runner/work/repomatic/repomatic/repomatic/deps/sync.py'), PosixPath('/home/runner/work/repomatic/repomatic/repomatic/deps/uv.py'), PosixPath('/home/runner/work/repomatic/repomatic/repomatic/docs.py'), PosixPath('/home/runner/work/repomatic/repomatic/repomatic/file_inventory.py'), PosixPath('/home/runner/work/repomatic/repomatic/repomatic/file_ops.py'), PosixPath('/home/runner/work/repomatic/repomatic/repomatic/frontmatter.py'), PosixPath('/home/runner/work/repomatic/repomatic/repomatic/git_ops.py'), PosixPath('/home/runner/work/repomatic/repomatic/repomatic/github/__init__.py'), PosixPath('/home/runner/work/repomatic/repomatic/repomatic/github/caches.py'), PosixPath('/home/runner/work/repomatic/repomatic/repomatic/github/ci_status.py'), PosixPath('/home/runner/work/repomatic/repomatic/repomatic/github/dev_release.py'), PosixPath('/home/runner/work/repomatic/repomatic/repomatic/github/event.py'), PosixPath('/home/runner/work/repomatic/repomatic/repomatic/github/gh.py'), PosixPath('/home/runner/work/repomatic/repomatic/repomatic/github/issue.py'), PosixPath('/home/runner/work/repomatic/repomatic/repomatic/github/job_timings.py'), PosixPath('/home/runner/work/repomatic/repomatic/repomatic/github/labels.py'), PosixPath('/home/runner/work/repomatic/repomatic/repomatic/github/outputs.py'), PosixPath('/home/runner/work/repomatic/repomatic/repomatic/github/pr.py'), PosixPath('/home/runner/work/repomatic/repomatic/repomatic/github/pr_body.py'), PosixPath('/home/runner/work/repomatic/repomatic/repomatic/github/release_sync.py'), PosixPath('/home/runner/work/repomatic/repomatic/repomatic/github/releases.py'), PosixPath('/home/runner/work/repomatic/repomatic/repomatic/github/runs.py'), PosixPath('/home/runner/work/repomatic/repomatic/repomatic/github/sponsor.py'), PosixPath('/home/runner/work/repomatic/repomatic/repomatic/github/status.py'), PosixPath('/home/runner/work/repomatic/repomatic/repomatic/github/threads.py'), PosixPath('/home/runner/work/repomatic/repomatic/repomatic/github/token.py'), PosixPath('/home/runner/work/repomatic/repomatic/repomatic/github/unsubscribe.py'), PosixPath('/home/runner/work/repomatic/repomatic/repomatic/github/urls.py'), PosixPath('/home/runner/work/repomatic/repomatic/repomatic/github/workflow_files.py'), PosixPath('/home/runner/work/repomatic/repomatic/repomatic/github/workflow_sync.py'), PosixPath('/home/runner/work/repomatic/repomatic/repomatic/gitignore.py'), PosixPath('/home/runner/work/repomatic/repomatic/repomatic/hashing.py'), PosixPath('/home/runner/work/repomatic/repomatic/repomatic/http.py'), PosixPath('/home/runner/work/repomatic/repomatic/repomatic/humanize.py'), PosixPath('/home/runner/work/repomatic/repomatic/repomatic/images.py'), PosixPath('/home/runner/work/repomatic/repomatic/repomatic/init/__init__.py'), PosixPath('/home/runner/work/repomatic/repomatic/repomatic/init/local_edits.py'), PosixPath('/home/runner/work/repomatic/repomatic/repomatic/init/removed_assets.py'), PosixPath('/home/runner/work/repomatic/repomatic/repomatic/init/run.py'), PosixPath('/home/runner/work/repomatic/repomatic/repomatic/init/tool_config.py'), PosixPath('/home/runner/work/repomatic/repomatic/repomatic/init/upgrade.py'), PosixPath('/home/runner/work/repomatic/repomatic/repomatic/lint_changelog.py'), PosixPath('/home/runner/work/repomatic/repomatic/repomatic/lint_repo/__init__.py'), PosixPath('/home/runner/work/repomatic/repomatic/repomatic/lint_repo/context.py'), PosixPath('/home/runner/work/repomatic/repomatic/repomatic/lint_repo/pins.py'), PosixPath('/home/runner/work/repomatic/repomatic/repomatic/lint_repo/repo.py'), PosixPath('/home/runner/work/repomatic/repomatic/repomatic/lint_repo/roster.py'), PosixPath('/home/runner/work/repomatic/repomatic/repomatic/lint_repo/settings.py'), PosixPath('/home/runner/work/repomatic/repomatic/repomatic/lint_repo/site.py'), PosixPath('/home/runner/work/repomatic/repomatic/repomatic/lint_repo/tool_config.py'), PosixPath('/home/runner/work/repomatic/repomatic/repomatic/lint_repo/workflows.py'), PosixPath('/home/runner/work/repomatic/repomatic/repomatic/mailmap.py'), PosixPath('/home/runner/work/repomatic/repomatic/repomatic/markdown.py'), PosixPath('/home/runner/work/repomatic/repomatic/repomatic/matrix/__init__.py'), PosixPath('/home/runner/work/repomatic/repomatic/repomatic/matrix/axes.py'), PosixPath('/home/runner/work/repomatic/repomatic/repomatic/matrix/model.py'), PosixPath('/home/runner/work/repomatic/repomatic/repomatic/matrix/runner_sync.py'), PosixPath('/home/runner/work/repomatic/repomatic/repomatic/matrix/runners.py'), PosixPath('/home/runner/work/repomatic/repomatic/repomatic/metadata/__init__.py'), PosixPath('/home/runner/work/repomatic/repomatic/repomatic/metadata/core.py'), PosixPath('/home/runner/work/repomatic/repomatic/repomatic/metadata/env.py'), PosixPath('/home/runner/work/repomatic/repomatic/repomatic/metadata/git.py'), PosixPath('/home/runner/work/repomatic/repomatic/repomatic/metadata/matrix.py'), PosixPath('/home/runner/work/repomatic/repomatic/repomatic/metadata/output.py'), PosixPath('/home/runner/work/repomatic/repomatic/repomatic/metadata/project.py'), PosixPath('/home/runner/work/repomatic/repomatic/repomatic/metrics/__init__.py'), PosixPath('/home/runner/work/repomatic/repomatic/repomatic/metrics/chart.py'), PosixPath('/home/runner/work/repomatic/repomatic/repomatic/metrics/forge.py'), PosixPath('/home/runner/work/repomatic/repomatic/repomatic/metrics/store.py'), PosixPath('/home/runner/work/repomatic/repomatic/repomatic/npm.py'), PosixPath('/home/runner/work/repomatic/repomatic/repomatic/pypi.py'), PosixPath('/home/runner/work/repomatic/repomatic/repomatic/pyproject.py'), PosixPath('/home/runner/work/repomatic/repomatic/repomatic/release/__init__.py'), PosixPath('/home/runner/work/repomatic/repomatic/repomatic/release/attestation.py'), PosixPath('/home/runner/work/repomatic/repomatic/repomatic/release/binaries_page.py'), PosixPath('/home/runner/work/repomatic/repomatic/repomatic/release/binary.py'), PosixPath('/home/runner/work/repomatic/repomatic/repomatic/release/manpages.py'), PosixPath('/home/runner/work/repomatic/repomatic/repomatic/release/prepare_release.py'), PosixPath('/home/runner/work/repomatic/repomatic/repomatic/release/protocol.py'), PosixPath('/home/runner/work/repomatic/repomatic/repomatic/release/self_pin.py'), PosixPath('/home/runner/work/repomatic/repomatic/repomatic/release/verify.py'), PosixPath('/home/runner/work/repomatic/repomatic/repomatic/release/virustotal.py'), PosixPath('/home/runner/work/repomatic/repomatic/repomatic/setup_guide.py'), PosixPath('/home/runner/work/repomatic/repomatic/repomatic/skills.py'), PosixPath('/home/runner/work/repomatic/repomatic/repomatic/tabular.py'), PosixPath('/home/runner/work/repomatic/repomatic/repomatic/templates/__init__.py'), PosixPath('/home/runner/work/repomatic/repomatic/repomatic/templating.py'), PosixPath('/home/runner/work/repomatic/repomatic/repomatic/tooling/__init__.py'), PosixPath('/home/runner/work/repomatic/repomatic/repomatic/tooling/binaries.py'), PosixPath('/home/runner/work/repomatic/repomatic/repomatic/tooling/checksums.py'), PosixPath('/home/runner/work/repomatic/repomatic/repomatic/tooling/nuitka.py'), PosixPath('/home/runner/work/repomatic/repomatic/repomatic/tooling/registry.py'), PosixPath('/home/runner/work/repomatic/repomatic/repomatic/tooling/runner.py'), PosixPath('/home/runner/work/repomatic/repomatic/repomatic/upstream.py'), PosixPath('/home/runner/work/repomatic/repomatic/repomatic/versions.py')]¶

Every Python module shipped in the package.

Sorted because @pytest.mark.parametrize derives test IDs from iteration order, and pytest-xdist aborts a run whose workers disagree on them.

tests.conftest.SITE_ANCHOR_RE = re.compile('https://repomatic\\.net/(?P<page>[\\w-]+)#(?P<anchor>[\\w-]+)')¶

A link into one section of the published documentation.

tests.conftest.WORKFLOWS_DIR = PosixPath('/home/runner/work/repomatic/repomatic/.github/workflows')¶

Directory holding this repository’s own workflow files.

tests.conftest.REAL_HTTP_MARKER = 'real_http'¶

Marks a test that runs a registry tool for real, downloads included.

The _no_real_http fixture leaves such a test alone, so the probe of skip_unless_tool_runs() can download the pinned binary on a cold cache. tests/test_suite_hygiene.py holds every caller of that probe to the marker.

tests.conftest.docs_heading_slug(title)[source]¶

The anchor the published Sphinx site derives from a heading.

Follows the docutils section-id algorithm (lowercase, every non-alphanumeric run collapsed to one hyphen, trimmed), which is what the published page exposes as id= attributes.

Parameters:

title (str) – Heading text, without its leading # marks.

Return type:

str

tests.conftest.docs_heading_anchors(page)[source]¶

Anchors a page of docs/ exposes: heading slugs and explicit targets.

Heading slugs follow docs_heading_slug().

Parameters:

page (str) – Name of the page, without its .md extension.

Return type:

set[str]

tests.conftest.assert_shipped_text_reads_true_downstream(origin, text)[source]¶

Check a text that travels downstream cites nothing a repository lacks.

A bundled configuration and a generated workflow comment both land in repositories that hold no copy of this project’s AGENTS.md: the agent component that shipped its sections retired in 7.14.0. A pointer to that file is a dead end there. So such a text states its rationale inline, or cites a section of the published documentation, whose anchor is held here to a heading that exists.

Parameters:
  • origin (str) – Name of the text under test, for the failure message.

  • text (str) – Content as it ships.

Return type:

None

tests.conftest.pytest_configure(config)[source]¶

Register the markers local to this suite.

Not in [tool.pytest] markers, which must match the template bundled in repomatic/data/pytest.toml.

Return type:

None

tests.conftest.pytest_collection_modifyitems(config, items)[source]¶

Skip the repo_maintenance tests outside a git checkout.

See IN_GIT_CHECKOUT.

Return type:

None

tests.conftest.WORKFLOWS_WITH_CONCURRENCY_BLOCK = ('autofix.yaml', 'changelog.yaml', 'debug.yaml', 'docs.yaml', 'labels.yaml', 'lint.yaml', 'metrics.yaml', 'release.yaml', 'self-maintenance.yaml', 'tests.yaml')¶

Workflows that actually define a concurrency block, read off disk.

Derived rather than hand-listed because two test modules assert against it from opposite directions, and a hand-listed pair drifted apart once already: a workflow can be exempt from the requirement and still carry a block, which no list of intentions can express.

tests.conftest.WORKFLOWS_WITHOUT_CONCURRENCY_BLOCK = ('_release-build.yaml', '_release-engine.yaml', 'autolock.yaml', 'cancel-runs.yaml', 'unsubscribe.yaml')¶

The complement of WORKFLOWS_WITH_CONCURRENCY_BLOCK.

tests.conftest.skip_unless_tool_runs(name)[source]¶

Skip the calling test when a registry tool cannot run on this machine.

A test that lints generated output reads the tool’s verdict off its exit code, and a uvx resolution that fails offline exits non-zero too. Probing with --version first keeps the two apart, so whatever the real invocation returns afterwards is the tool’s opinion of the content rather than a fetch failure misread as a defect in the generator.

The probe installs the tool, and a binary tool or companion downloads through repomatic.http on a cold cache. The caller carries the REAL_HTTP_MARKER marker so _no_real_http lets that download through: CI starts from a cold cache, and it is the enforcement point.

Only a developer with no network ever takes the skip. A failed download, a platform the tool publishes no binary for, and a missing uvx all skip.

Parameters:

name (str) – Registry key of the tool the caller is about to invoke.

Return type:

None

tests.conftest.load_workflow(workflow_name)[source]¶

Load and parse one of this repository’s workflow YAML files.

The one loader behind every test that reads a workflow off disk, so they all parse the same bytes the same way.

Return type:

dict[str, Any]

tests.conftest.requested_metadata_keys(command, package)[source]¶

Positional keys a shell command passes to the show-metadata subcommand.

Built on the reader unknown_metadata_keys runs in production, for the tests that hold the workflows to the keys they request. A call of the removed metadata alias requests nothing, since the command it names no longer exists.

Parameters:
  • command (str) – The step’s run: script, folded or literal.

  • package (str) – Upstream package name (like repomatic).

Return type:

list[str]

Returns:

The key names requested, in the order written.

tests.conftest.hermetic_git(monkeypatch)[source]¶

Shield temporary git repos from the developer’s own git configuration.

Commit signing, hooks, templates and identity from the global or system config would otherwise leak into repos a test builds under tmp_path and break hermeticity in machine-specific ways.

tests.conftest.scrub_workflow_event(monkeypatch)[source]¶

Detach a test from the CI run’s own workflow event.

In CI the suite inherits the real run’s GITHUB_EVENT_NAME, event payload and GITHUB_SHA, which event-derived properties (event_type, commit_range, the canary gating of nuitka_matrix) read, so expectations would differ between CI and a local run. Deleting the event markers pins a test to the deterministic local behavior; a test of the CI context sets the variables back with monkeypatch.setenv.

tests.conftest.run_git(*args, cwd)[source]¶

Run a git command in cwd and return its stdout.

Return type:

str

tests.conftest.seed_commit(workdir, filename, content, message)[source]¶

Create a file and commit it with a throwaway identity.

Return type:

None

tests.conftest.SHALLOW_HISTORY = ('apple', 'banana', 'cherry', 'date', 'elderberry')¶

Content of the successive commits make_shallow_clone() pushes.

tests.conftest.make_shallow_clone(tmp_path)[source]¶

Clone a remote holding one commit per SHALLOW_HISTORY entry.

The clone is one commit deep. The remote serves any commit it can reach by SHA, as GitHub does, so a commit outside the clone can be fetched alone.

Return type:

tuple[Path, list[str]]

Returns:

The clone, and the SHAs of the remote’s commits, oldest first.

class tests.conftest.FakeResponse(data, *, status=200, headers=None)[source]¶

Bases: object

Minimal urlopen response double: a byte body behind a context manager.

Stands in for the object repomatic.http.request() reads, so network tests patch repomatic.http.urlopen with return_value=FakeResponse(...).

read()[source]¶
Return type:

bytes

class tests.conftest.CutShortBody(initial_bytes=b'')[source]¶

Bases: BytesIO

The body of an error answer whose connection drops mid-read.

read(*args)[source]¶

Read at most size bytes, returned as a bytes object.

If the size argument is negative, read until EOF is reached. Return an empty bytes object at EOF.

Return type:

bytes

tests.conftest.pat_results(**overrides)[source]¶

Build a PatPermissionResults where every check passes by default.

Each keyword names a PatPermissionResults field and replaces its (passed, message) pair, so a test spells out only the checks whose outcome it cares about and the rest read as the happy path.

Parameters:

overrides (tuple[bool, str]) – Field name to its (passed, message) result.

Return type:

PatPermissionResults

Returns:

The assembled results object.

tests.conftest.metadata_from_pyproject(tmp_path, monkeypatch, content)[source]¶

Build a Metadata reading a throwaway pyproject.toml holding content.

Repointing Metadata.pyproject_path is what isolates the instance from the repository’s own pyproject.toml: the class reads that path lazily, so the patch has to be in place before the first property is touched. The autouse _reset_metadata fixture clears the cached values afterwards.

Parameters:
  • tmp_path (Path) – Directory to write the file into.

  • monkeypatch – The test’s monkeypatch fixture.

  • content (str) – Full pyproject.toml source.

Return type:

Metadata

Returns:

A Metadata bound to the written file.

tests.conftest.cache_env(monkeypatch, tmp_path)[source]¶

Point the repomatic cache at a per-test directory, auto-purge disabled.

Returns the cache root path so tests can assert on its contents.

tests.conftest.patch_gh(module, **mock_kwargs)[source]¶

Patch a module’s gh dispatch points with one shared mock.

Read paths go through gh_json (which calls the gh module’s run_gh_command) while write paths call the name imported into module directly; patching both with the same mock keeps a test’s single call sequence intact across the two layers. Bind the module with functools.partial for a per-file shorthand.

tests.conftest.attribute_docstrings(body)[source]¶

Yield (line, owner, text) for each attribute docstring in body.

An attribute docstring is the bare string literal following an assignment. ast.get_docstring cannot see one, yet it is this project’s convention for documenting a dataclass field or a module constant, and automodule ... :undoc-members: renders it.

tests.conftest.write_bundle(path, *subjects)[source]¶

Write a sigstore bundle attesting subjects.

Mirrors the shape actions/attest emits: a DSSE envelope whose base64 payload is an in-toto statement listing one entry per attested file.

Return type:

Path

tests.conftest.MULTI_RELEASE_CHANGELOG = '# Changelog\n\n## [2.0.0 (unreleased)](https://github.com/user/repo/compare/v1.1.0...main)\n\n> [!WARNING]\n> This version is **not released yet** and is under active development.\n\n## [1.1.0 (2026-02-10)](https://github.com/user/repo/compare/v1.0.0...v1.1.0)\n\n- Second release.\n\n## [1.0.0 (2025-12-01)](https://github.com/user/repo/compare/v0.9.0...v1.0.0)\n\n- Initial release.\n'¶

Changelog with multiple released versions and one unreleased.

tests.conftest.SHT_STRTAB = 3¶

ELF section type of a string table.

tests.conftest.make_elf(machine, versions=(), *, wide=True, big_endian=False, extended_numbering=False)[source]¶

Craft a minimal ELF file, requiring versions of libc when given.

Without versions the file holds a bare header and no section table. With them it carries a .dynstr string table and a .gnu.version_r section naming each one under a single libc.so.6 requirement, the way the linker writes them. wide picks ELF64 over ELF32, and big_endian the byte order, as the identification bytes declare them. extended_numbering moves the section count out of e_shnum into the sh_size of entry 0, the encoding a file with 0xff00 sections or more has to use.

Return type:

bytes

tests.conftest.pack_macho_version(version)[source]¶

Pack a major.minor string into a Mach-O version integer.

Return type:

int

tests.conftest.make_macho(cpu_type, min_os='11.0')[source]¶

Craft a minimal 64-bit Mach-O header with one LC_BUILD_VERSION command.

Return type:

bytes

tests.conftest.make_fat(slices)[source]¶

Wrap Mach-O slices into a universal (fat) container.

Return type:

bytes

tests.conftest.make_pe(machine)[source]¶

Craft a minimal PE header exposing only the COFF machine type.

Return type:

bytes

tests.conftest.macho_cpu_type(arch)[source]¶

The Mach-O cputype for an architecture, read for the byte builders.

MACHINE_IDS spans every format. These two accessors name the format for the helpers below, which write real header bytes.

Return type:

int

tests.conftest.pe_machine_id(arch)[source]¶

The PE COFF Machine value for an architecture.

Return type:

int