From 5f839a3b585266158a9ba9f1c5d330b46c759623 Mon Sep 17 00:00:00 2001 From: 55535K Date: Mon, 31 Aug 2026 16:03:01 +0200 Subject: [PATCH 1/9] =?UTF-8?q?=E2=99=BB=EF=B8=8F=20make=20Melusine=20Rege?= =?UTF-8?q?x=20return=20a=20dataclass?= MIME-Version: 1.0 Content-Type: text/plain; charset=UTF-8 Content-Transfer-Encoding: 8bit --- docs/tutorials/00_GettingStarted.md | 10 +- docs/tutorials/08_MelusineRegex.md | 18 +- melusine/__init__.py | 2 +- melusine/base.py | 232 +++++++++++++----- melusine/detectors.py | 10 +- tests/base/test_melusine_regex.py | 76 ++++-- tests/detectors/test_emergency_detector.py | 13 +- tests/detectors/test_reply_detector.py | 13 +- tests/detectors/test_thanks_detector.py | 26 +- tests/detectors/test_transfer_detector.py | 13 +- .../detectors/test_vacation_reply_detector.py | 21 +- 11 files changed, 297 insertions(+), 137 deletions(-) diff --git a/docs/tutorials/00_GettingStarted.md b/docs/tutorials/00_GettingStarted.md index 87eab5e5..84fae5cf 100644 --- a/docs/tutorials/00_GettingStarted.md +++ b/docs/tutorials/00_GettingStarted.md @@ -108,8 +108,8 @@ Inspecting the debug data gives a lot of info: - `text`: Effective text considered for detection. - `EmergencyRegex`: melusine used an `EmergencyRegex` object to run detection. - `match_result`: The `EmergencyRegex` did not match the text. -- `positive_match_data`: The `EmergencyRegex` matched **positively** the text pattern "Urgent" (Required condition). -- `negative_match_data`: The `EmergencyRegex` matched **negatively** the text pattern "Mr. Annoying" (Forbidden condition). +- `positive`: The `EmergencyRegex` matched **positively** the text pattern "Urgent" (Required condition). +- `negative`: The `EmergencyRegex` matched **negatively** the text pattern "Mr. Annoying" (Forbidden condition). - `BLACKLIST`: Detection groups can be defined to easily link a matching pattern to the corresponding regex. DEFAULT is used if no detection group is specified. ```Python @@ -118,12 +118,12 @@ Inspecting the debug data gives a lot of info: 'text': 'Latest news\nUrgent update about Mr. Annoying'}, 'EmergencyRegex': { 'match_result': False, - 'negative_match_data': { + 'negative': { 'BLACKLIST': [ {'match_text': 'Mr. Annoying', 'start': 32, 'stop': 44} ]}, - 'neutral_match_data': {}, - 'positive_match_data': { + 'neutral': {}, + 'positive': { 'DEFAULT': [ {'match_text': 'Urgent', 'start': 12, 'stop': 18} ] diff --git a/docs/tutorials/08_MelusineRegex.md b/docs/tutorials/08_MelusineRegex.md index e974b798..eba78324 100644 --- a/docs/tutorials/08_MelusineRegex.md +++ b/docs/tutorials/08_MelusineRegex.md @@ -48,8 +48,8 @@ to_delete_detection = to_delete_regex( "You shall not pass through the magical portal of the lake from Monday to Thursday as it is currently under repair." ) -print(to_delete_detection[MelusineRegex.MATCH_RESULT]) # (1)! -print(to_delete_detection[MelusineRegex.POSITIVE_MATCH_FIELD]) # (2)! +print(to_delete_detection.match_result) # (1)! +print(to_delete_detection.positive) # (2)! ``` 1. Prints `True` @@ -96,7 +96,7 @@ to_delete_regex = AnnoyingEmailsRegex() email = "You shall not pass through the magical portal of the lake from Monday to Thursday as it is currently under repair." to_delete_detection = to_delete_regex(email) -print(to_delete_detection[MelusineRegex.MATCH_RESULT]) # (1)! +print(to_delete_detection.match_result) # (1)! ``` 1. Prints `False` @@ -116,9 +116,9 @@ class PreMatchHookAnnoyingEmailsRegex(AnnoyingEmailsRegex): return text preprocessed_to_delete_regex = PreMatchHookAnnoyingEmailsRegex() - spell_result = preprocessed_to_delete_regex.get_match_result( + spell_result = preprocessed_to_delete_regex( "Andthen,, I told Morgana 'You sholl not pass!' as she wanted topass... Im stil wonddering why she did not find it fundny..." - ) + ).match_result ``` ## Using the regex result @@ -129,9 +129,9 @@ The complete `to_delete_detection` object looks like this: ``` json { "match_result":False, - "neutral_match_data":{ + "neutral":{ }, - "negative_match_data":{ + "negative":{ "PORTAL_MENTIONNED":[ { "start":31, @@ -140,7 +140,7 @@ The complete `to_delete_detection` object looks like this: } ] }, - "positive_match_data":{ + "positive":{ "GANDALF_BEING_GANDALF":[ { "start":0, @@ -155,7 +155,7 @@ The complete `to_delete_detection` object looks like this: For a more straightforward approach, if you only need the regex result, you can use the following syntax: ``` python -spell_analysis_result: bool = to_delete_regex.get_match_result(email) # (1)! +spell_analysis_result: bool = to_delete_regex(email).match_result # (1)! ``` 1. Returns `True` Some of the older fairies might need a more detailed explanation on what triggered the deletion of an email. diff --git a/melusine/__init__.py b/melusine/__init__.py index d95d8520..0ef47fc6 100644 --- a/melusine/__init__.py +++ b/melusine/__init__.py @@ -7,7 +7,7 @@ __all__ = ["config", "MelusinePipeline"] -VERSION = (3, 3, 4) +VERSION = (3, 4, 0) __version__ = ".".join(map(str, VERSION)) # ------------------------------- # diff --git a/melusine/base.py b/melusine/base.py index 9bce041d..32e2eb8c 100644 --- a/melusine/base.py +++ b/melusine/base.py @@ -20,6 +20,7 @@ import warnings from abc import ABC, abstractmethod from collections.abc import Callable, Iterable +from dataclasses import dataclass, field from typing import Any, TypeAlias, TypeVar import pandas as pd @@ -39,6 +40,18 @@ class TransformError(Exception): """Exception raised when an error occurs during the transform operation.""" +class DeprecatedClassAttribute: + """Descriptor exposing a deprecated class/instance attribute with warning.""" + + def __init__(self, value: str, message: str): + self._value = value + self._message = message + + def __get__(self, instance, owner) -> str: + warnings.warn(self._message, DeprecationWarning, stacklevel=2) + return self._value + + class MelusineTransformer(IoMixin): """Define a MelusineTransformer object. @@ -350,25 +363,120 @@ class MissingFieldError(Exception): """Exception raised when a missing field is encountered by a MelusineTransformer""" -MatchData = dict[str, list[dict[str, Any]]] +@dataclass(frozen=True) +class MelusineRegexUnitMatch: + start: int + stop: int + match_text: str + + def __getitem__(self, index): + return getattr(self, index) + + +MatchData: TypeAlias = dict[str, list[MelusineRegexUnitMatch]] + + +@dataclass +class MelusineRegexFullMatch: + match_result: bool = False + positive: MatchData = field(default_factory=dict) + neutral: MatchData = field(default_factory=dict) + negative: MatchData = field(default_factory=dict) + + @property + def positive_match_data(self): + """Legacy attribute name for compatibility""" + warnings.warn( + "positive_match_data attribute is deprecated, please use positive instead", + DeprecationWarning, + stacklevel=2, + ) + return self.positive + + @property + def neutral_match_data(self): + """Legacy attribute name for compatibility""" + warnings.warn( + "neutral_match_data attribute is deprecated, please use neutral instead", + DeprecationWarning, + stacklevel=2, + ) + return self.neutral + + @property + def negative_match_data(self): + """Legacy attribute name for compatibility""" + warnings.warn( + "negative_match_data attribute is deprecated, please use negative instead", + DeprecationWarning, + stacklevel=2, + ) + return self.negative + + def reset_match(self, value: bool = False): + self.match_result = value + + def reset_positive(self, values: MatchData | None = None) -> None: + self.positive = values or {} + + def reset_neutral(self, values: MatchData | None = None) -> None: + self.neutral = values or {} + + def reset_negative(self, values: MatchData | None = None) -> None: + self.negative = values or {} + + @property + def positive_keys(self): + return self.positive.keys() + + @property + def neutral_keys(self): + return self.neutral.keys() + + @property + def negative_keys(self): + return self.negative.keys() + + def __getitem__(self, index): + return getattr(self, index) class MelusineRegex(ABC): - """Class to standardise text pattern detection using regex.""" + """Class to standardize text pattern detection using regex.""" REGEX_FLAGS: re.RegexFlag = re.IGNORECASE | re.MULTILINE PAIRED_MATCHING_PREFIX: str = "_" - # Match fields - MATCH_RESULT: str = "match_result" - NEUTRAL_MATCH_FIELD: str = "neutral_match_data" - POSITIVE_MATCH_FIELD: str = "positive_match_data" - NEGATIVE_MATCH_FIELD: str = "negative_match_data" - - # Match data - MATCH_START: str = "start" - MATCH_STOP: str = "stop" - MATCH_TEXT: str = "match_text" + # Legacy aliases kept for compatibility + MATCH_RESULT = DeprecatedClassAttribute( + value="match_result", + message="MATCH_RESULT is deprecated, please use output.match_result instead", + ) + NEUTRAL_MATCH_FIELD = DeprecatedClassAttribute( + value="neutral_match_data", + message="NEUTRAL_MATCH_FIELD is deprecated, please use my_result.neutral instead", + ) + POSITIVE_MATCH_FIELD = DeprecatedClassAttribute( + value="positive_match_data", + message="POSITIVE_MATCH_FIELD is deprecated, please use output.positive instead", + ) + NEGATIVE_MATCH_FIELD = DeprecatedClassAttribute( + value="negative_match_data", + message="NEGATIVE_MATCH_FIELD is deprecated, please use output.negative instead", + ) + + MATCH_START = DeprecatedClassAttribute( + value="start", + message="MATCH_START is deprecated", + ) + MATCH_STOP = DeprecatedClassAttribute( + value="stop", + message="MATCH_STOP is deprecated", + ) + MATCH_TEXT = DeprecatedClassAttribute( + value="match_text", + message="MATCH_TEXT is deprecated", + ) def __init__(self, substitution_pattern: str = " ", default_match_group: str = "DEFAULT"): if not isinstance(substitution_pattern, str) or (len(substitution_pattern) > 1): @@ -439,7 +547,7 @@ def no_match_list(self) -> list[str]: def _get_match( self, text: str, base_regex: str | dict[str, str], regex_group: str | None = None - ) -> dict[str, list[dict[str, Any]]]: + ) -> MatchData: """Run specified regex on the input text and return a dict with matching group as key. Args: @@ -469,11 +577,11 @@ def _get_match( start, stop = match.span() match_data_dict[regex_group].append( - { - self.MATCH_START: start, - self.MATCH_STOP: stop, - self.MATCH_TEXT: text[start:stop], - } + MelusineRegexUnitMatch( + start=start, + stop=stop, + match_text=text[start:stop], + ) ) return match_data_dict @@ -481,7 +589,7 @@ def _get_match( def ignore_text( self, text: str, - match_data_dict: dict[str, list[dict[str, Any]]], + match_data_dict: MatchData, ) -> str: """Replace neutral regex match text with substitution text to ignore it. @@ -495,8 +603,8 @@ def ignore_text( """ for _, match_list in match_data_dict.items(): for match_data in match_list: - start = match_data[self.MATCH_START] - stop = match_data[self.MATCH_STOP] + start = match_data.start + stop = match_data.stop # Mask text to ignore text = text[:start] + self.substitution_pattern * (stop - start) + text[stop:] @@ -504,20 +612,16 @@ def ignore_text( return text def get_match_result(self, text: str) -> bool: - """Apply MelusineRegex patterns (neutral, negative and positive) on the input text. - Return a boolean output of the match result. - - Args: - text: input text. - - Returns: - _: True if the MelusineRegex matches the input text. - - """ - result = self(text) - return result[self.MATCH_RESULT] + """Legacy method for compatibility""" + warnings.warn( + "get_match_result method is deprecated, please use result.match_result instead.", + DeprecationWarning, + stacklevel=2, + ) + result : MelusineRegexFullMatch = self(text) + return result.match_result - def __call__(self, text: str) -> dict[str, Any]: + def __call__(self, text: str) -> MelusineRegexFullMatch: """Apply MelusineRegex patterns (neutral, negative and positive) on the input text. Return a detailed output of the match results as a dict. @@ -531,31 +635,31 @@ def __call__(self, text: str) -> dict[str, Any]: # Apply pre match hook text = self.pre_match_hook(text) - match_dict = { - self.MATCH_RESULT: False, - self.NEUTRAL_MATCH_FIELD: {}, - self.NEGATIVE_MATCH_FIELD: {}, - self.POSITIVE_MATCH_FIELD: {}, - } + match_dict = MelusineRegexFullMatch( + match_result=False, + neutral={}, + negative={}, + positive={}, + ) negative_match = False if self.neutral: neutral_match_data = self._get_match(text=text, base_regex=self.neutral) - match_dict[self.NEUTRAL_MATCH_FIELD] = neutral_match_data + match_dict.neutral = neutral_match_data text = self.ignore_text(text, neutral_match_data) if self.negative: negative_match_data = self._get_match(text=text, base_regex=self.negative) negative_match = bool(negative_match_data) - match_dict[self.NEGATIVE_MATCH_FIELD] = negative_match_data + match_dict.negative = negative_match_data positive_match_data = self._get_match(text=text, base_regex=self.positive) positive_match = bool(positive_match_data) - match_dict[self.POSITIVE_MATCH_FIELD] = positive_match_data + match_dict.positive = positive_match_data - match_dict[self.MATCH_RESULT] = positive_match and not negative_match + match_dict.match_result = positive_match and not negative_match # Apply post match hook match_dict = self.post_match_hook(match_dict) @@ -571,7 +675,7 @@ def describe(self, text: str, position: bool = False) -> None: """ - def _describe_match_field(match_field_data: dict[str, list[dict[str, Any]]]) -> None: + def _describe_match_field(match_field_data: MatchData) -> None: """Format and print result description text. Args: @@ -580,39 +684,39 @@ def _describe_match_field(match_field_data: dict[str, list[dict[str, Any]]]) -> """ for group, match_list in match_field_data.items(): for match_dict in match_list: - print(f"{indent}({group}) {match_dict[self.MATCH_TEXT]}") + print(f"{indent}({group}) {match_dict.match_text}") if position: - print(f"{indent}start: {match_dict[self.MATCH_START]}") - print(f"{indent}stop: {match_dict[self.MATCH_STOP]}") + print(f"{indent}start: {match_dict.start}") + print(f"{indent}stop: {match_dict.stop}") indent = " " * 4 match_data = self(text) - if match_data[self.MATCH_RESULT]: + if match_data.match_result: print("The MelusineRegex match result is : POSITIVE") else: print("The MelusineRegex match result is : NEGATIVE") if not any( [ - match_data[self.NEUTRAL_MATCH_FIELD], - match_data[self.NEGATIVE_MATCH_FIELD], - match_data[self.POSITIVE_MATCH_FIELD], + match_data.neutral, + match_data.negative, + match_data.positive, ] ): print("The input text did not match anything.") - if match_data[self.NEUTRAL_MATCH_FIELD]: + if match_data.neutral: print("The following text was ignored:") - _describe_match_field(match_data[self.NEUTRAL_MATCH_FIELD]) + _describe_match_field(match_data.neutral) - if match_data[self.NEGATIVE_MATCH_FIELD]: + if match_data.negative: print("The following text matched negatively:") - _describe_match_field(match_data[self.NEGATIVE_MATCH_FIELD]) + _describe_match_field(match_data.negative) - if match_data[self.POSITIVE_MATCH_FIELD]: + if match_data.positive: print("The following text matched positively:") - _describe_match_field(match_data[self.POSITIVE_MATCH_FIELD]) + _describe_match_field(match_data.positive) def apply_paired_matching(self, negative_match_data: MatchData, positive_match_data: MatchData) -> bool: """Check if negative match is effective in the case of paired matching. @@ -650,7 +754,7 @@ def pre_match_hook(self, text: str) -> str: """ return text - def post_match_hook(self, match_dict: dict[str, Any]) -> dict[str, Any]: + def post_match_hook(self, match_dict: MelusineRegexFullMatch) -> MelusineRegexFullMatch: """Hook to run after the Melusine regex match. Args: @@ -662,11 +766,11 @@ def post_match_hook(self, match_dict: dict[str, Any]) -> dict[str, Any]: """ # Paired matching negative_match = self.apply_paired_matching( - match_dict[self.NEGATIVE_MATCH_FIELD], match_dict[self.POSITIVE_MATCH_FIELD] + match_dict.negative, match_dict.positive ) - positive_match = bool(match_dict[self.POSITIVE_MATCH_FIELD]) + positive_match = bool(match_dict.positive) - match_dict[self.MATCH_RESULT] = positive_match and not negative_match + match_dict.match_result = positive_match and not negative_match return match_dict @@ -674,11 +778,11 @@ def test(self) -> None: """Test the MelusineRegex on the match_list and no_match_list.""" for text in self.match_list: match = self(text) - assert match[self.MATCH_RESULT] is True, f"Expected match for text\n{text}\nObtained: {match}" + assert match.match_result is True, f"Expected match for text\n{text}\nObtained: {match}" for text in self.no_match_list: match = self(text) - assert match[self.MATCH_RESULT] is False, f"Expected no match for text:\n{text}\nObtained: {match}" + assert match.match_result is False, f"Expected no match for text:\n{text}\nObtained: {match}" def __repr__(self) -> str: """Repr for the class MelusineRegex.""" diff --git a/melusine/detectors.py b/melusine/detectors.py index dc929376..85bdfece 100644 --- a/melusine/detectors.py +++ b/melusine/detectors.py @@ -124,7 +124,7 @@ def detect(self, row: MelusineItem, debug_mode: bool = False) -> MelusineItem: text: str = row[self.THANKS_TEXT_COL] detection_data = self.thanks_regex(text) - detection_result = detection_data[self.thanks_regex.MATCH_RESULT] + detection_result = detection_data.match_result # Save debug data if debug_mode: @@ -249,7 +249,7 @@ def detect(self, row: MelusineItem, debug_mode: bool = False) -> MelusineItem: text: str = row[self.CONST_TEXT_COL_NAME] detection_data = self.vacation_reply_regex(text) - detection_result = detection_data[self.vacation_reply_regex.MATCH_RESULT] + detection_result = detection_data.match_result # Save debug data if debug_mode: @@ -374,7 +374,7 @@ def detect(self, row: MelusineItem, debug_mode: bool = False) -> MelusineItem: text: str = row[self.CONST_ANALYSED_TEXT_COL] detection_data = self.reply_regex(text) - detection_result = detection_data[MelusineRegex.MATCH_RESULT] + detection_result = detection_data.match_result # Save debug data if debug_mode: @@ -504,7 +504,7 @@ def detect(self, row: MelusineItem, debug_mode: bool = False) -> MelusineItem: meta: str = row[self.messages_column][0].meta detection_data = self.transfer_regex(text) - detection_result = detection_data[MelusineRegex.MATCH_RESULT] + detection_result = detection_data.match_result # Save debug data if debug_mode: @@ -630,7 +630,7 @@ def detect(self, row: MelusineItem, debug_mode: bool = False) -> MelusineItem: text: str = row[self.CONST_TEXT_COL_NAME] detection_data = self.regex(text) - detection_result = detection_data[self.regex.MATCH_RESULT] + detection_result = detection_data.match_result # Save debug data if debug_mode: diff --git a/tests/base/test_melusine_regex.py b/tests/base/test_melusine_regex.py index f056fd62..0e0f0477 100644 --- a/tests/base/test_melusine_regex.py +++ b/tests/base/test_melusine_regex.py @@ -2,7 +2,7 @@ import pytest -from melusine.base import MelusineRegex +from melusine.base import MelusineRegex, MelusineRegexFullMatch, MelusineRegexUnitMatch class VirusRegex(MelusineRegex): @@ -58,29 +58,29 @@ def test_match_method(): regex = VirusRegex() match_data = regex("The computer virus in the ladybug software caused a bug in the corona virus dashboard") - assert match_data[MelusineRegex.MATCH_RESULT] is False - assert match_data[MelusineRegex.POSITIVE_MATCH_FIELD] == { - "DEFAULT": [{"match_text": "virus", "start": 13, "stop": 18}] + assert match_data.match_result is False + assert match_data.positive == { + "DEFAULT": [MelusineRegexUnitMatch(**{"match_text": "virus", "start": 13, "stop": 18})] } - assert match_data[MelusineRegex.NEUTRAL_MATCH_FIELD] == { - "NEUTRAL_INSECT": [{"match_text": "ladybug", "start": 26, "stop": 33}], - "NEUTRAL_MEDICAL_VIRUS": [{"match_text": "corona virus", "start": 63, "stop": 75}], + assert match_data.neutral == { + "NEUTRAL_INSECT": [MelusineRegexUnitMatch(**{"match_text": "ladybug", "start": 26, "stop": 33})], + "NEUTRAL_MEDICAL_VIRUS": [MelusineRegexUnitMatch(**{"match_text": "corona virus", "start": 63, "stop": 75})], } - assert match_data[MelusineRegex.NEGATIVE_MATCH_FIELD] == { - "NEGATIVE_BUG": [{"match_text": "bug", "start": 52, "stop": 55}] + assert match_data.negative == { + "NEGATIVE_BUG": [MelusineRegexUnitMatch(**{"match_text": "bug", "start": 52, "stop": 55})] } def test_direct_match_method(): regex = VirusRegex() - bool_match_result = regex.get_match_result("The computer virus") + bool_match_result = regex("The computer virus").match_result assert bool_match_result is True - bool_match_result = regex.get_match_result( + bool_match_result = regex( "The computer virus in the ladybug software caused a bug in the corona virus dashboard" - ) + ).match_result assert bool_match_result is False @@ -161,20 +161,20 @@ def pre_match_hook(self, text: str) -> str: def test_pre_match_hook(): reg = PreMatchHookVirusRegex() - bool_match_result = reg.get_match_result("I see a virrrrus !") + bool_match_result = reg("I see a virrrrus !").match_result assert bool_match_result is True class PostMatchHookVirusRegex(VirusRegex): - def post_match_hook(self, match_dict: Dict[str, Any]) -> Dict[str, Any]: + def post_match_hook(self, match_dict: MelusineRegexFullMatch) -> MelusineRegexFullMatch: """Test custom post processing of match data""" if ( - match_dict[self.MATCH_RESULT] is True - and "NEUTRAL_MEDICAL_VIRUS" in match_dict[self.NEUTRAL_MATCH_FIELD] - and "NEUTRAL_INSECT" in match_dict[self.NEUTRAL_MATCH_FIELD] + match_dict.match_result is True + and "NEUTRAL_MEDICAL_VIRUS" in match_dict.neutral + and "NEUTRAL_INSECT" in match_dict.neutral ): - match_dict[self.MATCH_RESULT] = False + match_dict.match_result = False return match_dict @@ -182,10 +182,10 @@ def post_match_hook(self, match_dict: Dict[str, Any]) -> Dict[str, Any]: def test_post_match_hook(): reg = PostMatchHookVirusRegex() - bool_match_result = reg.get_match_result("I see a virus, a corona virus and a ladybug") + bool_match_result = reg("I see a virus, a corona virus and a ladybug").match_result assert bool_match_result is False - bool_match_result = reg.get_match_result("I see a virus and a ladybug") + bool_match_result = reg("I see a virus and a ladybug").match_result assert bool_match_result is True @@ -229,3 +229,39 @@ def no_match_list(self) -> List[str]: def test_paired_matching_test(): regex = PairedMatchRegex() regex.test() + + +@pytest.mark.parametrize( + "attr_name,expected", + [ + ("MATCH_RESULT", "match_result"), + ("NEUTRAL_MATCH_FIELD", "neutral_match_data"), + ("POSITIVE_MATCH_FIELD", "positive_match_data"), + ("NEGATIVE_MATCH_FIELD", "negative_match_data"), + ("MATCH_START", "start"), + ("MATCH_STOP", "stop"), + ("MATCH_TEXT", "match_text"), + ], +) +def test_legacy_regex_attributes_warn_on_class_access(attr_name, expected): + with pytest.deprecated_call(match=attr_name): + assert getattr(MelusineRegex, attr_name) == expected + + +@pytest.mark.parametrize( + "attr_name,expected", + [ + ("MATCH_RESULT", "match_result"), + ("NEUTRAL_MATCH_FIELD", "neutral_match_data"), + ("POSITIVE_MATCH_FIELD", "positive_match_data"), + ("NEGATIVE_MATCH_FIELD", "negative_match_data"), + ("MATCH_START", "start"), + ("MATCH_STOP", "stop"), + ("MATCH_TEXT", "match_text"), + ], +) +def test_legacy_regex_attributes_warn_on_instance_access(attr_name, expected): + regex = VirusRegex() + with pytest.deprecated_call(match=attr_name): + assert getattr(regex, attr_name) == expected + diff --git a/tests/detectors/test_emergency_detector.py b/tests/detectors/test_emergency_detector.py index 0d4a7850..c0be206b 100644 --- a/tests/detectors/test_emergency_detector.py +++ b/tests/detectors/test_emergency_detector.py @@ -6,17 +6,20 @@ import pandas as pd import pytest +from melusine.base import MelusineRegexFullMatch, MelusineRegexUnitMatch from melusine.detectors import EmergencyDetector @pytest.fixture def emergency_detector_df(): - m0_debug_expected = { + m0_debug_expected = MelusineRegexFullMatch(**{ "match_result": True, - "negative_match_data": {}, - "neutral_match_data": {}, - "positive_match_data": {"DEFAULT": [{"match_text": "urgent", "start": 10, "stop": 16}]}, - } + "negative": {}, + "neutral": {}, + "positive": {"DEFAULT": [ + MelusineRegexUnitMatch(**{"match_text": "urgent", "start": 10, "stop": 16}) + ]}, + }) df = pd.DataFrame( { diff --git a/tests/detectors/test_reply_detector.py b/tests/detectors/test_reply_detector.py index c4fe6159..02b09157 100644 --- a/tests/detectors/test_reply_detector.py +++ b/tests/detectors/test_reply_detector.py @@ -6,6 +6,7 @@ import pytest from pandas import DataFrame +from melusine.base import MelusineRegexFullMatch, MelusineRegexUnitMatch from melusine.detectors import ReplyDetector from melusine.pipeline import MelusinePipeline @@ -131,12 +132,14 @@ def test_transform(df_emails, expected_result): ), True, { - "ReplyRegex": { + "ReplyRegex": MelusineRegexFullMatch(**{ "match_result": True, - "negative_match_data": {}, - "neutral_match_data": {}, - "positive_match_data": {"DEFAULT": [{"match_text": "re:", "start": 0, "stop": 3}]}, - }, + "negative": {}, + "neutral": {}, + "positive": {"DEFAULT": [ + MelusineRegexUnitMatch(**{"match_text": "re:", "start": 0, "stop": 3}) + ]}, + }), "reply_text": "re: suivi de dossier", }, ), diff --git a/tests/detectors/test_thanks_detector.py b/tests/detectors/test_thanks_detector.py index c17bbcd4..24adfc94 100644 --- a/tests/detectors/test_thanks_detector.py +++ b/tests/detectors/test_thanks_detector.py @@ -8,7 +8,7 @@ import pandas as pd import pytest -from melusine.base import MissingFieldError +from melusine.base import MissingFieldError, MelusineRegexFullMatch, MelusineRegexUnitMatch from melusine.detectors import ThanksDetector from melusine.message import Message @@ -22,12 +22,13 @@ def thanks_detector_df(): ] m0_messages = [m0] m0_expected = True - m0_debug_expected = { + m0_debug_expected = MelusineRegexFullMatch(**{ "match_result": True, - "negative_match_data": {}, - "neutral_match_data": {}, - "positive_match_data": {"DEFAULT": [{"match_text": "Merci", "start": 0, "stop": 5}]}, - } + "negative": {}, + "neutral": {}, + "positive": {"DEFAULT": [ + MelusineRegexUnitMatch(**{"match_text": "Merci", "start": 0, "stop": 5})]}, + }) m1 = Message("") m1.tags = [ @@ -36,12 +37,15 @@ def thanks_detector_df(): ] m1_messages = [m1] m1_expected = False - m1_debug_expected = { + m1_debug_expected = MelusineRegexFullMatch(**{ "match_result": False, - "negative_match_data": {"FORBIDDEN_WORDS": [{"match_text": "attend", "start": 9, "stop": 15}]}, - "neutral_match_data": {}, - "positive_match_data": {"DEFAULT": [{"match_text": "Merci", "start": 0, "stop": 5}]}, - } + "negative": {"FORBIDDEN_WORDS": [ + MelusineRegexUnitMatch(**{"match_text": "attend", "start": 9, "stop": 15})]}, + "neutral": {}, + "positive": {"DEFAULT": [ + MelusineRegexUnitMatch(**{"match_text": "Merci", "start": 0, "stop": 5}) + ]}, + }) df = pd.DataFrame( { diff --git a/tests/detectors/test_transfer_detector.py b/tests/detectors/test_transfer_detector.py index 9a86907f..bd3e292f 100644 --- a/tests/detectors/test_transfer_detector.py +++ b/tests/detectors/test_transfer_detector.py @@ -6,6 +6,7 @@ import pytest from pandas import DataFrame +from melusine.base import MelusineRegexFullMatch, MelusineRegexUnitMatch from melusine.detectors import TransferDetector from melusine.message import Message from melusine.pipeline import MelusinePipeline @@ -205,12 +206,14 @@ def test_transform(df_emails, expected_result): { "reply_text": "tr: suivi de dossier", "messages[0].meta": "", - "TransferRegex": { + "TransferRegex": MelusineRegexFullMatch(**{ "match_result": True, - "negative_match_data": {}, - "neutral_match_data": {}, - "positive_match_data": {"DEFAULT": [{"match_text": "tr:", "start": 0, "stop": 3}]}, - }, + "negative": {}, + "neutral": {}, + "positive": {"DEFAULT": [ + MelusineRegexUnitMatch(**{"match_text": "tr:", "start": 0, "stop": 3}) + ]}, + }), }, ), ], diff --git a/tests/detectors/test_vacation_reply_detector.py b/tests/detectors/test_vacation_reply_detector.py index d606ebeb..861ebb4f 100644 --- a/tests/detectors/test_vacation_reply_detector.py +++ b/tests/detectors/test_vacation_reply_detector.py @@ -6,6 +6,7 @@ import pytest from pandas import DataFrame +from melusine.base import MelusineRegexFullMatch, MelusineRegexUnitMatch from melusine.detectors import VacationReplyDetector from melusine.message import Message from melusine.pipeline import MelusinePipeline @@ -113,17 +114,23 @@ def test_transform(df, good_result): True, { "text": "Actuellement en conge je prendrai connaissance de votre message ulterieurement.", - "VacationReplyRegex": { + "VacationReplyRegex": MelusineRegexFullMatch(**{ "match_result": True, - "negative_match_data": {}, - "neutral_match_data": {}, - "positive_match_data": { - "VAC_REP_HOLIDAYS": [{"match_text": "Actuellement " "en " "conge", "start": 0, "stop": 21}], + "negative": {}, + "neutral": {}, + "positive": { + "VAC_REP_HOLIDAYS": [ + MelusineRegexUnitMatch(**{ + "match_text": "Actuellement en conge", "start": 0, "stop": 21 + }) + ], "VAC_REP_OUT_OF_OFFICE": [ - {"match_text": "je " "prendrai " "connaissance", "start": 22, "stop": 46} + MelusineRegexUnitMatch(**{ + "match_text": "je prendrai connaissance", "start": 22, "stop": 46 + }) ], }, - }, + }), }, ), ], From 840a32b772d3b95107ab61464345cc602bfa17af Mon Sep 17 00:00:00 2001 From: 55535K Date: Mon, 31 Aug 2026 16:39:20 +0200 Subject: [PATCH 2/9] =?UTF-8?q?=E2=99=BB=EF=B8=8F=20make=20Melusine=20Rege?= =?UTF-8?q?x=20return=20a=20dataclass?= MIME-Version: 1.0 Content-Type: text/plain; charset=UTF-8 Content-Transfer-Encoding: 8bit --- melusine/base.py | 10 +++------- 1 file changed, 3 insertions(+), 7 deletions(-) diff --git a/melusine/base.py b/melusine/base.py index 32e2eb8c..a4b1324d 100644 --- a/melusine/base.py +++ b/melusine/base.py @@ -545,9 +545,7 @@ def no_match_list(self) -> list[str]: """ - def _get_match( - self, text: str, base_regex: str | dict[str, str], regex_group: str | None = None - ) -> MatchData: + def _get_match(self, text: str, base_regex: str | dict[str, str], regex_group: str | None = None) -> MatchData: """Run specified regex on the input text and return a dict with matching group as key. Args: @@ -618,7 +616,7 @@ def get_match_result(self, text: str) -> bool: DeprecationWarning, stacklevel=2, ) - result : MelusineRegexFullMatch = self(text) + result: MelusineRegexFullMatch = self(text) return result.match_result def __call__(self, text: str) -> MelusineRegexFullMatch: @@ -765,9 +763,7 @@ def post_match_hook(self, match_dict: MelusineRegexFullMatch) -> MelusineRegexFu """ # Paired matching - negative_match = self.apply_paired_matching( - match_dict.negative, match_dict.positive - ) + negative_match = self.apply_paired_matching(match_dict.negative, match_dict.positive) positive_match = bool(match_dict.positive) match_dict.match_result = positive_match and not negative_match From 18aa0ceeb83a4545513da8c73e99a19e57a126ba Mon Sep 17 00:00:00 2001 From: 55535K Date: Mon, 31 Aug 2026 16:39:58 +0200 Subject: [PATCH 3/9] =?UTF-8?q?=E2=9C=85=20Update=20tests?= MIME-Version: 1.0 Content-Type: text/plain; charset=UTF-8 Content-Transfer-Encoding: 8bit --- tests/base/test_melusine_regex.py | 23 ++++++++++------------- 1 file changed, 10 insertions(+), 13 deletions(-) diff --git a/tests/base/test_melusine_regex.py b/tests/base/test_melusine_regex.py index 0e0f0477..b3d96e9e 100644 --- a/tests/base/test_melusine_regex.py +++ b/tests/base/test_melusine_regex.py @@ -247,21 +247,18 @@ def test_legacy_regex_attributes_warn_on_class_access(attr_name, expected): with pytest.deprecated_call(match=attr_name): assert getattr(MelusineRegex, attr_name) == expected - @pytest.mark.parametrize( - "attr_name,expected", + "attribute", [ - ("MATCH_RESULT", "match_result"), - ("NEUTRAL_MATCH_FIELD", "neutral_match_data"), - ("POSITIVE_MATCH_FIELD", "positive_match_data"), - ("NEGATIVE_MATCH_FIELD", "negative_match_data"), - ("MATCH_START", "start"), - ("MATCH_STOP", "stop"), - ("MATCH_TEXT", "match_text"), - ], + "positive_match_data", + "neutral_match_data", + "negative_match_data", + ] ) -def test_legacy_regex_attributes_warn_on_instance_access(attr_name, expected): +def test_legacy_dict_access(attribute): regex = VirusRegex() - with pytest.deprecated_call(match=attr_name): - assert getattr(regex, attr_name) == expected + match_data = regex("The computer virus in the ladybug software caused a bug in the corona virus dashboard") + + with pytest.deprecated_call(match=attribute): + assert match_data[attribute] == getattr(match_data, attribute) From 80e927db27485807a1052f714157851666ad38ff Mon Sep 17 00:00:00 2001 From: 55535K Date: Mon, 31 Aug 2026 16:53:09 +0200 Subject: [PATCH 4/9] =?UTF-8?q?=E2=9C=85=20Update=20tests?= MIME-Version: 1.0 Content-Type: text/plain; charset=UTF-8 Content-Transfer-Encoding: 8bit --- melusine/base.py | 17 +++++++++++++++++ tests/base/test_melusine_regex.py | 3 ++- tests/detectors/test_thanks_detector.py | 5 +---- 3 files changed, 20 insertions(+), 5 deletions(-) diff --git a/melusine/base.py b/melusine/base.py index a4b1324d..2f5a58e7 100644 --- a/melusine/base.py +++ b/melusine/base.py @@ -48,6 +48,7 @@ def __init__(self, value: str, message: str): self._message = message def __get__(self, instance, owner) -> str: + """Get""" warnings.warn(self._message, DeprecationWarning, stacklevel=2) return self._value @@ -365,11 +366,13 @@ class MissingFieldError(Exception): @dataclass(frozen=True) class MelusineRegexUnitMatch: + """Dataclass to structure a Unitary MelusineRegex match""" start: int stop: int match_text: str def __getitem__(self, index): + """GetItem""" return getattr(self, index) @@ -378,6 +381,7 @@ def __getitem__(self, index): @dataclass class MelusineRegexFullMatch: + """Dataclass to structure a Full MelusineRegex match""" match_result: bool = False positive: MatchData = field(default_factory=dict) neutral: MatchData = field(default_factory=dict) @@ -414,30 +418,43 @@ def negative_match_data(self): return self.negative def reset_match(self, value: bool = False): + """Reset the match value""" self.match_result = value def reset_positive(self, values: MatchData | None = None) -> None: + """Reset the positive value""" self.positive = values or {} def reset_neutral(self, values: MatchData | None = None) -> None: + """Reset the neutral value""" self.neutral = values or {} def reset_negative(self, values: MatchData | None = None) -> None: + """Reset the negative value""" self.negative = values or {} @property def positive_keys(self): + """Return the keys of positive match data.""" return self.positive.keys() @property def neutral_keys(self): + """Return the keys of neutral match data.""" return self.neutral.keys() @property def negative_keys(self): + """Return the keys of negative match data.""" return self.negative.keys() def __getitem__(self, index): + """Legacy dict like access""" + warnings.warn( + "Dict like access is deprecated, please use direct attribute access instead", + DeprecationWarning, + stacklevel=2, + ) return getattr(self, index) diff --git a/tests/base/test_melusine_regex.py b/tests/base/test_melusine_regex.py index b3d96e9e..a7c2c2a8 100644 --- a/tests/base/test_melusine_regex.py +++ b/tests/base/test_melusine_regex.py @@ -250,6 +250,7 @@ def test_legacy_regex_attributes_warn_on_class_access(attr_name, expected): @pytest.mark.parametrize( "attribute", [ + "match_result", "positive_match_data", "neutral_match_data", "negative_match_data", @@ -260,5 +261,5 @@ def test_legacy_dict_access(attribute): match_data = regex("The computer virus in the ladybug software caused a bug in the corona virus dashboard") - with pytest.deprecated_call(match=attribute): + with pytest.deprecated_call(match="Dict like access is deprecated, please use direct attribute access instead"): assert match_data[attribute] == getattr(match_data, attribute) diff --git a/tests/detectors/test_thanks_detector.py b/tests/detectors/test_thanks_detector.py index 24adfc94..e8fecec0 100644 --- a/tests/detectors/test_thanks_detector.py +++ b/tests/detectors/test_thanks_detector.py @@ -2,13 +2,10 @@ Unit test of the ThanksDetector. """ - -from tempfile import TemporaryDirectory - import pandas as pd import pytest -from melusine.base import MissingFieldError, MelusineRegexFullMatch, MelusineRegexUnitMatch +from melusine.base import MelusineRegexFullMatch, MelusineRegexUnitMatch, MissingFieldError from melusine.detectors import ThanksDetector from melusine.message import Message From 33d3b5f11211b01cad708e40a4a830bda3b62e35 Mon Sep 17 00:00:00 2001 From: 55535K Date: Mon, 31 Aug 2026 16:59:33 +0200 Subject: [PATCH 5/9] =?UTF-8?q?=E2=9C=85=20Update=20tests?= MIME-Version: 1.0 Content-Type: text/plain; charset=UTF-8 Content-Transfer-Encoding: 8bit --- melusine/__init__.py | 10 +++++- melusine/base.py | 2 ++ tests/base/test_melusine_regex.py | 3 +- tests/detectors/test_emergency_detector.py | 16 +++++---- tests/detectors/test_reply_detector.py | 18 +++++----- tests/detectors/test_thanks_detector.py | 18 +++++----- tests/detectors/test_transfer_detector.py | 16 +++++---- .../detectors/test_vacation_reply_detector.py | 36 ++++++++++--------- 8 files changed, 70 insertions(+), 49 deletions(-) diff --git a/melusine/__init__.py b/melusine/__init__.py index 0ef47fc6..5e84a319 100644 --- a/melusine/__init__.py +++ b/melusine/__init__.py @@ -3,9 +3,17 @@ import logging from melusine._config import config +from melusine.base import MelusineDetector, MelusineRegex, MelusineRegexFullMatch, MelusineTransformer from melusine.pipeline import MelusinePipeline -__all__ = ["config", "MelusinePipeline"] +__all__ = [ + "config", + "MelusineDetector", + "MelusineRegex", + "MelusineRegexFullMatch", + "MelusineTransformer", + "MelusinePipeline" +] VERSION = (3, 4, 0) __version__ = ".".join(map(str, VERSION)) diff --git a/melusine/base.py b/melusine/base.py index 2f5a58e7..2ec460f8 100644 --- a/melusine/base.py +++ b/melusine/base.py @@ -367,6 +367,7 @@ class MissingFieldError(Exception): @dataclass(frozen=True) class MelusineRegexUnitMatch: """Dataclass to structure a Unitary MelusineRegex match""" + start: int stop: int match_text: str @@ -382,6 +383,7 @@ def __getitem__(self, index): @dataclass class MelusineRegexFullMatch: """Dataclass to structure a Full MelusineRegex match""" + match_result: bool = False positive: MatchData = field(default_factory=dict) neutral: MatchData = field(default_factory=dict) diff --git a/tests/base/test_melusine_regex.py b/tests/base/test_melusine_regex.py index a7c2c2a8..f86a209f 100644 --- a/tests/base/test_melusine_regex.py +++ b/tests/base/test_melusine_regex.py @@ -247,6 +247,7 @@ def test_legacy_regex_attributes_warn_on_class_access(attr_name, expected): with pytest.deprecated_call(match=attr_name): assert getattr(MelusineRegex, attr_name) == expected + @pytest.mark.parametrize( "attribute", [ @@ -254,7 +255,7 @@ def test_legacy_regex_attributes_warn_on_class_access(attr_name, expected): "positive_match_data", "neutral_match_data", "negative_match_data", - ] + ], ) def test_legacy_dict_access(attribute): regex = VirusRegex() diff --git a/tests/detectors/test_emergency_detector.py b/tests/detectors/test_emergency_detector.py index c0be206b..06aa0a4a 100644 --- a/tests/detectors/test_emergency_detector.py +++ b/tests/detectors/test_emergency_detector.py @@ -12,13 +12,15 @@ @pytest.fixture def emergency_detector_df(): - m0_debug_expected = MelusineRegexFullMatch(**{ - "match_result": True, - "negative": {}, - "neutral": {}, - "positive": {"DEFAULT": [ - MelusineRegexUnitMatch(**{"match_text": "urgent", "start": 10, "stop": 16}) - ]}, + m0_debug_expected = MelusineRegexFullMatch( + **{ + "match_result": True, + "negative": {}, + "neutral": {}, + "positive": {"DEFAULT": [ + MelusineRegexUnitMatch(**{"match_text": "urgent", "start": 10, "stop": 16}) + ] + }, }) df = pd.DataFrame( diff --git a/tests/detectors/test_reply_detector.py b/tests/detectors/test_reply_detector.py index 02b09157..3dd23fd4 100644 --- a/tests/detectors/test_reply_detector.py +++ b/tests/detectors/test_reply_detector.py @@ -132,14 +132,16 @@ def test_transform(df_emails, expected_result): ), True, { - "ReplyRegex": MelusineRegexFullMatch(**{ - "match_result": True, - "negative": {}, - "neutral": {}, - "positive": {"DEFAULT": [ - MelusineRegexUnitMatch(**{"match_text": "re:", "start": 0, "stop": 3}) - ]}, - }), + "ReplyRegex": MelusineRegexFullMatch( + **{ + "match_result": True, + "negative": {}, + "neutral": {}, + "positive": {"DEFAULT": [ + MelusineRegexUnitMatch(**{"match_text": "re:", "start": 0, "stop": 3}) + ]}, + } + ), "reply_text": "re: suivi de dossier", }, ), diff --git a/tests/detectors/test_thanks_detector.py b/tests/detectors/test_thanks_detector.py index e8fecec0..1f81952e 100644 --- a/tests/detectors/test_thanks_detector.py +++ b/tests/detectors/test_thanks_detector.py @@ -34,14 +34,16 @@ def thanks_detector_df(): ] m1_messages = [m1] m1_expected = False - m1_debug_expected = MelusineRegexFullMatch(**{ - "match_result": False, - "negative": {"FORBIDDEN_WORDS": [ - MelusineRegexUnitMatch(**{"match_text": "attend", "start": 9, "stop": 15})]}, - "neutral": {}, - "positive": {"DEFAULT": [ - MelusineRegexUnitMatch(**{"match_text": "Merci", "start": 0, "stop": 5}) - ]}, + m1_debug_expected = MelusineRegexFullMatch( + **{ + "match_result": False, + "negative": {"FORBIDDEN_WORDS": [ + MelusineRegexUnitMatch(**{"match_text": "attend", "start": 9, "stop": 15})]}, + "neutral": {}, + "positive": {"DEFAULT": [ + MelusineRegexUnitMatch(**{"match_text": "Merci", "start": 0, "stop": 5}) + ] + }, }) df = pd.DataFrame( diff --git a/tests/detectors/test_transfer_detector.py b/tests/detectors/test_transfer_detector.py index bd3e292f..2963e1e8 100644 --- a/tests/detectors/test_transfer_detector.py +++ b/tests/detectors/test_transfer_detector.py @@ -206,13 +206,15 @@ def test_transform(df_emails, expected_result): { "reply_text": "tr: suivi de dossier", "messages[0].meta": "", - "TransferRegex": MelusineRegexFullMatch(**{ - "match_result": True, - "negative": {}, - "neutral": {}, - "positive": {"DEFAULT": [ - MelusineRegexUnitMatch(**{"match_text": "tr:", "start": 0, "stop": 3}) - ]}, + "TransferRegex": MelusineRegexFullMatch( + **{ + "match_result": True, + "negative": {}, + "neutral": {}, + "positive": {"DEFAULT": [ + MelusineRegexUnitMatch(**{"match_text": "tr:", "start": 0, "stop": 3}) + ] + }, }), }, ), diff --git a/tests/detectors/test_vacation_reply_detector.py b/tests/detectors/test_vacation_reply_detector.py index 861ebb4f..ec198260 100644 --- a/tests/detectors/test_vacation_reply_detector.py +++ b/tests/detectors/test_vacation_reply_detector.py @@ -114,23 +114,25 @@ def test_transform(df, good_result): True, { "text": "Actuellement en conge je prendrai connaissance de votre message ulterieurement.", - "VacationReplyRegex": MelusineRegexFullMatch(**{ - "match_result": True, - "negative": {}, - "neutral": {}, - "positive": { - "VAC_REP_HOLIDAYS": [ - MelusineRegexUnitMatch(**{ - "match_text": "Actuellement en conge", "start": 0, "stop": 21 - }) - ], - "VAC_REP_OUT_OF_OFFICE": [ - MelusineRegexUnitMatch(**{ - "match_text": "je prendrai connaissance", "start": 22, "stop": 46 - }) - ], - }, - }), + "VacationReplyRegex": MelusineRegexFullMatch( + **{ + "match_result": True, + "negative": {}, + "neutral": {}, + "positive": { + "VAC_REP_HOLIDAYS": [ + MelusineRegexUnitMatch(**{ + "match_text": "Actuellement en conge", "start": 0, "stop": 21 + }) + ], + "VAC_REP_OUT_OF_OFFICE": [ + MelusineRegexUnitMatch(**{ + "match_text": "je prendrai connaissance", "start": 22, "stop": 46 + }) + ], + }, + } + ), }, ), ], From 9cbf368ef33f57e06e16622ee5cd5401ce255eef Mon Sep 17 00:00:00 2001 From: 55535K Date: Mon, 31 Aug 2026 17:07:20 +0200 Subject: [PATCH 6/9] =?UTF-8?q?=E2=9C=85=20Update=20tests?= MIME-Version: 1.0 Content-Type: text/plain; charset=UTF-8 Content-Transfer-Encoding: 8bit --- melusine/__init__.py | 2 +- tests/detectors/test_emergency_detector.py | 4 +--- tests/detectors/test_reply_detector.py | 6 ++--- tests/detectors/test_thanks_detector.py | 22 +++++++++---------- tests/detectors/test_transfer_detector.py | 10 ++++----- .../detectors/test_vacation_reply_detector.py | 16 +++++++++----- 6 files changed, 31 insertions(+), 29 deletions(-) diff --git a/melusine/__init__.py b/melusine/__init__.py index 5e84a319..ffbf66f3 100644 --- a/melusine/__init__.py +++ b/melusine/__init__.py @@ -12,7 +12,7 @@ "MelusineRegex", "MelusineRegexFullMatch", "MelusineTransformer", - "MelusinePipeline" + "MelusinePipeline", ] VERSION = (3, 4, 0) diff --git a/tests/detectors/test_emergency_detector.py b/tests/detectors/test_emergency_detector.py index 06aa0a4a..c9ae65e8 100644 --- a/tests/detectors/test_emergency_detector.py +++ b/tests/detectors/test_emergency_detector.py @@ -17,9 +17,7 @@ def emergency_detector_df(): "match_result": True, "negative": {}, "neutral": {}, - "positive": {"DEFAULT": [ - MelusineRegexUnitMatch(**{"match_text": "urgent", "start": 10, "stop": 16}) - ] + "positive": {"DEFAULT": [MelusineRegexUnitMatch(**{"match_text": "urgent", "start": 10, "stop": 16})] }, }) diff --git a/tests/detectors/test_reply_detector.py b/tests/detectors/test_reply_detector.py index 3dd23fd4..6aa37af4 100644 --- a/tests/detectors/test_reply_detector.py +++ b/tests/detectors/test_reply_detector.py @@ -137,9 +137,9 @@ def test_transform(df_emails, expected_result): "match_result": True, "negative": {}, "neutral": {}, - "positive": {"DEFAULT": [ - MelusineRegexUnitMatch(**{"match_text": "re:", "start": 0, "stop": 3}) - ]}, + "positive": { + "DEFAULT": [MelusineRegexUnitMatch(**{"match_text": "re:", "start": 0, "stop": 3})] + }, } ), "reply_text": "re: suivi de dossier", diff --git a/tests/detectors/test_thanks_detector.py b/tests/detectors/test_thanks_detector.py index 1f81952e..e17f7d9e 100644 --- a/tests/detectors/test_thanks_detector.py +++ b/tests/detectors/test_thanks_detector.py @@ -2,6 +2,7 @@ Unit test of the ThanksDetector. """ + import pandas as pd import pytest @@ -19,13 +20,14 @@ def thanks_detector_df(): ] m0_messages = [m0] m0_expected = True - m0_debug_expected = MelusineRegexFullMatch(**{ - "match_result": True, - "negative": {}, - "neutral": {}, - "positive": {"DEFAULT": [ - MelusineRegexUnitMatch(**{"match_text": "Merci", "start": 0, "stop": 5})]}, - }) + m0_debug_expected = MelusineRegexFullMatch( + **{ + "match_result": True, + "negative": {}, + "neutral": {}, + "positive": {"DEFAULT": [MelusineRegexUnitMatch(**{"match_text": "Merci", "start": 0, "stop": 5})]}, + } + ) m1 = Message("") m1.tags = [ @@ -37,11 +39,9 @@ def thanks_detector_df(): m1_debug_expected = MelusineRegexFullMatch( **{ "match_result": False, - "negative": {"FORBIDDEN_WORDS": [ - MelusineRegexUnitMatch(**{"match_text": "attend", "start": 9, "stop": 15})]}, + "negative": {"FORBIDDEN_WORDS": [MelusineRegexUnitMatch(**{"match_text": "attend", "start": 9, "stop": 15})]}, "neutral": {}, - "positive": {"DEFAULT": [ - MelusineRegexUnitMatch(**{"match_text": "Merci", "start": 0, "stop": 5}) + "positive": {"DEFAULT": [MelusineRegexUnitMatch(**{"match_text": "Merci", "start": 0, "stop": 5}) ] }, }) diff --git a/tests/detectors/test_transfer_detector.py b/tests/detectors/test_transfer_detector.py index 2963e1e8..ae50c519 100644 --- a/tests/detectors/test_transfer_detector.py +++ b/tests/detectors/test_transfer_detector.py @@ -211,11 +211,11 @@ def test_transform(df_emails, expected_result): "match_result": True, "negative": {}, "neutral": {}, - "positive": {"DEFAULT": [ - MelusineRegexUnitMatch(**{"match_text": "tr:", "start": 0, "stop": 3}) - ] - }, - }), + "positive": { + "DEFAULT": [MelusineRegexUnitMatch(**{"match_text": "tr:", "start": 0, "stop": 3})] + }, + } + ), }, ), ], diff --git a/tests/detectors/test_vacation_reply_detector.py b/tests/detectors/test_vacation_reply_detector.py index ec198260..31ba6284 100644 --- a/tests/detectors/test_vacation_reply_detector.py +++ b/tests/detectors/test_vacation_reply_detector.py @@ -121,14 +121,18 @@ def test_transform(df, good_result): "neutral": {}, "positive": { "VAC_REP_HOLIDAYS": [ - MelusineRegexUnitMatch(**{ - "match_text": "Actuellement en conge", "start": 0, "stop": 21 - }) + MelusineRegexUnitMatch( + **{ + "match_text": "Actuellement en conge", "start": 0, "stop": 21 + } + ) ], "VAC_REP_OUT_OF_OFFICE": [ - MelusineRegexUnitMatch(**{ - "match_text": "je prendrai connaissance", "start": 22, "stop": 46 - }) + MelusineRegexUnitMatch( + **{ + "match_text": "je prendrai connaissance", "start": 22, "stop": 46 + } + ) ], }, } From 2ace4ef98a78966bb7eddcc215733293885c253f Mon Sep 17 00:00:00 2001 From: 55535K Date: Mon, 31 Aug 2026 17:17:52 +0200 Subject: [PATCH 7/9] =?UTF-8?q?=E2=9C=85=20Update=20tests?= MIME-Version: 1.0 Content-Type: text/plain; charset=UTF-8 Content-Transfer-Encoding: 8bit --- tests/detectors/test_emergency_detector.py | 2 +- tests/detectors/test_thanks_detector.py | 8 ++++---- tests/detectors/test_vacation_reply_detector.py | 8 ++------ 3 files changed, 7 insertions(+), 11 deletions(-) diff --git a/tests/detectors/test_emergency_detector.py b/tests/detectors/test_emergency_detector.py index c9ae65e8..dab64c64 100644 --- a/tests/detectors/test_emergency_detector.py +++ b/tests/detectors/test_emergency_detector.py @@ -17,7 +17,7 @@ def emergency_detector_df(): "match_result": True, "negative": {}, "neutral": {}, - "positive": {"DEFAULT": [MelusineRegexUnitMatch(**{"match_text": "urgent", "start": 10, "stop": 16})] + "positive": {"DEFAULT": [MelusineRegexUnitMatch(**{"match_text": "urgent", "start": 10, "stop": 16})], }, }) diff --git a/tests/detectors/test_thanks_detector.py b/tests/detectors/test_thanks_detector.py index e17f7d9e..daa4bd8a 100644 --- a/tests/detectors/test_thanks_detector.py +++ b/tests/detectors/test_thanks_detector.py @@ -39,11 +39,11 @@ def thanks_detector_df(): m1_debug_expected = MelusineRegexFullMatch( **{ "match_result": False, - "negative": {"FORBIDDEN_WORDS": [MelusineRegexUnitMatch(**{"match_text": "attend", "start": 9, "stop": 15})]}, + "negative": { + "FORBIDDEN_WORDS": [MelusineRegexUnitMatch(**{"match_text": "attend", "start": 9, "stop": 15})] + }, "neutral": {}, - "positive": {"DEFAULT": [MelusineRegexUnitMatch(**{"match_text": "Merci", "start": 0, "stop": 5}) - ] - }, + "positive": {"DEFAULT": [MelusineRegexUnitMatch(**{"match_text": "Merci", "start": 0, "stop": 5})]}, }) df = pd.DataFrame( diff --git a/tests/detectors/test_vacation_reply_detector.py b/tests/detectors/test_vacation_reply_detector.py index 31ba6284..f913091f 100644 --- a/tests/detectors/test_vacation_reply_detector.py +++ b/tests/detectors/test_vacation_reply_detector.py @@ -122,16 +122,12 @@ def test_transform(df, good_result): "positive": { "VAC_REP_HOLIDAYS": [ MelusineRegexUnitMatch( - **{ - "match_text": "Actuellement en conge", "start": 0, "stop": 21 - } + **{"match_text": "Actuellement en conge", "start": 0, "stop": 21} ) ], "VAC_REP_OUT_OF_OFFICE": [ MelusineRegexUnitMatch( - **{ - "match_text": "je prendrai connaissance", "start": 22, "stop": 46 - } + **{"match_text": "je prendrai connaissance", "start": 22, "stop": 46} ) ], }, From 0ef42738ec32b5b734081a9f5ae85980ba2a6ee6 Mon Sep 17 00:00:00 2001 From: 55535K Date: Mon, 31 Aug 2026 17:22:51 +0200 Subject: [PATCH 8/9] =?UTF-8?q?=E2=9C=85=20Update=20tests?= MIME-Version: 1.0 Content-Type: text/plain; charset=UTF-8 Content-Transfer-Encoding: 8bit --- tests/detectors/test_emergency_detector.py | 3 ++- tests/detectors/test_thanks_detector.py | 3 ++- 2 files changed, 4 insertions(+), 2 deletions(-) diff --git a/tests/detectors/test_emergency_detector.py b/tests/detectors/test_emergency_detector.py index dab64c64..a19074f3 100644 --- a/tests/detectors/test_emergency_detector.py +++ b/tests/detectors/test_emergency_detector.py @@ -17,7 +17,8 @@ def emergency_detector_df(): "match_result": True, "negative": {}, "neutral": {}, - "positive": {"DEFAULT": [MelusineRegexUnitMatch(**{"match_text": "urgent", "start": 10, "stop": 16})], + "positive": { + "DEFAULT": [MelusineRegexUnitMatch(**{"match_text": "urgent", "start": 10, "stop": 16})], }, }) diff --git a/tests/detectors/test_thanks_detector.py b/tests/detectors/test_thanks_detector.py index daa4bd8a..d4965bef 100644 --- a/tests/detectors/test_thanks_detector.py +++ b/tests/detectors/test_thanks_detector.py @@ -44,7 +44,8 @@ def thanks_detector_df(): }, "neutral": {}, "positive": {"DEFAULT": [MelusineRegexUnitMatch(**{"match_text": "Merci", "start": 0, "stop": 5})]}, - }) + } + ) df = pd.DataFrame( { From bb98fbac3650eb9d253868907b7717d1a0c4f50d Mon Sep 17 00:00:00 2001 From: 55535K Date: Mon, 31 Aug 2026 17:26:53 +0200 Subject: [PATCH 9/9] =?UTF-8?q?=E2=9C=85=20Update=20tests?= MIME-Version: 1.0 Content-Type: text/plain; charset=UTF-8 Content-Transfer-Encoding: 8bit --- tests/detectors/test_emergency_detector.py | 5 +++-- 1 file changed, 3 insertions(+), 2 deletions(-) diff --git a/tests/detectors/test_emergency_detector.py b/tests/detectors/test_emergency_detector.py index a19074f3..0b2bd09c 100644 --- a/tests/detectors/test_emergency_detector.py +++ b/tests/detectors/test_emergency_detector.py @@ -19,8 +19,9 @@ def emergency_detector_df(): "neutral": {}, "positive": { "DEFAULT": [MelusineRegexUnitMatch(**{"match_text": "urgent", "start": 10, "stop": 16})], - }, - }) + }, + } + ) df = pd.DataFrame( {