config: don't crash with a config file containing only comments

This commit is contained in:
Aldo Cortesi 2017-06-13 09:33:29 +12:00
parent 06cb68c799
commit d95f28e6bf
2 changed files with 6 additions and 0 deletions

View File

@ -432,6 +432,8 @@ def parse(text):
raise exceptions.OptionsError("Could not parse options.")
if isinstance(data, str):
raise exceptions.OptionsError("Config error - no keys found.")
elif data is None:
return {}
return data

View File

@ -257,6 +257,10 @@ def test_serialize():
with pytest.raises(Exception, match="Config error"):
optmanager.load(o2, t)
t = "# a comment"
optmanager.load(o2, t)
assert optmanager.load(o2, "foobar: '123'") == {"foobar": "123"}
t = ""
optmanager.load(o2, t)
assert optmanager.load(o2, "foobar: '123'") == {"foobar": "123"}