Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

fix read_callback user provided input case (in)sensitivity #352

Merged
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
4 changes: 4 additions & 0 deletions scrapli/driver/generic/base_driver.py
Original file line number Diff line number Diff line change
Expand Up @@ -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

Expand All @@ -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

Expand Down
9 changes: 8 additions & 1 deletion tests/unit/driver/generic/test_generic_async_driver.py
Original file line number Diff line number Diff line change
Expand Up @@ -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,
Expand All @@ -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
9 changes: 8 additions & 1 deletion tests/unit/driver/generic/test_generic_sync_driver.py
Original file line number Diff line number Diff line change
Expand Up @@ -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,
Expand All @@ -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
Loading