Skip to content

Commit e72cf4b

Browse files
committed
test(unit/cli): Simplify targets checks for binding manager processors
1 parent 7548e39 commit e72cf4b

File tree

1 file changed

+14
-14
lines changed

1 file changed

+14
-14
lines changed

tests/unit/cli/test_binding_manager.py

Lines changed: 14 additions & 14 deletions
Original file line numberDiff line numberDiff line change
@@ -34,8 +34,7 @@
3434

3535
from powerapi.cli.binding_manager import PreProcessorBindingManager
3636
from powerapi.dispatcher import DispatcherActor
37-
from powerapi.exception import UnsupportedActorTypeException, UnexistingActorException, \
38-
TargetActorAlreadyUsed
37+
from powerapi.exception import UnsupportedActorTypeException, UnexistingActorException, TargetActorAlreadyUsed
3938
from powerapi.processor.processor_actor import ProcessorActor
4039

4140

@@ -134,35 +133,36 @@ def test_check_processors_targets_are_unique_pass_without_reused_puller_in_bindi
134133
pytest.fail("Processors targets are not unique")
135134

136135

137-
def test_check_processor_targets_raise_exception_with_no_existing_puller(
138-
pre_processor_binding_manager_with_unexisting_puller):
136+
def check_all_processors_targets(preprocessor_binding_manager: PreProcessorBindingManager):
137+
"""
138+
Helper function that checks the processors targets of the given binding manager.
139+
"""
140+
for processor in preprocessor_binding_manager.processors.values():
141+
preprocessor_binding_manager.check_processor_targets(processor)
142+
143+
144+
def test_check_processor_targets_raise_exception_with_no_existing_puller(pre_processor_binding_manager_with_unexisting_puller):
139145
"""
140146
Test that an exception is raised with a puller that doesn't exist
141147
"""
142-
pre_processor_binding_manager = pre_processor_binding_manager_with_unexisting_puller
143148
with pytest.raises(UnexistingActorException):
144-
for _, processor in pre_processor_binding_manager.processors.items():
145-
pre_processor_binding_manager.check_processor_targets(processor=processor)
149+
check_all_processors_targets(pre_processor_binding_manager_with_unexisting_puller)
146150

147151

148-
def test_check_processor_targets_raise_exception_with_raise_exception_with_wrong_binding_types(
149-
pre_processor_binding_manager_with_wrong_binding_types):
152+
def test_check_processor_targets_raise_exception_with_raise_exception_with_wrong_binding_types(pre_processor_binding_manager_with_wrong_binding_types):
150153
"""
151154
Test that an exception is raised with a puller that doesn't exist
152155
"""
153-
pre_processor_binding_manager = pre_processor_binding_manager_with_wrong_binding_types
154156
with pytest.raises(UnsupportedActorTypeException):
155-
for _, processor in pre_processor_binding_manager.processors.items():
156-
pre_processor_binding_manager.check_processor_targets(processor=processor)
157+
check_all_processors_targets(pre_processor_binding_manager_with_wrong_binding_types)
157158

158159

159160
def test_check_processor_targets_pass_with_correct_targets(pre_processor_binding_manager):
160161
"""
161162
Test that validation of a configuration with existing targets of the correct type
162163
"""
163164
try:
164-
for _, processor in pre_processor_binding_manager.processors.items():
165-
pre_processor_binding_manager.check_processor_targets(processor=processor)
165+
check_all_processors_targets(pre_processor_binding_manager)
166166
except UnsupportedActorTypeException as e:
167167
pytest.fail(f'Unsupported actor type: {e}')
168168
except UnexistingActorException as e:

0 commit comments

Comments
 (0)