@@ -71,6 +71,25 @@ def test_jmspath_return_none(jmspath):
71
71
"" ,
72
72
marks = pytest .mark .xfail (reason = "Jmespath issue - path returns empty list." ),
73
73
),
74
+ ("global.peers.*.is_enabled" , [True , True , False , True ]),
75
+ (
76
+ "global.peers.$*$.is_enabled" ,
77
+ [
78
+ {"10.1.0.0" : {"is_enabled" : True }},
79
+ {"10.2.0.0" : {"is_enabled" : True }},
80
+ {"10.64.207.255" : {"is_enabled" : False }},
81
+ {"7.7.7.7" : {"is_enabled" : True }},
82
+ ],
83
+ ),
84
+ (
85
+ "global.peers.$*$.[is_enabled]" ,
86
+ [
87
+ {"10.1.0.0" : {"is_enabled" : True }},
88
+ {"10.2.0.0" : {"is_enabled" : True }},
89
+ {"10.64.207.255" : {"is_enabled" : False }},
90
+ {"7.7.7.7" : {"is_enabled" : True }},
91
+ ],
92
+ ),
74
93
]
75
94
76
95
@@ -83,3 +102,38 @@ def test_extract_data_from_json(jmspath, expected_value):
83
102
value = extract_data_from_json (data = data , path = jmspath )
84
103
85
104
assert value == expected_value , ASSERT_FAIL_MESSAGE .format (output = value , expected_output = expected_value )
105
+
106
+
107
+ test_cases_top_key_anchor = [
108
+ ("$*$.is_enabled" , [{".local." : {"is_enabled" : True }}, {".local..0" : {"is_enabled" : True }}]),
109
+ ("$*$.is_up" , [{".local." : {"is_up" : True }}, {".local..0" : {"is_up" : True }}]),
110
+ ]
111
+
112
+
113
+ @pytest .mark .parametrize ("jmspath, expected_value" , test_cases_top_key_anchor )
114
+ def test_top_key_anchor (jmspath , expected_value ):
115
+ """Test JMSPath return value for anchoring the top key."""
116
+ data = {
117
+ ".local." : {
118
+ "description" : "" ,
119
+ "is_enabled" : True ,
120
+ "is_up" : True ,
121
+ "last_flapped" : - 1 ,
122
+ "mac_address" : "Unspecified" ,
123
+ "mtu" : 0 ,
124
+ "speed" : - 1 ,
125
+ },
126
+ ".local..0" : {
127
+ "description" : "" ,
128
+ "is_enabled" : True ,
129
+ "is_up" : True ,
130
+ "last_flapped" : - 1 ,
131
+ "mac_address" : "Unspecified" ,
132
+ "mtu" : 0 ,
133
+ "speed" : - 1 ,
134
+ },
135
+ }
136
+
137
+ value = extract_data_from_json (data = data , path = jmspath )
138
+
139
+ assert value == expected_value , ASSERT_FAIL_MESSAGE .format (output = value , expected_output = expected_value )
0 commit comments