Skip to content

Commit 4aafeeb

Browse files
committed
Refactor to simplify code.
1 parent 7165e74 commit 4aafeeb

File tree

2 files changed

+5
-5
lines changed

2 files changed

+5
-5
lines changed

jdiff/utils/jmespath_parsers.py

+3-3
Original file line numberDiff line numberDiff line change
@@ -31,15 +31,15 @@ def jmespath_value_parser(path: str):
3131
path_suffix = path.split(".")[-1]
3232

3333
if regex_match_ref_key:
34+
reference_key = regex_match_ref_key.group()
3435
if regex_ref_key.search(path_suffix):
3536
# [$peerAddress$,prefixesReceived] --> [prefixesReceived]
36-
reference_key = regex_match_ref_key.group()
3737
return path.replace(reference_key, "")
3838

3939
# result[0].$vrfs$.default... --> result[0].vrfs.default....
40-
regex_normalized_value = re.search(r"\$.*\$", regex_match_ref_key.group())
40+
regex_normalized_value = re.search(r"\$.*\$", reference_key)
4141
if regex_normalized_value:
42-
normalized_value = regex_match_ref_key.group().split("$")[1]
42+
normalized_value = reference_key.split("$")[1]
4343
return path.replace(regex_normalized_value.group(), normalized_value)
4444
return path
4545

tests/test_get_value.py

+2-2
Original file line numberDiff line numberDiff line change
@@ -30,7 +30,7 @@ def test_jmspath_return_none(jmspath):
3030
]
3131

3232

33-
test_cases_extract_data__with_ref_key = [
33+
test_cases_extract_data_with_ref_key = [
3434
(
3535
"global.peers.$*$.*.ipv6.[accepted_prefixes]",
3636
[
@@ -48,7 +48,7 @@ def test_jmspath_return_none(jmspath):
4848

4949

5050
@pytest.mark.parametrize(
51-
"jmspath, expected_value", test_cases_extract_data_no_ref_key + test_cases_extract_data__with_ref_key
51+
"jmspath, expected_value", test_cases_extract_data_no_ref_key + test_cases_extract_data_with_ref_key
5252
)
5353
def test_extract_data_from_json(jmspath, expected_value):
5454
"""Test JMSPath return value."""

0 commit comments

Comments
 (0)