From f2472a88841b00821e8cf23e06c4245e88f81e49 Mon Sep 17 00:00:00 2001 From: Viktor Kertesz Date: Fri, 11 Oct 2024 12:25:41 +0000 Subject: [PATCH] fix user provided input case (in)sensitivity --- scrapli/driver/generic/base_driver.py | 4 ++++ tests/unit/driver/generic/test_generic_async_driver.py | 9 ++++++++- tests/unit/driver/generic/test_generic_sync_driver.py | 9 ++++++++- 3 files changed, 20 insertions(+), 2 deletions(-) diff --git a/scrapli/driver/generic/base_driver.py b/scrapli/driver/generic/base_driver.py index cdc78ac5..364435ec 100644 --- a/scrapli/driver/generic/base_driver.py +++ b/scrapli/driver/generic/base_driver.py @@ -123,6 +123,8 @@ def contains_bytes(self) -> bytes: """ if self.contains and not self._contains_bytes: self._contains_bytes = self.contains.encode() + if self.case_insensitive: + self._contains_bytes = self._contains_bytes.lower() return self._contains_bytes @@ -143,6 +145,8 @@ def not_contains_bytes(self) -> bytes: """ if self.not_contains and not self._not_contains_bytes: self._not_contains_bytes = self.not_contains.encode() + if self.case_insensitive: + self._not_contains_bytes = self._not_contains_bytes.lower() return self._not_contains_bytes diff --git a/tests/unit/driver/generic/test_generic_async_driver.py b/tests/unit/driver/generic/test_generic_async_driver.py index b279fea8..4e1affb4 100644 --- a/tests/unit/driver/generic/test_generic_async_driver.py +++ b/tests/unit/driver/generic/test_generic_async_driver.py @@ -142,6 +142,13 @@ async def callback_two(cls, read_output): case_insensitive=False, only_once=True, ), + ReadCallback( + contains="RTR1#", + callback=callback_one, + name="call1.5", + case_insensitive=True, + only_once=True, + ), ReadCallback( contains_re=r"^rtr1#", callback=callback_two, @@ -151,5 +158,5 @@ async def callback_two(cls, read_output): await async_generic_driver.read_callback(callbacks=callbacks, initial_input="nada") - assert callback_one_counter == 1 + assert callback_one_counter == 2 assert callback_two_counter == 1 diff --git a/tests/unit/driver/generic/test_generic_sync_driver.py b/tests/unit/driver/generic/test_generic_sync_driver.py index 7bac0521..3e23863f 100644 --- a/tests/unit/driver/generic/test_generic_sync_driver.py +++ b/tests/unit/driver/generic/test_generic_sync_driver.py @@ -131,6 +131,13 @@ def callback_two(cls, read_output): case_insensitive=False, only_once=True, ), + ReadCallback( + contains="RTR1#", + callback=callback_one, + name="call1.5", + case_insensitive=True, + only_once=True, + ), ReadCallback( contains_re=r"^rtr1#", callback=callback_two, @@ -140,5 +147,5 @@ def callback_two(cls, read_output): sync_generic_driver.read_callback(callbacks=callbacks, initial_input="nada") - assert callback_one_counter == 1 + assert callback_one_counter == 2 assert callback_two_counter == 1