Merge remote-tracking branch 'origin/pr/3561'
This commit is contained in:
commit
1913012c8a
@ -92,6 +92,10 @@ class ConfigErrorDesc:
|
||||
traceback = attr.ib(None)
|
||||
|
||||
def __str__(self):
|
||||
if self.traceback:
|
||||
return '{} - {}: {}'.format(self.text,
|
||||
self.exception.__class__.__name__,
|
||||
self.exception)
|
||||
return '{}: {}'.format(self.text, self.exception)
|
||||
|
||||
def with_text(self, text):
|
||||
|
@ -419,7 +419,7 @@ def read_config_py(filename, raising=False):
|
||||
desc = configexc.ConfigErrorDesc("Error while compiling", e)
|
||||
raise configexc.ConfigFileErrors(basename, [desc])
|
||||
except SyntaxError as e:
|
||||
desc = configexc.ConfigErrorDesc("Syntax Error", e,
|
||||
desc = configexc.ConfigErrorDesc("Unhandled exception", e,
|
||||
traceback=traceback.format_exc())
|
||||
raise configexc.ConfigFileErrors(basename, [desc])
|
||||
|
||||
|
@ -309,6 +309,18 @@ class TestSource:
|
||||
" While setting 'foo': No option 'foo'")
|
||||
assert str(excinfo.value) == expected
|
||||
|
||||
def test_invalid_source(self, commands, config_tmpdir):
|
||||
pyfile = config_tmpdir / 'config.py'
|
||||
pyfile.write_text('1/0', encoding='utf-8')
|
||||
|
||||
with pytest.raises(cmdexc.CommandError) as excinfo:
|
||||
commands.config_source()
|
||||
|
||||
expected = ("Errors occurred while reading config.py:\n"
|
||||
" Unhandled exception - ZeroDivisionError:"
|
||||
" division by zero")
|
||||
assert str(excinfo.value) == expected
|
||||
|
||||
|
||||
class TestEdit:
|
||||
|
||||
|
@ -74,7 +74,7 @@ def test_config_file_errors_str(errors):
|
||||
assert str(errors).splitlines() == [
|
||||
'Errors occurred while reading config.py:',
|
||||
' Error text 1: Exception 1',
|
||||
' Error text 2: Exception 2',
|
||||
' Error text 2 - Exception: Exception 2',
|
||||
]
|
||||
|
||||
|
||||
|
@ -550,7 +550,7 @@ class TestConfigPy:
|
||||
assert len(excinfo.value.errors) == 1
|
||||
error = excinfo.value.errors[0]
|
||||
assert isinstance(error.exception, SyntaxError)
|
||||
assert error.text == "Syntax Error"
|
||||
assert error.text == "Unhandled exception"
|
||||
exception_text = 'invalid syntax (config.py, line 1)'
|
||||
assert str(error.exception) == exception_text
|
||||
|
||||
|
Loading…
Reference in New Issue
Block a user