Skip to content

Commit 338030c

Browse files
committed
FIx 67
1 parent 4443a22 commit 338030c

File tree

2 files changed

+13
-3
lines changed

2 files changed

+13
-3
lines changed

netcompare/check_types.py

Lines changed: 6 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -1,5 +1,6 @@
11
"""CheckType Implementation."""
22
import re
3+
import json
34
import warnings
45
from typing import Mapping, Tuple, List, Dict, Any, Union
56
from abc import ABC, abstractmethod
@@ -56,6 +57,11 @@ def get_value(output: Union[Mapping, List], path: str = "*", exclude: List = Non
5657
Returns:
5758
Evaluated data, may be anything depending on JMESPath used.
5859
"""
60+
try:
61+
json.loads(output)
62+
except TypeError:
63+
raise TypeError(f"'output' must be a valid JSON object. You have {type(output)}")
64+
5965
if exclude and isinstance(output, Dict):
6066
if not isinstance(exclude, list):
6167
raise ValueError(f"Exclude list must be defined as a list. You have {type(exclude)}")

tests/test_bugs.py

Lines changed: 7 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -6,7 +6,7 @@
66

77
issue_67 = (
88
{"global": {"peers": {"10.1.0.0": "peer1", "10.2.0.0": "peer2"}}},
9-
[]
9+
"TypeError: 'output' must be a valid JSON object. You have <class 'dict'>"
1010
)
1111

1212
issue_67_test = [
@@ -19,5 +19,9 @@ def test_issue_67(data, expected_output):
1919
"""Resolve issue 67: https://github.com/networktocode-llc/netcompare/issues/67"""
2020
my_jmspath = "global[*]"
2121
my_check = CheckType.init(check_type="exact_match")
22-
pre_value = my_check.get_value(output=data, path=my_jmspath)
23-
assert pre_value == pre_value, ASSERT_FAIL_MESSAGE.format(output=pre_value, expected_output=expected_output)
22+
with pytest.raises(TypeError) as error:
23+
my_check.get_value(output=data, path=my_jmspath)() # pylint: disable=E0110
24+
25+
assert (
26+
"'output' must be a valid JSON object. You have <class 'dict'>" in error.value.__str__()
27+
)

0 commit comments

Comments
 (0)