Skip to content

Commit

Permalink
fixed raise and added tests
Browse files Browse the repository at this point in the history
  • Loading branch information
forrejam committed Sep 16, 2024
1 parent 87f350f commit 9f5d9d0
Show file tree
Hide file tree
Showing 3 changed files with 18 additions and 3 deletions.
6 changes: 3 additions & 3 deletions scrapli/helper.py
Original file line number Diff line number Diff line change
Expand Up @@ -113,7 +113,7 @@ def textfsm_parse(
output: structured data
Raises:
N/A
textfsm.parser.TextFSMError: If raise_err is set and a textfsm parsing error occours
"""
import textfsm # pylint: disable=C0415
Expand All @@ -137,10 +137,10 @@ def textfsm_parse(
structured_output=structured_output, header=re_table.header
)
return structured_output
except textfsm.parser.TextFSMError as e:
except textfsm.parser.TextFSMError:
logger.warning("failed to parse data with textfsm")
if raise_err:
raise e
raise
return []


Expand Down
7 changes: 7 additions & 0 deletions tests/unit/test_helper.py
Original file line number Diff line number Diff line change
Expand Up @@ -142,6 +142,13 @@ def test_textfsm_parse_failed_to_parse():
assert result == []


def test_textfsm_parse_failed_to_parse_with_raise():
template = _textfsm_get_template("cisco_ios", "show ip arp")
with pytest.raises(Exception):
result = textfsm_parse(template, "not really arp data", raise_err=True)
assert result == []


@pytest.mark.skipif(
sys.version_info.minor > 10, reason="genie not currently available for python 3.11"
)
Expand Down
8 changes: 8 additions & 0 deletions tests/unit/test_response.py
Original file line number Diff line number Diff line change
Expand Up @@ -155,6 +155,14 @@ def test_response_parse_textfsm_fail():
assert response.textfsm_parse_output() == []


def test_response_parse_textfsm_fail_with_raise():
response = Response("localhost", channel_input="show ip arp", textfsm_platform="cisco_ios")
response_bytes = b"not ip arp output"
response.record_response(response_bytes)
with pytest.raises(Exception):
assert response.textfsm_parse_output(raise_err=True) == []


def test_response_parse_textfsm_no_template():
response = Response("localhost", channel_input="show ip arp", textfsm_platform="potato")
response_bytes = b""
Expand Down

0 comments on commit 9f5d9d0

Please sign in to comment.