Skip to content

Commit c351f1e

Browse files
committed
fix: item_dict returns empty stanzas
This fix is a result of migrating from splunk-appinspect to this library in pytest-splunk-addon. Reference PR: splunk/pytest-splunk-addon#464 Closes #36.
1 parent ae26caf commit c351f1e

File tree

2 files changed

+36
-2
lines changed

2 files changed

+36
-2
lines changed

addonfactory_splunk_conf_parser_lib.py

Lines changed: 1 addition & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -227,6 +227,5 @@ def item_dict(self):
227227
):
228228
continue
229229
kv[k] = v
230-
if kv:
231-
res[section] = kv
230+
res[section] = kv
232231
return res

test_addonfactory_splunk_conf_parser_lib.py

Lines changed: 35 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -163,6 +163,41 @@ def test_item_dict(self):
163163
}
164164
self.assertEqual(expected_item_dict, parser.item_dict())
165165

166+
def test_item_dict_when_there_is_empty_stanza(self):
167+
conf = """
168+
[stanza_with_something]
169+
key = value
170+
171+
[empty_stanza]
172+
"""
173+
parser = conf_parser.TABConfigParser()
174+
parser.read_string(conf)
175+
expected_item_dict = {
176+
"stanza_with_something": {
177+
"key": "value",
178+
},
179+
"empty_stanza": {},
180+
}
181+
self.assertEqual(expected_item_dict, parser.item_dict())
182+
183+
def test_item_dict_when_there_is_empty_stanza_and_comment(self):
184+
conf = """
185+
[stanza_with_something]
186+
key = value
187+
188+
[empty_stanza]
189+
# This is a comment
190+
"""
191+
parser = conf_parser.TABConfigParser()
192+
parser.read_string(conf)
193+
expected_item_dict = {
194+
"stanza_with_something": {
195+
"key": "value",
196+
},
197+
"empty_stanza": {},
198+
}
199+
self.assertEqual(expected_item_dict, parser.item_dict())
200+
166201
def test_remove_existing_section(self):
167202
conf = """
168203
# Comment

0 commit comments

Comments
 (0)