Handle OSError in :config-write-py

This commit is contained in:
Florian Bruhin 2017-11-17 09:09:02 +01:00
parent 8fb03208e7
commit 2b063f577e
2 changed files with 9 additions and 1 deletions

View File

@ -289,4 +289,7 @@ class ConfigCommands:
writer = configfiles.ConfigPyWriter(options, bindings,
commented=commented)
writer.write(filename)
try:
writer.write(filename)
except OSError as e:
raise cmdexc.CommandError(str(e))

View File

@ -413,6 +413,11 @@ class TestWritePy:
lines = confpy.read_text('utf-8').splitlines()
assert '# Autogenerated config.py' in lines
def test_oserror(self, commands, tmpdir):
"""Test writing to a directory which does not exist."""
with pytest.raises(cmdexc.CommandError):
commands.config_write_py(str(tmpdir / 'foo' / 'config.py'))
class TestBind: