def testParser(self): test_data = r""" key1 = a list of \ fields # but not \n this, or \ this. # Nothing here. key 2:another entry = # Bad line 'a key'with" no" value field ;; and not this comment. """ expected = [{ "key1": ["a", "list", "of", "fields"] }, { "key 2": ["another", "entry"] }, { "a keywith no value field": [] }] cfg = config_file.KeyValueParser(kv_sep=["=", ":"], comments=["#", ";;"]) results = cfg.ParseEntries(test_data) for i, expect in enumerate(expected): self.assertDictEqual(expect, results[i])
def __init__(self, *args, **kwargs): super(SysctlCmdParser, self).__init__(*args, **kwargs) self.lexer = config_file.KeyValueParser()