8000 Work around changes in Click 8.2.0 by nolar · Pull Request #1174 · nolar/kopf · GitHub
[go: up one dir, main page]
More Web Proxy on the site http://driver.im/
Skip to content

Work around changes in Click 8.2.0 #1174

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

Merged
merged 2 commits into from
May 12, 2025
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
4 changes: 2 additions & 2 deletions docs/testing.rst
Original file line number Diff line number Diff line change
Expand Up @@ -34,8 +34,8 @@ exit code and output are available to the test (for additional assertions).

assert runner.exit_code == 0
assert runner.exception is None
assert 'And here we are!' in runner.stdout
assert 'Deleted, really deleted' in runner.stdout
assert 'And here we are!' in runner.output
assert 'Deleted, really deleted' in runner.output

.. note::
The operator runs against the cluster which is currently authenticated ---
Expand Down
4 changes: 2 additions & 2 deletions examples/09-testing/test_example_09.py
Original file line number Diff line number Diff line change
Expand Up @@ -51,5 +51,5 @@ def test_resource_lifecycle():
assert runner.exit_code == 0

# There are usually more than these messages, but we only check for the certain ones.
assert '[default/kopf-example-1] Creation is in progress:' in runner.stdout
assert '[default/kopf-example-1] Something was logged here.' in runner.stdout
assert '[default/kopf-example-1] Creation is in progress:' in runner.output
assert '[default/kopf-example-1] Something was logged here.' in runner.output
8 changes: 4 additions & 4 deletions examples/10-builtins/test_example_10.py
Original file line number Diff line number Diff line change
Expand Up @@ -19,10 +19,10 @@ def test_pods_reacted():
assert runner.exception is None
assert runner.exit_code == 0

assert f'[default/{name}] Creation is in progress:' in runner.stdout
assert f'[default/{name}] === Pod killing happens in 30s.' in runner.stdout
assert f'[default/{name}] Deletion is in progress:' in runner.stdout
assert f'[default/{name}] === Pod killing is cancelled!' in runner.stdout
assert f'[default/{name}] Creation is in progress:' in runner.output
assert f'[default/{name}] === Pod killing happens in 30s.' in runner.output
assert f'[default/{name}] Deletion is in progress:' in runner.output
assert f'[default/{name}] === Pod killing is cancelled!' in runner.output


def _create_pod():
Expand Down
32 changes: 16 additions & 16 deletions examples/11-filtering-handlers/test_example_11.py
Original file line number Diff line number Diff line change
Expand Up @@ -54,19 +54,19 @@ def test_handler_filtering():
assert runner.exit_code == 0

# Check for correct log lines (to indicate correct handlers were executed).
assert '[default/kopf-example-1] Label is matching.' in runner.stdout
assert '[default/kopf-example-1] Label is present.' in runner.stdout
assert '[default/kopf-example-1] Label is absent.' in runner.stdout
assert '[default/kopf-example-1] Label callback matching.' in runner.stdout
assert '[default/kopf-example-1] Annotation is matching.' in runner.stdout
assert '[default/kopf-example-1] Annotation is present.' in runner.stdout
assert '[default/kopf-example-1] Annotation is absent.' in runner.stdout
assert '[default/kopf-example-1] Annotation callback mismatch.' not in runner.stdout
assert '[default/kopf-example-1] Filter satisfied.' in runner.stdout
assert '[default/kopf-example-1] Filter not satisfied.' not in runner.stdout
assert '[default/kopf-example-1] Field value is satisfied.' in runner.stdout
assert '[default/kopf-example-1] Field value is not satisfied.' not in runner.stdout
assert '[default/kopf-example-1] Field presence is satisfied.' in runner.stdout
assert '[default/kopf-example-1] Field presence is not satisfied.' not in runner.stdout
assert '[default/kopf-example-1] Field change is satisfied.' in runner.stdout
assert '[default/kopf-example-1] Field daemon is satisfied.' in runner.stdout
assert '[default/kopf-example-1] Label is matching.' in runner.output
assert '[default/kopf-example-1] Label is present.' in runner.output
assert '[default/kopf-example-1] Label is absent.' in runner.output
assert '[default/kopf-example-1] Label callback matching.' in runner.output
assert '[default/kopf-example-1] Annotation is matching.' in runner.output
assert '[default/kopf-example-1] Annotation is present.' in runner.output
assert '[default/kopf-example-1] Annotation is absent.' in runner.output
assert '[default/kopf-example-1] Annotation callback mismatch.' not in runner.output
assert '[default/kopf-example-1] Filter satisfied.' in runner.output
assert '[default/kopf-example-1] Filter not satisfied.' not in runner.output
assert '[default/kopf-example-1] Field value is satisfied.' in runner.output
assert '[default/kopf-example-1] Field value is not satisfied.' not in runner.output
assert '[default/kopf-example-1] Field presence is satisfied.' in runner.output
assert '[default/kopf-example-1] Field presence is not satisfied.' not in runner.output
assert '[default/kopf-example-1] Field change is satisfied.' in runner.output
assert '[default/kopf-example-1] Field daemon is satisfied.' in runner.output
2 changes: 1 addition & 1 deletion kopf/_kits/runner.py
Original file line number Diff line number Diff line change
Expand Up @@ -38,7 +38,7 @@ class KopfRunner(_AbstractKopfRunner):

assert runner.exit_code == 0
assert runner.exception is None
assert 'And here we are!' in runner.stdout
assert 'And here we are!' in runner.output

All the args & kwargs are passed directly to Click's invocation method.
See: `click.testing.CliRunner`.
Expand Down
5 changes: 4 additions & 1 deletion kopf/cli.py
Original file line number Diff line number Diff line change
Expand Up @@ -29,7 +29,10 @@ class CLIControls:
loop: Optional[asyncio.AbstractEventLoop] = None


class LogFormatParamType(click.Choice):
# With Click>=8.2.0, that should be `click.Choice[LogFormat]`, but it is good for now, too.
# TODO: when Python 3.9 is dropped, upgrade dependencies to click>=8.2.0, and remake the class here.
# see: https://github.com/nolar/kopf/pull/1174
class LogFormatParamType(click.Choice): # type: ignore

def __init__(self) -> None:
super().__init__(choices=[v.name.lower() for v in loggers.LogFormat])
Expand Down
14 changes: 7 additions & 7 deletions tests/e2e/test_examples.py