Skip to content

Commit d5763ef

Browse files
authored
Merge pull request #69 from networktocode-llc/fix_67
Fix 67
2 parents 5a893b5 + 58e82a5 commit d5763ef

File tree

2 files changed

+20
-0
lines changed

2 files changed

+20
-0
lines changed

netcompare/check_types.py

Lines changed: 3 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -72,6 +72,9 @@ def get_value(output: Union[Mapping, List], path: str = "*", exclude: List = Non
7272

7373
values = jmespath.search(jmespath_value_parser(path), output)
7474

75+
if values is None:
76+
raise TypeError("JMSPath returned 'None'. Please, verify your JMSPath regex.")
77+
7578
# check for multi-nested lists if not found return here
7679
if not any(isinstance(i, list) for i in values):
7780
return values

tests/test_get_value.py

Lines changed: 17 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,17 @@
1+
"""Test GitHub issues."""
2+
import pytest
3+
from netcompare import CheckType
4+
5+
6+
my_data = [{"global": {"peers": {"10.1.0.0": "peer1", "10.2.0.0": "peer2"}}}]
7+
8+
9+
@pytest.mark.parametrize("data", my_data)
10+
def test_jmspath_return_none(data):
11+
"""Handle exception when JMSPath retunr None."""
12+
my_jmspath = "global[*]"
13+
my_check = CheckType.init(check_type="exact_match")
14+
with pytest.raises(TypeError) as error:
15+
my_check.get_value(output=data, path=my_jmspath)() # pylint: disable=E0110
16+
17+
assert "JMSPath returned 'None'. Please, verify your JMSPath regex." in error.value.__str__()

0 commit comments

Comments
 (0)