Thanks to visit codestin.com
Credit goes to github.com

Skip to content
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
Original file line number Diff line number Diff line change
Expand Up @@ -67,18 +67,18 @@ def test_all_examples_are_runnable(mocker, settings, with_crd, exampledir, caplo
# There are usually more than these messages, but we only check for the certain ones.
# This just shows us that the operator is doing something, it is alive.
if e2e.has_mandatory_on_delete:
assert '[default/kopf-example-1] Adding the finalizer' in runner.stdout
assert '[default/kopf-example-1] Adding the finalizer' in runner.output
if e2e.has_on_create:
assert '[default/kopf-example-1] Creation is in progress:' in runner.stdout
assert '[default/kopf-example-1] Creation is in progress:' in runner.output
if e2e.has_mandatory_on_delete:
assert '[default/kopf-example-1] Deletion is in progress:' in runner.stdout
assert '[default/kopf-example-1] Deletion is in progress:' in runner.output
if e2e.has_changing_handlers:
assert '[default/kopf-example-1] Deleted, really deleted' in runner.stdout
assert '[default/kopf-example-1] Deleted, really deleted' in runner.output
if not e2e.allow_tracebacks:
assert 'Traceback (most recent call last):' not in runner.stdout
assert 'Traceback (most recent call last):' not in runner.output

# Verify that once a handler succeeds, it is never re-executed again.
handler_names = re.findall(r"'(.+?)' succeeded", runner.stdout)
handler_names = re.findall(r"'(.+?)' succeeded", runner.output)
if e2e.success_counts is not None:
checked_names = [name for name in handler_names if name in e2e.success_counts]
name_counts = collections.Counter(checked_names)
Expand All @@ -88,7 +88,7 @@ def test_all_examples_are_runnable(mocker, settings, with_crd, exampledir, caplo
assert set(name_counts.values()) == {1}

# Verify that once a handler fails, it is never re-executed again.
handler_names = re.findall(r"'(.+?)' failed (?:permanently|with an exception. Will stop.)", runner.stdout)
handler_names = re.findall(r"'(.+?)' failed (?:permanently|with an exception. Will stop.)", runner.output)
if e2e.failure_counts is not None:
checked_names = [name for name in handler_names if name in e2e.failure_counts]
name_counts = collections.Counter(checked_names)
Expand Down
Loading