From 3a41cfe71de71a0a53416c68979d5e77f77de503 Mon Sep 17 00:00:00 2001 From: Sergey Vasilyev Date: Fri, 7 Feb 2020 16:12:38 +0100 Subject: [PATCH] Deprecate the proxying methods of registries --- kopf/reactor/registries.py | 57 ++++++++ .../legacy-1/test_legacy1_handler_matching.py | 3 +- .../legacy-1/test_legacy1_id_detection.py | 15 ++- .../legacy-1/test_legacy1_registering.py | 3 +- .../test_legacy1_requires_finalizer.py | 21 ++- .../legacy-2/test_legacy2_decorators.py | 64 ++++++--- .../legacy-2/test_legacy2_handler_matching.py | 123 ++++++++++++------ .../test_legacy2_operator_resources.py | 15 ++- .../legacy-2/test_legacy2_registering.py | 39 ++++-- .../test_legacy2_requires_finalizer.py | 21 ++- .../legacy-2/test_legacy2_resumes_mixed_in.py | 12 +- 11 files changed, 272 insertions(+), 101 deletions(-) diff --git a/kopf/reactor/registries.py b/kopf/reactor/registries.py index 603b11c9..ea2dda2e 100644 --- a/kopf/reactor/registries.py +++ b/kopf/reactor/registries.py @@ -14,6 +14,7 @@ import abc import collections import functools +import warnings from types import FunctionType, MethodType from typing import (Any, MutableMapping, Optional, Sequence, Collection, Iterable, Iterator, List, Set, FrozenSet, Mapping, Callable, cast, Generic, TypeVar) @@ -65,6 +66,9 @@ def register( activity: Optional[causation.Activity] = None, _fallback: bool = False, ) -> callbacks.ActivityHandlerFn: + warnings.warn("registry.register() is deprecated; " + "use @kopf.on... decorators with registry= kwarg.", + DeprecationWarning) real_id = generate_id(fn=fn, id=id) handler = handlers.ActivityHandler( id=real_id, fn=fn, activity=activity, @@ -122,6 +126,10 @@ def register( annotations: Optional[bodies.Annotations] = None, when: Optional[callbacks.WhenHandlerFn] = None, ) -> callbacks.ResourceHandlerFn: + warnings.warn("registry.register() is deprecated; " + "use @kopf.on... decorators with registry= kwarg.", + DeprecationWarning) + if reason is None and event is not None: reason = causation.Reason(event) @@ -228,6 +236,10 @@ def resources(self) -> FrozenSet[resources_.Resource]: return (frozenset(self.resource_watching_handlers) | frozenset(self.resource_changing_handlers)) + # + # Everything below is deprecated and will be removed in the next major release. + # + def register_activity_handler( self, fn: callbacks.ActivityHandlerFn, @@ -241,6 +253,9 @@ def register_activity_handler( activity: Optional[causation.Activity] = None, _fallback: bool = False, ) -> callbacks.ActivityHandlerFn: + warnings.warn("registry.register_activity_handler() is deprecated; " + "use @kopf.on... decorators with registry= kwarg.", + DeprecationWarning) return self.activity_handlers.register( fn=fn, id=id, activity=activity, errors=errors, timeout=timeout, retries=retries, backoff=backoff, cooldown=cooldown, @@ -261,6 +276,9 @@ def register_resource_watching_handler( """ Register an additional handler function for low-level events. """ + warnings.warn("registry.register_resource_watching_handler() is deprecated; " + "use @kopf.on... decorators with registry= kwarg.", + DeprecationWarning) resource = resources_.Resource(group, version, plural) return self.resource_watching_handlers[resource].register( fn=fn, id=id, @@ -292,6 +310,9 @@ def register_resource_changing_handler( """ Register an additional handler function for the specific resource and specific reason. """ + warnings.warn("registry.register_resource_changing_handler() is deprecated; " + "use @kopf.on... decorators with registry= kwarg.", + DeprecationWarning) resource = resources_.Resource(group, version, plural) return self.resource_changing_handlers[resource].register( reason=reason, event=event, field=field, fn=fn, id=id, @@ -303,18 +324,27 @@ def register_resource_changing_handler( def has_activity_handlers( self, ) -> bool: + warnings.warn("registry.has_activity_handlers() is deprecated; " + "use registry.activity_handlers directly.", + DeprecationWarning) return bool(self.activity_handlers) def has_resource_watching_handlers( self, resource: resources_.Resource, ) -> bool: + warnings.warn("registry.has_resource_watching_handlers() is deprecated; " + "use registry.resource_watching_handlers[resource] directly.", + DeprecationWarning) return bool(self.resource_watching_handlers[resource]) def has_resource_changing_handlers( self, resource: resources_.Resource, ) -> bool: + warnings.warn("registry.has_resource_changing_handlers() is deprecated; " + "use registry.resource_changing_handlers[resource] directly.", + DeprecationWarning) return bool(self.resource_changing_handlers[resource]) def get_activity_handlers( @@ -322,18 +352,27 @@ def get_activity_handlers( *, activity: causation.Activity, ) -> Sequence[handlers.ActivityHandler]: + warnings.warn("registry.get_activity_handlers() is deprecated; " + "use registry.activity_handlers.get_handlers().", + DeprecationWarning) return self.activity_handlers.get_handlers(activity=activity) def get_resource_watching_handlers( self, cause: causation.ResourceWatchingCause, ) -> Sequence[handlers.ResourceHandler]: + warnings.warn("registry.get_resource_watching_handlers() is deprecated; " + "use registry.resource_watching_handlers[resource].get_handlers().", + DeprecationWarning) return self.resource_watching_handlers[cause.resource].get_handlers(cause=cause) def get_resource_changing_handlers( self, cause: causation.ResourceChangingCause, ) -> Sequence[handlers.ResourceHandler]: + warnings.warn("registry.get_resource_changing_handlers() is deprecated; " + "use registry.resource_changing_handlers[resource].get_handlers().", + DeprecationWarning) return self.resource_changing_handlers[cause.resource].get_handlers(cause=cause) def iter_activity_handlers( @@ -341,6 +380,9 @@ def iter_activity_handlers( *, activity: causation.Activity, ) -> Iterator[handlers.ActivityHandler]: + warnings.warn("registry.iter_activity_handlers() is deprecated; " + "use registry.activity_handlers.iter_handlers().", + DeprecationWarning) yield from self.activity_handlers.iter_handlers(activity=activity) def iter_resource_watching_handlers( @@ -350,6 +392,9 @@ def iter_resource_watching_handlers( """ Iterate all handlers for the low-level events. """ + warnings.warn("registry.iter_resource_watching_handlers() is deprecated; " + "use registry.resource_watching_handlers[resource].iter_handlers().", + DeprecationWarning) yield from self.resource_watching_handlers[cause.resource].iter_handlers(cause=cause) def iter_resource_changing_handlers( @@ -359,18 +404,27 @@ def iter_resource_changing_handlers( """ Iterate all handlers that match this cause/event, in the order they were registered (even if mixed). """ + warnings.warn("registry.iter_resource_changing_handlers() is deprecated; " + "use registry.resource_changing_handlers[resource].iter_handlers().", + DeprecationWarning) yield from self.resource_changing_handlers[cause.resource].iter_handlers(cause=cause) def get_extra_fields( self, resource: resources_.Resource, ) -> Set[dicts.FieldPath]: + warnings.warn("registry.get_extra_fields() is deprecated; " + "use registry.resource_changing_handlers[resource].get_extra_fields().", + DeprecationWarning) return self.resource_changing_handlers[resource].get_extra_fields() def iter_extra_fields( self, resource: resources_.Resource, ) -> Iterator[dicts.FieldPath]: + warnings.warn("registry.iter_extra_fields() is deprecated; " + "use registry.resource_changing_handlers[resource].iter_extra_fields().", + DeprecationWarning) yield from self.resource_changing_handlers[resource].iter_extra_fields() def requires_finalizer( @@ -381,6 +435,9 @@ def requires_finalizer( """ Check whether a finalizer should be added to the given resource or not. """ + warnings.warn("registry.requires_finalizer() is deprecated; " + "use registry.resource_changing_handlers[resource].requires_finalizer().", + DeprecationWarning) return self.resource_changing_handlers[resource].requires_finalizer(cause=cause) diff --git a/tests/registries/legacy-1/test_legacy1_handler_matching.py b/tests/registries/legacy-1/test_legacy1_handler_matching.py index b7e9e93a..744bd607 100644 --- a/tests/registries/legacy-1/test_legacy1_handler_matching.py +++ b/tests/registries/legacy-1/test_legacy1_handler_matching.py @@ -22,7 +22,8 @@ def registry(request): @pytest.fixture() def register_fn(registry, resource): if isinstance(registry, SimpleRegistry): - yield registry.register + with pytest.deprecated_call(match=r"registry.register\(\) is deprecated"): + yield registry.register elif isinstance(registry, GlobalRegistry): with pytest.deprecated_call(match=r"GlobalRegistry.register_cause_handler\(\) is deprecated"): yield functools.partial(registry.register_cause_handler, resource.group, resource.version, resource.plural) diff --git a/tests/registries/legacy-1/test_legacy1_id_detection.py b/tests/registries/legacy-1/test_legacy1_id_detection.py index 7dfe1ed3..e26fbda0 100644 --- a/tests/registries/legacy-1/test_legacy1_id_detection.py +++ b/tests/registries/legacy-1/test_legacy1_id_detection.py @@ -75,7 +75,8 @@ def test_with_no_hints(mocker): get_fn_id = mocker.patch('kopf.reactor.registries.get_callable_id', return_value='some-id') registry = SimpleRegistry() - registry.register(some_fn) + with pytest.deprecated_call(match=r"registry.register\(\) is deprecated"): + registry.register(some_fn) with pytest.deprecated_call(match=r"get_cause_handlers\(\) is deprecated"): handlers = registry.get_cause_handlers(mocker.MagicMock()) @@ -91,7 +92,8 @@ def test_with_prefix(mocker): get_fn_id = mocker.patch('kopf.reactor.registries.get_callable_id', return_value='some-id') registry = SimpleRegistry() - registry.register(some_fn) + with pytest.deprecated_call(match=r"registry.register\(\) is deprecated"): + registry.register(some_fn) with pytest.deprecated_call(match=r"get_cause_handlers\(\) is deprecated"): handlers = registry.get_cause_handlers(mocker.MagicMock()) @@ -107,7 +109,8 @@ def test_with_suffix(mocker, field): diff = [('add', ('some-field', 'sub-field'), 'old', 'new')] registry = SimpleRegistry() - registry.register(some_fn, field=field) + with pytest.deprecated_call(match=r"registry.register\(\) is deprecated"): + registry.register(some_fn, field=field) with pytest.deprecated_call(match=r"get_cause_handlers\(\) is deprecated"): handlers = registry.get_cause_handlers(mocker.MagicMock(diff=diff)) @@ -124,7 +127,8 @@ def test_with_prefix_and_suffix(mocker, field): diff = [('add', ('some-field', 'sub-field'), 'old', 'new')] registry = SimpleRegistry(prefix='some-prefix') - registry.register(some_fn, field=field) + with pytest.deprecated_call(match=r"registry.register\(\) is deprecated"): + registry.register(some_fn, field=field) with pytest.deprecated_call(match=r"get_cause_handlers\(\) is deprecated"): handlers = registry.get_cause_handlers(mocker.MagicMock(diff=diff)) @@ -141,7 +145,8 @@ def test_with_explicit_id_and_prefix_and_suffix(mocker, field): diff = [('add', ('some-field', 'sub-field'), 'old', 'new')] registry = SimpleRegistry(prefix='some-prefix') - registry.register(some_fn, id='explicit-id', field=field) + with pytest.deprecated_call(match=r"registry.register\(\) is deprecated"): + registry.register(some_fn, id='explicit-id', field=field) with pytest.deprecated_call(match=r"get_cause_handlers\(\) is deprecated"): handlers = registry.get_cause_handlers(mocker.MagicMock(diff=diff)) diff --git a/tests/registries/legacy-1/test_legacy1_registering.py b/tests/registries/legacy-1/test_legacy1_registering.py index d7810cef..fe7fb4ab 100644 --- a/tests/registries/legacy-1/test_legacy1_registering.py +++ b/tests/registries/legacy-1/test_legacy1_registering.py @@ -43,7 +43,8 @@ def test_simple_registry_with_minimal_signature(mocker): cause = mocker.Mock(event=None, diff=None) registry = SimpleRegistry() - registry.register(some_fn) + with pytest.deprecated_call(match=r"registry.register\(\) is deprecated"): + registry.register(some_fn) with pytest.deprecated_call(match=r"use ResourceChangingRegistry.get_handlers\(\)"): handlers = registry.get_cause_handlers(cause) diff --git a/tests/registries/legacy-1/test_legacy1_requires_finalizer.py b/tests/registries/legacy-1/test_legacy1_requires_finalizer.py index bd15167c..4bf16c2e 100644 --- a/tests/registries/legacy-1/test_legacy1_requires_finalizer.py +++ b/tests/registries/legacy-1/test_legacy1_requires_finalizer.py @@ -40,7 +40,8 @@ def test_requires_finalizer_deletion_handler(optional, expected): def fn(**_): pass - requires_finalizer = registry.requires_finalizer(resource=resource, cause=CAUSE) + with pytest.deprecated_call(match=r"use registry.resource_changing_handlers"): + requires_finalizer = registry.requires_finalizer(resource=resource, cause=CAUSE) assert requires_finalizer == expected @@ -62,7 +63,8 @@ def fn1(**_): def fn2(**_): pass - requires_finalizer = registry.requires_finalizer(resource=resource, cause=CAUSE) + with pytest.deprecated_call(match=r"use registry.resource_changing_handlers"): + requires_finalizer = registry.requires_finalizer(resource=resource, cause=CAUSE) assert requires_finalizer == expected @@ -75,7 +77,8 @@ def test_requires_finalizer_no_deletion_handler(): def fn1(**_): pass - requires_finalizer = registry.requires_finalizer(resource=resource, cause=CAUSE) + with pytest.deprecated_call(match=r"use registry.resource_changing_handlers"): + requires_finalizer = registry.requires_finalizer(resource=resource, cause=CAUSE) assert requires_finalizer is False @@ -97,7 +100,8 @@ def test_requires_finalizer_deletion_handler_matches_labels(labels, optional, ex def fn(**_): pass - requires_finalizer = registry.requires_finalizer(resource=resource, cause=CAUSE) + with pytest.deprecated_call(match=r"use registry.resource_changing_handlers"): + requires_finalizer = registry.requires_finalizer(resource=resource, cause=CAUSE) assert requires_finalizer == expected @@ -119,7 +123,8 @@ def test_requires_finalizer_deletion_handler_mismatches_labels(labels, optional, def fn(**_): pass - requires_finalizer = registry.requires_finalizer(resource=resource, cause=CAUSE) + with pytest.deprecated_call(match=r"use registry.resource_changing_handlers"): + requires_finalizer = registry.requires_finalizer(resource=resource, cause=CAUSE) assert requires_finalizer == expected @@ -141,7 +146,8 @@ def test_requires_finalizer_deletion_handler_matches_annotations(annotations, op def fn(**_): pass - requires_finalizer = registry.requires_finalizer(resource=resource, cause=CAUSE) + with pytest.deprecated_call(match=r"use registry.resource_changing_handlers"): + requires_finalizer = registry.requires_finalizer(resource=resource, cause=CAUSE) assert requires_finalizer == expected @@ -163,5 +169,6 @@ def test_requires_finalizer_deletion_handler_mismatches_annotations(annotations, def fn(**_): pass - requires_finalizer = registry.requires_finalizer(resource=resource, cause=CAUSE) + with pytest.deprecated_call(match=r"use registry.resource_changing_handlers"): + requires_finalizer = registry.requires_finalizer(resource=resource, cause=CAUSE) assert requires_finalizer == expected diff --git a/tests/registries/legacy-2/test_legacy2_decorators.py b/tests/registries/legacy-2/test_legacy2_decorators.py index 3b96d768..cde495e4 100644 --- a/tests/registries/legacy-2/test_legacy2_decorators.py +++ b/tests/registries/legacy-2/test_legacy2_decorators.py @@ -16,7 +16,9 @@ def test_on_startup_minimal(): def fn(**_): pass - handlers = registry.get_activity_handlers(activity=Activity.STARTUP) + with pytest.deprecated_call(match=r"use registry.activity_handlers"): + handlers = registry.get_activity_handlers(activity=Activity.STARTUP) + assert len(handlers) == 1 assert handlers[0].fn is fn assert handlers[0].activity == Activity.STARTUP @@ -33,7 +35,9 @@ def test_on_cleanup_minimal(): def fn(**_): pass - handlers = registry.get_activity_handlers(activity=Activity.CLEANUP) + with pytest.deprecated_call(match=r"use registry.activity_handlers"): + handlers = registry.get_activity_handlers(activity=Activity.CLEANUP) + assert len(handlers) == 1 assert handlers[0].fn is fn assert handlers[0].activity == Activity.CLEANUP @@ -50,7 +54,9 @@ def test_on_probe_minimal(): def fn(**_): pass - handlers = registry.get_activity_handlers(activity=Activity.PROBE) + with pytest.deprecated_call(match=r"use registry.activity_handlers"): + handlers = registry.get_activity_handlers(activity=Activity.PROBE) + assert len(handlers) == 1 assert handlers[0].fn is fn assert handlers[0].activity == Activity.PROBE @@ -71,7 +77,9 @@ def test_on_resume_minimal(mocker, reason): def fn(**_): pass - handlers = registry.get_resource_changing_handlers(cause) + with pytest.deprecated_call(match=r"use registry.resource_changing_handlers"): + handlers = registry.get_resource_changing_handlers(cause) + assert len(handlers) == 1 assert handlers[0].fn is fn assert handlers[0].reason is None @@ -94,7 +102,9 @@ def test_on_create_minimal(mocker): def fn(**_): pass - handlers = registry.get_resource_changing_handlers(cause) + with pytest.deprecated_call(match=r"use registry.resource_changing_handlers"): + handlers = registry.get_resource_changing_handlers(cause) + assert len(handlers) == 1 assert handlers[0].fn is fn assert handlers[0].reason == Reason.CREATE @@ -117,7 +127,9 @@ def test_on_update_minimal(mocker): def fn(**_): pass - handlers = registry.get_resource_changing_handlers(cause) + with pytest.deprecated_call(match=r"use registry.resource_changing_handlers"): + handlers = registry.get_resource_changing_handlers(cause) + assert len(handlers) == 1 assert handlers[0].fn is fn assert handlers[0].reason == Reason.UPDATE @@ -140,7 +152,9 @@ def test_on_delete_minimal(mocker): def fn(**_): pass - handlers = registry.get_resource_changing_handlers(cause) + with pytest.deprecated_call(match=r"use registry.resource_changing_handlers"): + handlers = registry.get_resource_changing_handlers(cause) + assert len(handlers) == 1 assert handlers[0].fn is fn assert handlers[0].reason == Reason.DELETE @@ -164,7 +178,9 @@ def test_on_field_minimal(mocker): def fn(**_): pass - handlers = registry.get_resource_changing_handlers(cause) + with pytest.deprecated_call(match=r"use registry.resource_changing_handlers"): + handlers = registry.get_resource_changing_handlers(cause) + assert len(handlers) == 1 assert handlers[0].fn is fn assert handlers[0].reason is None @@ -194,7 +210,9 @@ def test_on_startup_with_all_kwargs(mocker): def fn(**_): pass - handlers = registry.get_activity_handlers(activity=Activity.STARTUP) + with pytest.deprecated_call(match=r"use registry.activity_handlers"): + handlers = registry.get_activity_handlers(activity=Activity.STARTUP) + assert len(handlers) == 1 assert handlers[0].fn is fn assert handlers[0].activity == Activity.STARTUP @@ -214,7 +232,9 @@ def test_on_cleanup_with_all_kwargs(mocker): def fn(**_): pass - handlers = registry.get_activity_handlers(activity=Activity.CLEANUP) + with pytest.deprecated_call(match=r"use registry.activity_handlers"): + handlers = registry.get_activity_handlers(activity=Activity.CLEANUP) + assert len(handlers) == 1 assert handlers[0].fn is fn assert handlers[0].activity == Activity.CLEANUP @@ -234,7 +254,9 @@ def test_on_probe_with_all_kwargs(mocker): def fn(**_): pass - handlers = registry.get_activity_handlers(activity=Activity.PROBE) + with pytest.deprecated_call(match=r"use registry.activity_handlers"): + handlers = registry.get_activity_handlers(activity=Activity.PROBE) + assert len(handlers) == 1 assert handlers[0].fn is fn assert handlers[0].activity == Activity.PROBE @@ -265,7 +287,9 @@ def test_on_resume_with_all_kwargs(mocker, reason): def fn(**_): pass - handlers = registry.get_resource_changing_handlers(cause) + with pytest.deprecated_call(match=r"use registry.resource_changing_handlers"): + handlers = registry.get_resource_changing_handlers(cause) + assert len(handlers) == 1 assert handlers[0].fn is fn assert handlers[0].reason is None @@ -298,7 +322,9 @@ def test_on_create_with_all_kwargs(mocker): def fn(**_): pass - handlers = registry.get_resource_changing_handlers(cause) + with pytest.deprecated_call(match=r"use registry.resource_changing_handlers"): + handlers = registry.get_resource_changing_handlers(cause) + assert len(handlers) == 1 assert handlers[0].fn is fn assert handlers[0].reason == Reason.CREATE @@ -330,7 +356,9 @@ def test_on_update_with_all_kwargs(mocker): def fn(**_): pass - handlers = registry.get_resource_changing_handlers(cause) + with pytest.deprecated_call(match=r"use registry.resource_changing_handlers"): + handlers = registry.get_resource_changing_handlers(cause) + assert len(handlers) == 1 assert handlers[0].fn is fn assert handlers[0].reason == Reason.UPDATE @@ -367,7 +395,9 @@ def test_on_delete_with_all_kwargs(mocker, optional): def fn(**_): pass - handlers = registry.get_resource_changing_handlers(cause) + with pytest.deprecated_call(match=r"use registry.resource_changing_handlers"): + handlers = registry.get_resource_changing_handlers(cause) + assert len(handlers) == 1 assert handlers[0].fn is fn assert handlers[0].reason == Reason.DELETE @@ -400,7 +430,9 @@ def test_on_field_with_all_kwargs(mocker): def fn(**_): pass - handlers = registry.get_resource_changing_handlers(cause) + with pytest.deprecated_call(match=r"use registry.resource_changing_handlers"): + handlers = registry.get_resource_changing_handlers(cause) + assert len(handlers) == 1 assert handlers[0].fn is fn assert handlers[0].reason is None diff --git a/tests/registries/legacy-2/test_legacy2_handler_matching.py b/tests/registries/legacy-2/test_legacy2_handler_matching.py index f66e9817..ed7bfdba 100644 --- a/tests/registries/legacy-2/test_legacy2_handler_matching.py +++ b/tests/registries/legacy-2/test_legacy2_handler_matching.py @@ -3,7 +3,7 @@ import pytest -from kopf import ResourceRegistry, OperatorRegistry +from kopf import OperatorRegistry from kopf.reactor.causation import ResourceChangingCause @@ -13,7 +13,6 @@ def some_fn(x=None): @pytest.fixture(params=[ - # pytest.param(ResourceRegistry, id='in-simple-registry'), pytest.param(OperatorRegistry, id='in-global-registry'), ]) def registry(request): @@ -22,11 +21,11 @@ def registry(request): @pytest.fixture() def register_fn(registry, resource): - # if isinstance(registry, ResourceRegistry): - # return registry.register if isinstance(registry, OperatorRegistry): - return functools.partial(registry.register_resource_changing_handler, resource.group, resource.version, resource.plural) - raise Exception(f"Unsupported registry type: {registry}") + with pytest.deprecated_call(match=r"register_resource_changing_handler\(\) is deprecated"): + yield functools.partial(registry.register_resource_changing_handler, resource.group, resource.version, resource.plural) + else: + raise Exception(f"Unsupported registry type: {registry}") @pytest.fixture(params=[ @@ -63,19 +62,22 @@ def cause_any_diff(resource, request): def test_catchall_handlers_without_field_found(cause_any_diff, registry, register_fn): register_fn(some_fn, reason=None, field=None) - handlers = registry.get_resource_changing_handlers(cause_any_diff) + with pytest.deprecated_call(match=r"use registry.resource_changing_handlers"): + handlers = registry.get_resource_changing_handlers(cause_any_diff) assert handlers def test_catchall_handlers_with_field_found(cause_with_diff, registry, register_fn): register_fn(some_fn, reason=None, field='some-field') - handlers = registry.get_resource_changing_handlers(cause_with_diff) + with pytest.deprecated_call(match=r"use registry.resource_changing_handlers"): + handlers = registry.get_resource_changing_handlers(cause_with_diff) assert handlers def test_catchall_handlers_with_field_ignored(cause_no_diff, registry, register_fn): register_fn(some_fn, reason=None, field='some-field') - handlers = registry.get_resource_changing_handlers(cause_no_diff) + with pytest.deprecated_call(match=r"use registry.resource_changing_handlers"): + handlers = registry.get_resource_changing_handlers(cause_no_diff) assert not handlers @@ -86,7 +88,8 @@ def test_catchall_handlers_with_field_ignored(cause_no_diff, registry, register_ def test_catchall_handlers_with_labels_satisfied(registry, register_fn, resource, labels): cause = Mock(resource=resource, reason='some-reason', diff=None, body={'metadata': {'labels': labels}}) register_fn(some_fn, reason=None, field=None, labels={'somelabel': 'somevalue'}) - handlers = registry.get_resource_changing_handlers(cause) + with pytest.deprecated_call(match=r"use registry.resource_changing_handlers"): + handlers = registry.get_resource_changing_handlers(cause) assert handlers @@ -98,7 +101,8 @@ def test_catchall_handlers_with_labels_satisfied(registry, register_fn, resource def test_catchall_handlers_with_labels_not_satisfied(registry, register_fn, resource, labels): cause = Mock(resource=resource, reason='some-reason', diff=None, body={'metadata': {'labels': labels}}) register_fn(some_fn, reason=None, field=None, labels={'somelabel': 'somevalue'}) - handlers = registry.get_resource_changing_handlers(cause) + with pytest.deprecated_call(match=r"use registry.resource_changing_handlers"): + handlers = registry.get_resource_changing_handlers(cause) assert not handlers @@ -109,7 +113,8 @@ def test_catchall_handlers_with_labels_not_satisfied(registry, register_fn, reso def test_catchall_handlers_with_labels_exist(registry, register_fn, resource, labels): cause = Mock(resource=resource, reason='some-reason', diff=None, body={'metadata': {'labels': labels}}) register_fn(some_fn, reason=None, field=None, labels={'somelabel': None}) - handlers = registry.get_resource_changing_handlers(cause) + with pytest.deprecated_call(match=r"use registry.resource_changing_handlers"): + handlers = registry.get_resource_changing_handlers(cause) assert handlers @@ -120,7 +125,8 @@ def test_catchall_handlers_with_labels_exist(registry, register_fn, resource, la def test_catchall_handlers_with_labels_not_exist(registry, register_fn, resource, labels): cause = Mock(resource=resource, reason='some-reason', diff=None, body={'metadata': {'labels': labels}}) register_fn(some_fn, reason=None, field=None, labels={'somelabel': None}) - handlers = registry.get_resource_changing_handlers(cause) + with pytest.deprecated_call(match=r"use registry.resource_changing_handlers"): + handlers = registry.get_resource_changing_handlers(cause) assert not handlers @@ -134,7 +140,8 @@ def test_catchall_handlers_with_labels_not_exist(registry, register_fn, resource def test_catchall_handlers_without_labels(registry, register_fn, resource, labels): cause = Mock(resource=resource, reason='some-reason', diff=None, body={'metadata': {'labels': labels}}) register_fn(some_fn, reason=None, field=None, labels=None) - handlers = registry.get_resource_changing_handlers(cause) + with pytest.deprecated_call(match=r"use registry.resource_changing_handlers"): + handlers = registry.get_resource_changing_handlers(cause) assert handlers @@ -145,7 +152,8 @@ def test_catchall_handlers_without_labels(registry, register_fn, resource, label def test_catchall_handlers_with_annotations_satisfied(registry, register_fn, resource, annotations): cause = Mock(resource=resource, reason='some-reason', diff=None, body={'metadata': {'annotations': annotations}}) register_fn(some_fn, reason=None, field=None, annotations={'someannotation': 'somevalue'}) - handlers = registry.get_resource_changing_handlers(cause) + with pytest.deprecated_call(match=r"use registry.resource_changing_handlers"): + handlers = registry.get_resource_changing_handlers(cause) assert handlers @@ -157,7 +165,8 @@ def test_catchall_handlers_with_annotations_satisfied(registry, register_fn, res def test_catchall_handlers_with_annotations_not_satisfied(registry, register_fn, resource, annotations): cause = Mock(resource=resource, reason='some-reason', diff=None, body={'metadata': {'annotations': annotations}}) register_fn(some_fn, reason=None, field=None, annotations={'someannotation': 'somevalue'}) - handlers = registry.get_resource_changing_handlers(cause) + with pytest.deprecated_call(match=r"use registry.resource_changing_handlers"): + handlers = registry.get_resource_changing_handlers(cause) assert not handlers @@ -168,7 +177,8 @@ def test_catchall_handlers_with_annotations_not_satisfied(registry, register_fn, def test_catchall_handlers_with_annotations_exist(registry, register_fn, resource, annotations): cause = Mock(resource=resource, reason='some-reason', diff=None, body={'metadata': {'annotations': annotations}}) register_fn(some_fn, reason=None, field=None, annotations={'someannotation': None}) - handlers = registry.get_resource_changing_handlers(cause) + with pytest.deprecated_call(match=r"use registry.resource_changing_handlers"): + handlers = registry.get_resource_changing_handlers(cause) assert handlers @@ -179,7 +189,8 @@ def test_catchall_handlers_with_annotations_exist(registry, register_fn, resourc def test_catchall_handlers_with_annotations_not_exist(registry, register_fn, resource, annotations): cause = Mock(resource=resource, reason='some-reason', diff=None, body={'metadata': {'annotations': annotations}}) register_fn(some_fn, reason=None, field=None, annotations={'someannotation': None}) - handlers = registry.get_resource_changing_handlers(cause) + with pytest.deprecated_call(match=r"use registry.resource_changing_handlers"): + handlers = registry.get_resource_changing_handlers(cause) assert not handlers @@ -193,7 +204,8 @@ def test_catchall_handlers_with_annotations_not_exist(registry, register_fn, res def test_catchall_handlers_without_annotations(registry, register_fn, resource, annotations): cause = Mock(resource=resource, reason='some-reason', diff=None, body={'metadata': {'annotations': annotations}}) register_fn(some_fn, reason=None, field=None, annotations=None) - handlers = registry.get_resource_changing_handlers(cause) + with pytest.deprecated_call(match=r"use registry.resource_changing_handlers"): + handlers = registry.get_resource_changing_handlers(cause) assert handlers @@ -206,7 +218,8 @@ def test_catchall_handlers_without_annotations(registry, register_fn, resource, def test_catchall_handlers_with_labels_and_annotations_satisfied(registry, register_fn, resource, labels, annotations): cause = Mock(resource=resource, reason='some-reason', diff=None, body={'metadata': {'labels': labels, 'annotations': annotations}}) register_fn(some_fn, reason=None, field=None, labels={'somelabel': 'somevalue'}, annotations={'someannotation': 'somevalue'}) - handlers = registry.get_resource_changing_handlers(cause) + with pytest.deprecated_call(match=r"use registry.resource_changing_handlers"): + handlers = registry.get_resource_changing_handlers(cause) assert handlers @@ -220,7 +233,8 @@ def test_catchall_handlers_with_labels_and_annotations_satisfied(registry, regis def test_catchall_handlers_with_labels_and_annotations_not_satisfied(registry, register_fn, resource, labels): cause = Mock(resource=resource, reason='some-reason', diff=None, body={'metadata': {'labels': labels}}) register_fn(some_fn, reason=None, field=None, labels={'somelabel': 'somevalue'}, annotations={'someannotation': 'somevalue'}) - handlers = registry.get_resource_changing_handlers(cause) + with pytest.deprecated_call(match=r"use registry.resource_changing_handlers"): + handlers = registry.get_resource_changing_handlers(cause) assert not handlers @@ -241,7 +255,8 @@ def test_catchall_handlers_with_when_match(registry, register_fn, resource, when initial=None ) register_fn(some_fn, reason=None, field=None, when=when) - handlers = registry.get_resource_changing_handlers(cause) + with pytest.deprecated_call(match=r"use registry.resource_changing_handlers"): + handlers = registry.get_resource_changing_handlers(cause) assert handlers @@ -261,7 +276,8 @@ def test_catchall_handlers_with_when_not_match(registry, register_fn, resource, initial=None ) register_fn(some_fn, reason=None, field=None, when=when) - handlers = registry.get_resource_changing_handlers(cause) + with pytest.deprecated_call(match=r"use registry.resource_changing_handlers"): + handlers = registry.get_resource_changing_handlers(cause) assert not handlers @@ -274,102 +290,120 @@ def test_catchall_handlers_with_when_not_match(registry, register_fn, resource, def test_relevant_handlers_without_field_found(cause_any_diff, registry, register_fn): register_fn(some_fn, reason='some-reason') - handlers = registry.get_resource_changing_handlers(cause_any_diff) + with pytest.deprecated_call(match=r"use registry.resource_changing_handlers"): + handlers = registry.get_resource_changing_handlers(cause_any_diff) assert handlers def test_relevant_handlers_with_field_found(cause_with_diff, registry, register_fn): register_fn(some_fn, reason='some-reason', field='some-field') - handlers = registry.get_resource_changing_handlers(cause_with_diff) + with pytest.deprecated_call(match=r"use registry.resource_changing_handlers"): + handlers = registry.get_resource_changing_handlers(cause_with_diff) assert handlers def test_relevant_handlers_with_field_ignored(cause_no_diff, registry, register_fn): register_fn(some_fn, reason='some-reason', field='some-field') - handlers = registry.get_resource_changing_handlers(cause_no_diff) + with pytest.deprecated_call(match=r"use registry.resource_changing_handlers"): + handlers = registry.get_resource_changing_handlers(cause_no_diff) assert not handlers def test_relevant_handlers_with_labels_satisfied(cause_any_diff, registry, register_fn): register_fn(some_fn, reason='some-reason', labels={'somelabel': None}) - handlers = registry.get_resource_changing_handlers(cause_any_diff) + with pytest.deprecated_call(match=r"use registry.resource_changing_handlers"): + handlers = registry.get_resource_changing_handlers(cause_any_diff) assert handlers def test_relevant_handlers_with_labels_not_satisfied(cause_any_diff, registry, register_fn): register_fn(some_fn, reason='some-reason', labels={'otherlabel': None}) - handlers = registry.get_resource_changing_handlers(cause_any_diff) + with pytest.deprecated_call(match=r"use registry.resource_changing_handlers"): + handlers = registry.get_resource_changing_handlers(cause_any_diff) assert not handlers def test_relevant_handlers_with_annotations_satisfied(cause_any_diff, registry, register_fn): register_fn(some_fn, reason='some-reason', annotations={'someannotation': None}) - handlers = registry.get_resource_changing_handlers(cause_any_diff) + with pytest.deprecated_call(match=r"use registry.resource_changing_handlers"): + handlers = registry.get_resource_changing_handlers(cause_any_diff) assert handlers def test_relevant_handlers_with_annotations_not_satisfied(cause_any_diff, registry, register_fn): register_fn(some_fn, reason='some-reason', annotations={'otherannotation': None}) - handlers = registry.get_resource_changing_handlers(cause_any_diff) + with pytest.deprecated_call(match=r"use registry.resource_changing_handlers"): + handlers = registry.get_resource_changing_handlers(cause_any_diff) assert not handlers def test_relevant_handlers_with_filter_satisfied(cause_any_diff, registry, register_fn): register_fn(some_fn, reason='some-reason', when=lambda *_: True) - handlers = registry.get_resource_changing_handlers(cause_any_diff) + with pytest.deprecated_call(match=r"use registry.resource_changing_handlers"): + handlers = registry.get_resource_changing_handlers(cause_any_diff) assert handlers def test_relevant_handlers_with_filter_not_satisfied(cause_any_diff, registry, register_fn): register_fn(some_fn, reason='some-reason', when=lambda *_: False) - handlers = registry.get_resource_changing_handlers(cause_any_diff) + with pytest.deprecated_call(match=r"use registry.resource_changing_handlers"): + handlers = registry.get_resource_changing_handlers(cause_any_diff) assert not handlers def test_irrelevant_handlers_without_field_ignored(cause_any_diff, registry, register_fn): register_fn(some_fn, reason='another-reason') - handlers = registry.get_resource_changing_handlers(cause_any_diff) + with pytest.deprecated_call(match=r"use registry.resource_changing_handlers"): + handlers = registry.get_resource_changing_handlers(cause_any_diff) assert not handlers def test_irrelevant_handlers_with_field_ignored(cause_any_diff, registry, register_fn): register_fn(some_fn, reason='another-reason', field='another-field') - handlers = registry.get_resource_changing_handlers(cause_any_diff) + with pytest.deprecated_call(match=r"use registry.resource_changing_handlers"): + handlers = registry.get_resource_changing_handlers(cause_any_diff) assert not handlers + def test_irrelevant_handlers_with_labels_satisfied(cause_any_diff, registry, register_fn): register_fn(some_fn, reason='another-reason', labels={'somelabel': None}) - handlers = registry.get_resource_changing_handlers(cause_any_diff) + with pytest.deprecated_call(match=r"use registry.resource_changing_handlers"): + handlers = registry.get_resource_changing_handlers(cause_any_diff) assert not handlers def test_irrelevant_handlers_with_labels_not_satisfied(cause_any_diff, registry, register_fn): register_fn(some_fn, reason='another-reason', labels={'otherlabel': None}) - handlers = registry.get_resource_changing_handlers(cause_any_diff) + with pytest.deprecated_call(match=r"use registry.resource_changing_handlers"): + handlers = registry.get_resource_changing_handlers(cause_any_diff) assert not handlers def test_irrelevant_handlers_with_annotations_satisfied(cause_any_diff, registry, register_fn): register_fn(some_fn, reason='another-reason', annotations={'someannotation': None}) - handlers = registry.get_resource_changing_handlers(cause_any_diff) + with pytest.deprecated_call(match=r"use registry.resource_changing_handlers"): + handlers = registry.get_resource_changing_handlers(cause_any_diff) assert not handlers def test_irrelevant_handlers_with_annotations_not_satisfied(cause_any_diff, registry, register_fn): register_fn(some_fn, reason='another-reason', annotations={'otherannotation': None}) - handlers = registry.get_resource_changing_handlers(cause_any_diff) + with pytest.deprecated_call(match=r"use registry.resource_changing_handlers"): + handlers = registry.get_resource_changing_handlers(cause_any_diff) assert not handlers def test_irrelevant_handlers_with_when_satisfied(cause_any_diff, registry, register_fn): register_fn(some_fn, reason='another-reason', when=lambda *_: True) - handlers = registry.get_resource_changing_handlers(cause_any_diff) + with pytest.deprecated_call(match=r"use registry.resource_changing_handlers"): + handlers = registry.get_resource_changing_handlers(cause_any_diff) assert not handlers def test_irrelevant_handlers_with_when_not_satisfied(cause_any_diff, registry, register_fn): register_fn(some_fn, reason='another-reason', when=lambda *_: False) - handlers = registry.get_resource_changing_handlers(cause_any_diff) + with pytest.deprecated_call(match=r"use registry.resource_changing_handlers"): + handlers = registry.get_resource_changing_handlers(cause_any_diff) assert not handlers # @@ -384,7 +418,8 @@ def test_order_persisted_a(cause_with_diff, registry, register_fn): register_fn(functools.partial(some_fn, 4), reason=None, field='filtered-out-reason') register_fn(functools.partial(some_fn, 5), reason=None, field='some-field') - handlers = registry.get_resource_changing_handlers(cause_with_diff) + with pytest.deprecated_call(match=r"use registry.resource_changing_handlers"): + handlers = registry.get_resource_changing_handlers(cause_with_diff) # Order must be preserved -- same as registered. assert len(handlers) == 3 @@ -403,7 +438,8 @@ def test_order_persisted_b(cause_with_diff, registry, register_fn): register_fn(functools.partial(some_fn, 4), reason='some-reason') register_fn(functools.partial(some_fn, 5), reason=None) - handlers = registry.get_resource_changing_handlers(cause_with_diff) + with pytest.deprecated_call(match=r"use registry.resource_changing_handlers"): + handlers = registry.get_resource_changing_handlers(cause_with_diff) # Order must be preserved -- same as registered. assert len(handlers) == 3 @@ -423,7 +459,8 @@ def test_deduplicated(cause_with_diff, registry, register_fn): register_fn(some_fn, reason=None, id='a') register_fn(some_fn, reason=None, id='b') - handlers = registry.get_resource_changing_handlers(cause_with_diff) + with pytest.deprecated_call(match=r"use registry.resource_changing_handlers"): + handlers = registry.get_resource_changing_handlers(cause_with_diff) assert len(handlers) == 1 assert handlers[0].id == 'a' # the first found one is returned diff --git a/tests/registries/legacy-2/test_legacy2_operator_resources.py b/tests/registries/legacy-2/test_legacy2_operator_resources.py index 7de8c582..27d40294 100644 --- a/tests/registries/legacy-2/test_legacy2_operator_resources.py +++ b/tests/registries/legacy-2/test_legacy2_operator_resources.py @@ -1,5 +1,7 @@ import collections +import pytest + from kopf.reactor.registries import OperatorRegistry from kopf.structs.resources import Resource @@ -11,10 +13,15 @@ def some_fn(): def test_resources(): registry = OperatorRegistry() - registry.register_resource_watching_handler('group1', 'version1', 'plural1', some_fn) - registry.register_resource_changing_handler('group2', 'version2', 'plural2', some_fn) - registry.register_resource_watching_handler('group2', 'version2', 'plural2', some_fn) - registry.register_resource_changing_handler('group1', 'version1', 'plural1', some_fn) + + with pytest.deprecated_call(match=r"use @kopf.on"): + registry.register_resource_watching_handler('group1', 'version1', 'plural1', some_fn) + with pytest.deprecated_call(match=r"use @kopf.on"): + registry.register_resource_changing_handler('group2', 'version2', 'plural2', some_fn) + with pytest.deprecated_call(match=r"use @kopf.on"): + registry.register_resource_watching_handler('group2', 'version2', 'plural2', some_fn) + with pytest.deprecated_call(match=r"use @kopf.on"): + registry.register_resource_changing_handler('group1', 'version1', 'plural1', some_fn) resources = registry.resources diff --git a/tests/registries/legacy-2/test_legacy2_registering.py b/tests/registries/legacy-2/test_legacy2_registering.py index 149fde03..d026ea85 100644 --- a/tests/registries/legacy-2/test_legacy2_registering.py +++ b/tests/registries/legacy-2/test_legacy2_registering.py @@ -41,7 +41,8 @@ def test_generic_registry_with_minimal_signature(mocker, generic_registry_cls): cause = mocker.Mock(event=None, diff=None) registry = generic_registry_cls() - registry.register(some_fn) + with pytest.deprecated_call(match=r"use @kopf.on"): + registry.register(some_fn) handlers = registry.get_handlers(cause) assert len(handlers) == 1 @@ -60,7 +61,8 @@ def test_operator_registry_with_activity_via_iter( assert not isinstance(iterator, collections.abc.Container) assert not isinstance(iterator, (list, tuple)) - handlers = list(iterator) + with pytest.deprecated_call(match=r"use registry.activity_handlers"): + handlers = list(iterator) assert not handlers @@ -76,7 +78,8 @@ def test_operator_registry_with_resource_watching_via_iter( assert not isinstance(iterator, collections.abc.Container) assert not isinstance(iterator, (list, tuple)) - handlers = list(iterator) + with pytest.deprecated_call(match=r"use registry.resource_watching_handlers"): + handlers = list(iterator) assert not handlers @@ -92,7 +95,8 @@ def test_operator_registry_with_resource_changing_via_iter( assert not isinstance(iterator, collections.abc.Container) assert not isinstance(iterator, (list, tuple)) - handlers = list(iterator) + with pytest.deprecated_call(match=r"use registry.resource_changing_handlers"): + handlers = list(iterator) assert not handlers @@ -101,7 +105,8 @@ def test_operator_registry_with_activity_via_list( operator_registry_cls, activity): registry = operator_registry_cls() - handlers = registry.get_activity_handlers(activity=activity) + with pytest.deprecated_call(match=r"use registry.activity_handlers"): + handlers = registry.get_activity_handlers(activity=activity) assert isinstance(handlers, collections.abc.Iterable) assert isinstance(handlers, collections.abc.Container) @@ -114,7 +119,8 @@ def test_operator_registry_with_resource_watching_via_list( cause = mocker.Mock(resource=resource, event=None, diff=None) registry = operator_registry_cls() - handlers = registry.get_resource_watching_handlers(cause) + with pytest.deprecated_call(match=r"use registry.resource_watching_handlers"): + handlers = registry.get_resource_watching_handlers(cause) assert isinstance(handlers, collections.abc.Iterable) assert isinstance(handlers, collections.abc.Container) @@ -127,7 +133,8 @@ def test_operator_registry_with_resource_changing_via_list( cause = mocker.Mock(resource=resource, event=None, diff=None) registry = operator_registry_cls() - handlers = registry.get_resource_changing_handlers(cause) + with pytest.deprecated_call(match=r"use registry.resource_changing_handlers"): + handlers = registry.get_resource_changing_handlers(cause) assert isinstance(handlers, collections.abc.Iterable) assert isinstance(handlers, collections.abc.Container) @@ -140,8 +147,10 @@ def test_operator_registry_with_activity_with_minimal_signature( operator_registry_cls, activity): registry = operator_registry_cls() - registry.register_activity_handler(some_fn) - handlers = registry.get_activity_handlers(activity=activity) + with pytest.deprecated_call(match=r"use @kopf.on"): + registry.register_activity_handler(some_fn) + with pytest.deprecated_call(match=r"use registry.activity_handlers"): + handlers = registry.get_activity_handlers(activity=activity) assert len(handlers) == 1 assert handlers[0].fn is some_fn @@ -152,8 +161,10 @@ def test_operator_registry_with_resource_watching_with_minimal_signature( cause = mocker.Mock(resource=resource, event=None, diff=None) registry = operator_registry_cls() - registry.register_resource_watching_handler(resource.group, resource.version, resource.plural, some_fn) - handlers = registry.get_resource_watching_handlers(cause) + with pytest.deprecated_call(match=r"use @kopf.on"): + registry.register_resource_watching_handler(resource.group, resource.version, resource.plural, some_fn) + with pytest.deprecated_call(match=r"use registry.resource_watching_handlers"): + handlers = registry.get_resource_watching_handlers(cause) assert len(handlers) == 1 assert handlers[0].fn is some_fn @@ -164,8 +175,10 @@ def test_operator_registry_with_resource_changing_with_minimal_signature( cause = mocker.Mock(resource=resource, event=None, diff=None) registry = operator_registry_cls() - registry.register_resource_changing_handler(resource.group, resource.version, resource.plural, some_fn) - handlers = registry.get_resource_changing_handlers(cause) + with pytest.deprecated_call(match=r"use @kopf.on"): + registry.register_resource_changing_handler(resource.group, resource.version, resource.plural, some_fn) + with pytest.deprecated_call(match=r"use registry.resource_changing_handlers"): + handlers = registry.get_resource_changing_handlers(cause) assert len(handlers) == 1 assert handlers[0].fn is some_fn diff --git a/tests/registries/legacy-2/test_legacy2_requires_finalizer.py b/tests/registries/legacy-2/test_legacy2_requires_finalizer.py index 10d77a24..906a9b2a 100644 --- a/tests/registries/legacy-2/test_legacy2_requires_finalizer.py +++ b/tests/registries/legacy-2/test_legacy2_requires_finalizer.py @@ -40,7 +40,8 @@ def test_requires_finalizer_deletion_handler(optional, expected): def fn(**_): pass - requires_finalizer = registry.requires_finalizer(resource=resource, cause=CAUSE) + with pytest.deprecated_call(match=r"use registry.resource_changing_handlers"): + requires_finalizer = registry.requires_finalizer(resource=resource, cause=CAUSE) assert requires_finalizer == expected @@ -62,7 +63,8 @@ def fn1(**_): def fn2(**_): pass - requires_finalizer = registry.requires_finalizer(resource=resource, cause=CAUSE) + with pytest.deprecated_call(match=r"use registry.resource_changing_handlers"): + requires_finalizer = registry.requires_finalizer(resource=resource, cause=CAUSE) assert requires_finalizer == expected @@ -75,7 +77,8 @@ def test_requires_finalizer_no_deletion_handler(): def fn1(**_): pass - requires_finalizer = registry.requires_finalizer(resource=resource, cause=CAUSE) + with pytest.deprecated_call(match=r"use registry.resource_changing_handlers"): + requires_finalizer = registry.requires_finalizer(resource=resource, cause=CAUSE) assert requires_finalizer is False @@ -97,7 +100,8 @@ def test_requires_finalizer_deletion_handler_matches_labels(labels, optional, ex def fn(**_): pass - requires_finalizer = registry.requires_finalizer(resource=resource, cause=CAUSE) + with pytest.deprecated_call(match=r"use registry.resource_changing_handlers"): + requires_finalizer = registry.requires_finalizer(resource=resource, cause=CAUSE) assert requires_finalizer == expected @@ -119,7 +123,8 @@ def test_requires_finalizer_deletion_handler_mismatches_labels(labels, optional, def fn(**_): pass - requires_finalizer = registry.requires_finalizer(resource=resource, cause=CAUSE) + with pytest.deprecated_call(match=r"use registry.resource_changing_handlers"): + requires_finalizer = registry.requires_finalizer(resource=resource, cause=CAUSE) assert requires_finalizer == expected @@ -141,7 +146,8 @@ def test_requires_finalizer_deletion_handler_matches_annotations(annotations, op def fn(**_): pass - requires_finalizer = registry.requires_finalizer(resource=resource, cause=CAUSE) + with pytest.deprecated_call(match=r"use registry.resource_changing_handlers"): + requires_finalizer = registry.requires_finalizer(resource=resource, cause=CAUSE) assert requires_finalizer == expected @@ -163,5 +169,6 @@ def test_requires_finalizer_deletion_handler_mismatches_annotations(annotations, def fn(**_): pass - requires_finalizer = registry.requires_finalizer(resource=resource, cause=CAUSE) + with pytest.deprecated_call(match=r"use registry.resource_changing_handlers"): + requires_finalizer = registry.requires_finalizer(resource=resource, cause=CAUSE) assert requires_finalizer == expected diff --git a/tests/registries/legacy-2/test_legacy2_resumes_mixed_in.py b/tests/registries/legacy-2/test_legacy2_resumes_mixed_in.py index bf813e1d..c25d3340 100644 --- a/tests/registries/legacy-2/test_legacy2_resumes_mixed_in.py +++ b/tests/registries/legacy-2/test_legacy2_resumes_mixed_in.py @@ -16,7 +16,8 @@ def test_resumes_ignored_for_non_initial_causes(mocker, reason, deleted): def fn(**_): pass - handlers = registry.get_resource_changing_handlers(cause) + with pytest.deprecated_call(match=r"use registry.resource_changing_handlers"): + handlers = registry.get_resource_changing_handlers(cause) assert len(handlers) == 0 @@ -30,7 +31,8 @@ def test_resumes_selected_for_initial_non_deletions(mocker, reason): def fn(**_): pass - handlers = registry.get_resource_changing_handlers(cause) + with pytest.deprecated_call(match=r"use registry.resource_changing_handlers"): + handlers = registry.get_resource_changing_handlers(cause) assert len(handlers) == 1 assert handlers[0].fn is fn @@ -45,7 +47,8 @@ def test_resumes_ignored_for_initial_deletions_by_default(mocker, reason): def fn(**_): pass - handlers = registry.get_resource_changing_handlers(cause) + with pytest.deprecated_call(match=r"use registry.resource_changing_handlers"): + handlers = registry.get_resource_changing_handlers(cause) assert len(handlers) == 0 @@ -59,6 +62,7 @@ def test_resumes_selected_for_initial_deletions_when_explicitly_marked(mocker, r def fn(**_): pass - handlers = registry.get_resource_changing_handlers(cause) + with pytest.deprecated_call(match=r"use registry.resource_changing_handlers"): + handlers = registry.get_resource_changing_handlers(cause) assert len(handlers) == 1 assert handlers[0].fn is fn