зеркало из https://github.com/mozilla/gecko-dev.git
Bug 1580620 - [mozbase] Make manifestparser fail on duplicate keys even without strict mode r=gbrown
Differential Revision: https://phabricator.services.mozilla.com/D45592 --HG-- extra : moz-landing-system : lando
This commit is contained in:
Родитель
33cc71cc3b
Коммит
9a9c5a8311
|
@ -123,11 +123,13 @@ def read_ini(fp, variables=None, default='DEFAULT', defaults_only=False,
|
|||
value = value.strip()
|
||||
key_indent = line_indent
|
||||
|
||||
# make sure this key isn't already in the section
|
||||
if key and current_section is not variables:
|
||||
assert key not in current_section
|
||||
|
||||
if strict:
|
||||
# make sure this key isn't already in the section or empty
|
||||
# make sure this key isn't empty
|
||||
assert key
|
||||
if current_section is not variables:
|
||||
assert key not in current_section
|
||||
|
||||
current_section[key] = value
|
||||
break
|
||||
|
|
|
@ -21,11 +21,11 @@ import mozunit
|
|||
|
||||
class IniParserTest(unittest.TestCase):
|
||||
|
||||
def parse_manifest(self, string):
|
||||
def parse_manifest(self, string, **kwargs):
|
||||
buf = StringIO()
|
||||
buf.write(string)
|
||||
buf.seek(0)
|
||||
return read_ini(buf)
|
||||
return read_ini(buf, **kwargs)
|
||||
|
||||
def test_inline_comments(self):
|
||||
result = self.parse_manifest("""
|
||||
|
@ -59,6 +59,18 @@ birds=nope
|
|||
self.assertEqual(result[1][1]['dogs'].split(), ['yep', 'yep'])
|
||||
self.assertEqual(result[1][1]['birds'].split(), ['nope', 'fish=nope'])
|
||||
|
||||
def test_dupes_error(self):
|
||||
dupes = """
|
||||
[test_dupes.py]
|
||||
foo = bar
|
||||
foo = baz
|
||||
"""
|
||||
with self.assertRaises(AssertionError):
|
||||
self.parse_manifest(dupes, strict=True)
|
||||
|
||||
with self.assertRaises(AssertionError):
|
||||
self.parse_manifest(dupes, strict=False)
|
||||
|
||||
|
||||
if __name__ == '__main__':
|
||||
mozunit.main()
|
||||
|
|
Загрузка…
Ссылка в новой задаче