Skip to content

Commit

Permalink
fix processor tests in cause of changing processingcrititcalerror
Browse files Browse the repository at this point in the history
  • Loading branch information
ekneg54 committed Oct 1, 2024
1 parent 72b7882 commit 61e184d
Show file tree
Hide file tree
Showing 4 changed files with 15 additions and 14 deletions.
4 changes: 2 additions & 2 deletions logprep/abc/processor.py
Original file line number Diff line number Diff line change
Expand Up @@ -274,8 +274,8 @@ def _apply_rules_wrapper(self, event: dict, rule: "Rule"):
except ProcessingCriticalError as error:
self.result.errors.append(error) # is needed to prevent wrapping it in itself
event.clear()
except Exception as error:
self.result.errors.append(ProcessingCriticalError(str(error), rule, event))
except Exception as error: # pylint: disable=broad-except
self.result.errors.append(ProcessingCriticalError(str(error), rule))
event.clear()
if not hasattr(rule, "delete_source_fields"):
return
Expand Down
7 changes: 2 additions & 5 deletions logprep/processor/generic_resolver/processor.py
Original file line number Diff line number Diff line change
Expand Up @@ -41,8 +41,8 @@
class GenericResolverError(ProcessingCriticalError):
"""Base class for GenericResolver related exceptions."""

def __init__(self, name: str, message: str, rule: GenericResolverRule, event: dict):
super().__init__(f"{name}: {message}", rule=rule, event=event)
def __init__(self, name: str, message: str, rule: GenericResolverRule):
super().__init__(f"{name}: {message}", rule=rule)


class GenericResolver(FieldManager):
Expand Down Expand Up @@ -82,7 +82,6 @@ def _apply_rules(self, event, rule):
self.name,
"Mapping group is missing in mapping file pattern!",
rule=rule,
event=event,
)
dest_val = replacements.get(mapping)
if dest_val:
Expand Down Expand Up @@ -151,12 +150,10 @@ def ensure_rules_from_file(self, rule):
f'\'{rule.resolve_from_file["path"]}\''
f" must be a dictionary with string values!",
rule=rule,
event=None,
)
except FileNotFoundError as error:
raise GenericResolverError(
self.name,
f'Additions file \'{rule.resolve_from_file["path"]}' f"' not found!",
rule=rule,
event=None,
) from error
14 changes: 10 additions & 4 deletions tests/unit/exceptions/test_processing_exceptions.py
Original file line number Diff line number Diff line change
Expand Up @@ -3,6 +3,8 @@
# pylint: disable=protected-access
# pylint: disable=line-too-long

from unittest import mock

from logprep.processor.base.exceptions import (
FieldExistsWarning,
ProcessingCriticalError,
Expand All @@ -23,7 +25,7 @@ class TestProcessingWarning(ExceptionBaseTest):
counted_metric_name = "number_of_warnings"


class TestFieldExsitsWarning(ExceptionBaseTest):
class TestFieldExistsWarning(ExceptionBaseTest):
exception = FieldExistsWarning
error_message = (
r"FieldExistsWarning: The following fields could not be written,"
Expand All @@ -42,13 +44,17 @@ class TestProcessingCriticalError(ExceptionBaseTest):
exception = ProcessingCriticalError

error_message = (
r"ProcessingCriticalError: the error message ->"
r" event was send to error output and further processing stopped, "
r"rule.id='.+', rule.description='', event=\{'message': 'test_event'\}"
r"ProcessingCriticalError: 'the error message' -> "
r"rule.id: '.*' -> "
r"event was send to error output and further processing stopped"
)

counted_metric_name = "number_of_errors"

def setup_method(self):
super().setup_method()
self.exception_args = ("the error message", self.object)


class TestProcessingError(ExceptionBaseTest):
exception = ProcessingError
Expand Down
4 changes: 1 addition & 3 deletions tests/unit/processor/base.py
Original file line number Diff line number Diff line change
Expand Up @@ -322,9 +322,7 @@ def test_process_collects_errors_in_result_object(self):
with mock.patch.object(
self.object,
"_apply_rules",
side_effect=ProcessingCriticalError(
"side effect", rule=self.object.rules[0], event=self.match_all_event
),
side_effect=ProcessingCriticalError("side effect", rule=self.object.rules[0]),
):
result = self.object.process(self.match_all_event)
assert len(result.errors) > 0, "minimum one error should be in result object"
Expand Down

0 comments on commit 61e184d

Please sign in to comment.