Skip to content

Commit

Permalink
Convert to private method; add tests
Browse files Browse the repository at this point in the history
  • Loading branch information
ktbyers committed Nov 8, 2024
1 parent e09fa2b commit da97740
Show file tree
Hide file tree
Showing 2 changed files with 31 additions and 3 deletions.
4 changes: 2 additions & 2 deletions netmiko/nokia/nokia_srl.py
Original file line number Diff line number Diff line change
Expand Up @@ -56,9 +56,9 @@ def session_preparation(self) -> None:
def strip_prompt(self, *args: Any, **kwargs: Any) -> str:
"""Strip the line1 of multiline prompt from the output."""
a_string = super().strip_prompt(*args, **kwargs)
return self.strip_context_items(a_string)
return self._strip_context_items(a_string)

def strip_context_items(self, a_string: str) -> str:
def _strip_context_items(self, a_string: str) -> str:
"""Strip NokiaSRL-specific output.
Nokia will put extra context is line 1 of the prompt, such as:
Expand Down
30 changes: 29 additions & 1 deletion tests/unit/test_base_connection.py
Original file line number Diff line number Diff line change
@@ -1,5 +1,5 @@
#!/usr/bin/env python

import pytest
import time
from os.path import dirname, join
from threading import Lock
Expand Down Expand Up @@ -553,3 +553,31 @@ def test_disable_sha2_fix():
assert {"rsa-sha2-512", "rsa-sha2-256"} & allowed_pubkeys == set()

connection.disconnect()


TEST_CASES = [
("some important data\n--{ running }--[ ]--\nA:srl1#", "some important data"),
(
"more data\nsome important data\n--{ running }--[ ]--\nA:srl1#",
"more data\nsome important data",
),
(
"more data\nsome important data\n--{ candidate private private-admin }--[ ]--\nA:srl1#",
"more data\nsome important data",
),
(
"more data\nsome important data\n--{ candidate private private-admin }--[ ]--\nA:srl1#",
"more data\nsome important data",
),
]


@pytest.mark.parametrize("test_string,expected", TEST_CASES)
def test_nokiasrl_prompt_stripping(test_string, expected):
conn = ConnectHandler(
host="testhost",
device_type="nokia_srl",
auto_connect=False, # No need to connect for the test purposes
)
result = conn.strip_prompt(a_string=test_string)
assert result == expected

0 comments on commit da97740

Please sign in to comment.