From 8cbae6306a53056379662bdd0725366da34a1140 Mon Sep 17 00:00:00 2001 From: Darshan Varasani Date: Fri, 8 Aug 2025 17:21:41 +0530 Subject: [PATCH] feat: add support of python3.13 with CIM v5 --- pytest_splunk_addon/addon_parser/props_parser.py | 4 ++-- pytest_splunk_addon/sample_generation/rule.py | 6 +++--- pytest_splunk_addon/sample_generation/sample_stanza.py | 2 +- pytest_splunk_addon/splunk.py | 2 +- .../test_event_ingestors/test_ingestor_helper.py | 2 +- 5 files changed, 8 insertions(+), 8 deletions(-) diff --git a/pytest_splunk_addon/addon_parser/props_parser.py b/pytest_splunk_addon/addon_parser/props_parser.py index b1275156a..22800faf9 100644 --- a/pytest_splunk_addon/addon_parser/props_parser.py +++ b/pytest_splunk_addon/addon_parser/props_parser.py @@ -203,7 +203,7 @@ def _get_extract_fields(self, name: str, value: str): yield field # If SOURCE_KEY is used in EXTRACT, generate the test for the same. - regex_for_source_key = r"(?:(?i)in\s+(\w+))\s*$" + regex_for_source_key = r"(?i)(?:in\s+(\w+))\s*$" extract_source_key = re.search(regex_for_source_key, value, re.MULTILINE) if extract_source_key: LOGGER.info(f"Found a source key in {name}") @@ -260,7 +260,7 @@ def _get_fieldalias_fields(self, name: str, value: str): """ regex = ( r"(\"(?:\\\"|[^\"])*\"|\'(?:\\\'|[^\'])*\'|[^\s,]+)" - r"\s+(?i)(?:as(?:new)?)\s+" + r"\s+(?:as(?:new)?)\s+" r"(\"(?:\\\"|[^\"])*\"|\'(?:\\\'|[^\'])*\'|[^\s,]+)" ) fields_tuples = re.findall(regex, value, re.IGNORECASE) diff --git a/pytest_splunk_addon/sample_generation/rule.py b/pytest_splunk_addon/sample_generation/rule.py index ff86134c7..272f6bcf2 100644 --- a/pytest_splunk_addon/sample_generation/rule.py +++ b/pytest_splunk_addon/sample_generation/rule.py @@ -188,7 +188,7 @@ def apply(self, events): .replace(".", "-") ) host_split = host.split("-") - if re.match("\d+", host_split[-1]): + if re.match(r"\d+", host_split[-1]): host = "-".join(host_split[:-1]) new_event.metadata["host"] = "{}-{}".format( host, event_host_count @@ -327,7 +327,7 @@ def replace(self, sample, token_count): float_match = re.match(r"[Ff]loat\[(-?[\d\.]+):(-?[\d\.]+)\]", self.replacement) if float_match: lower_limit, upper_limit = float_match.groups() - precision = re.search("\[-?\d+\.?(\d*):", self.replacement).group(1) + precision = re.search(r"\[-?\d+\.?(\d*):", self.replacement).group(1) if not precision: precision = str(1) for _ in range(token_count): @@ -681,7 +681,7 @@ def replace(self, sample, token_count): yield self.token for _ in range(token_count): random_time = datetime.fromtimestamp( - randint(earliest_in_epoch, latest_in_epoch) + randint(int(earliest_in_epoch), int(latest_in_epoch)) ) if timezone_time in ["local", '"local"', "'local'"]: random_time = random_time.replace(tzinfo=timezone.utc).astimezone( diff --git a/pytest_splunk_addon/sample_generation/sample_stanza.py b/pytest_splunk_addon/sample_generation/sample_stanza.py index 0d75aab4e..05c443ac1 100644 --- a/pytest_splunk_addon/sample_generation/sample_stanza.py +++ b/pytest_splunk_addon/sample_generation/sample_stanza.py @@ -25,7 +25,7 @@ LOGGER = logging.getLogger("pytest-splunk-addon") -TIMEZONE_REX = "((\+1[0-2])|(-1[0-4])|[+|-][0][0-9])([0-5][0-9])" +TIMEZONE_REX = r"((\+1[0-2])|(-1[0-4])|[+|-][0][0-9])([0-5][0-9])" BULK_EVENT_COUNT = 250 token_value = namedtuple("token_value", ["key", "value"]) diff --git a/pytest_splunk_addon/splunk.py b/pytest_splunk_addon/splunk.py index 5916dda5b..fd40f3ccf 100644 --- a/pytest_splunk_addon/splunk.py +++ b/pytest_splunk_addon/splunk.py @@ -842,7 +842,7 @@ def docker_ip(): if not docker_host: return "127.0.0.1" - match = re.match("^tcp://(.+?):\d+$", docker_host) + match = re.match(r"^tcp://(.+?):\d+$", docker_host) if not match: raise ValueError('Invalid value for DOCKER_HOST: "%s".' % (docker_host,)) return match.group(1) diff --git a/tests/unit/tests_standard_lib/test_event_ingestors/test_ingestor_helper.py b/tests/unit/tests_standard_lib/test_event_ingestors/test_ingestor_helper.py index 3d9a37dc6..2d6702a5b 100644 --- a/tests/unit/tests_standard_lib/test_event_ingestors/test_ingestor_helper.py +++ b/tests/unit/tests_standard_lib/test_event_ingestors/test_ingestor_helper.py @@ -103,7 +103,7 @@ def test_ingestor_can_be_obtained( ingestor_helper.get_event_ingestor(ingest_method, "ingest_meta_data") == expected_output ) - assert ingestors_mocks[expected_output].has_calls("ingest_meta_data") + ingestors_mocks[expected_output].assert_called_with("ingest_meta_data") @pytest.mark.parametrize(