Skip to content

Commit

Permalink
Merge pull request pulp#100 from mdellweg/update_tests
Browse files Browse the repository at this point in the history
Modernize test infrastructure
  • Loading branch information
quba42 authored Feb 20, 2024
2 parents f9e3399 + 04dfae5 commit a846e99
Show file tree
Hide file tree
Showing 3 changed files with 55 additions and 23 deletions.
21 changes: 11 additions & 10 deletions releasing.md
Original file line number Diff line number Diff line change
Expand Up @@ -2,14 +2,15 @@ _taken from `pulp-cli` [repository](https://github.com/pulp/pulp-cli/blob/main/r

# Releasing (for internal use)

1. Run `pip install bump2version towncrier==19.9.0 .` (see also the `pulp_deb` release CI)
1. Run `bumpversion release`.
1. Generate the changelog (`towncrier --yes`).
1. Check and fix the changelog according to markdown formatting and language conventions.
1. Commit your local changes with commit message "Release 0.1.0".
1. Run `bumpversion minor` to update the version to the next dev release version and commit with "Bump version to 0.2.0.dev".
1. Push your commits, open a PR, and get it merged.
1. After your PR is merged, pull the latest changes from develop.
1. Now tag your release commit (e.g. `git tag -s 0.1.0`) and push to pulp/pulp-cli.
1. Monitor the build job and then check PyPI to make sure the package has been uploaded and the docs updated.
## Create new y-Release Branch

1. Trigger the [Create Release Branch](https://github.com/pulp/pulp-cli-deb/actions/workflows/release_branch.yml) action.
1. Review (if need to, repair) and merge the "Bumb Version" PR.

## Create a new Release from a Release Branch

1. Trigger the [pulp-cli Release](https://github.com/pulp/pulp-cli-deb/actions/workflows/release.yml) action with the release branch selected.
1. Monitor the release and build jobs and then check PyPI to make sure the package has been uploaded and the docs updated.
1. Announce the release at https://discourse.pulpproject.org/c/announcements/6.
1. Wait for nightlies (or trigger the [collect changes][https://github.com/pulp/pulp-cli-deb/actions/workflows/collect_changes.yml] workflow) to pickup new changelogs.
1. Review (if need to, repair) and merge the "Update Changelog" PR.
6 changes: 4 additions & 2 deletions test_requirements.txt
Original file line number Diff line number Diff line change
@@ -1,2 +1,4 @@
pytest
python-gnupg
# Test requirements
pytest>=7.0.0,<9.0.0
pytest-subtests>=0.8.0,<0.12.0
python-gnupg==0.5.2
51 changes: 40 additions & 11 deletions tests/test_help_pages.py
Original file line number Diff line number Diff line change
@@ -1,6 +1,4 @@
# type: ignore

from unittest.mock import PropertyMock, patch
import typing as t

import click
import pytest
Expand All @@ -14,20 +12,51 @@
from pulpcore.cli.common import main


def traverse_commands(command, args):
# Workaround for missing type annotations.
# from pytest_subtests.plugin import SubTests
SubTests = t.Any


def traverse_commands(command: click.Command, args: t.List[str]) -> t.Iterator[t.List[str]]:
yield args

if isinstance(command, click.Group):
for name, sub in command.commands.items():
yield from traverse_commands(sub, args + [name])

params = command.params
if params:
if "--type" in params[0].opts:
# iterate over commands with specific context types
assert isinstance(params[0].type, click.Choice)
for context_type in params[0].type.choices:
yield args + ["--type", context_type]

for name, sub in command.commands.items():
yield from traverse_commands(sub, args + ["--type", context_type, name])


@pytest.fixture
def no_api(monkeypatch: pytest.MonkeyPatch) -> None:
@property # type: ignore
def getter(self: t.Any) -> None:
pytest.fail("Invalid access to 'PulpContext.api'.", pytrace=False)

monkeypatch.setattr("pulp_glue.common.context.PulpContext.api", getter)


@pytest.mark.help_page
@pytest.mark.parametrize("args", traverse_commands(main.commands["deb"], ["deb"]), ids=" ".join)
@patch("pulpcore.cli.common.context.PulpContext.api", new_callable=PropertyMock)
def test_access_help(_api, args):
def test_access_help(no_api: None, subtests: SubTests) -> None:
"""Test, that all help screens are accessible without touching the api property."""
runner = CliRunner()
result = runner.invoke(main, args + ["--help"])
assert result.exit_code == 0
assert result.stdout.startswith("Usage:") or result.stdout.startswith("DeprecationWarning:")
_api.assert_not_called()
for args in traverse_commands(main, []):
with subtests.test(msg=" ".join(args)):
result = runner.invoke(main, args + ["--help"], catch_exceptions=False)

if result.exit_code == 2:
assert "not available in this context" in result.stdout
else:
assert result.exit_code == 0
assert result.stdout.startswith("Usage:") or result.stdout.startswith(
"DeprecationWarning:"
)

0 comments on commit a846e99

Please sign in to comment.