Raise config.py errors happening in tests
This commit is contained in:
parent
ebf378a945
commit
9b22480b07
@ -214,8 +214,13 @@ class ConfigAPI:
|
|||||||
self._keyconfig.unbind(key, mode=mode)
|
self._keyconfig.unbind(key, mode=mode)
|
||||||
|
|
||||||
|
|
||||||
def read_config_py(filename=None):
|
def read_config_py(filename=None, raising=False):
|
||||||
"""Read a config.py file."""
|
"""Read a config.py file.
|
||||||
|
|
||||||
|
Arguments;
|
||||||
|
raising: Raise exceptions happening in config.py.
|
||||||
|
This is needed during tests to use pytest's inspection.
|
||||||
|
"""
|
||||||
api = ConfigAPI(config.instance, config.key_instance)
|
api = ConfigAPI(config.instance, config.key_instance)
|
||||||
|
|
||||||
if filename is None:
|
if filename is None:
|
||||||
@ -261,6 +266,8 @@ def read_config_py(filename=None):
|
|||||||
|
|
||||||
exec(code, module.__dict__)
|
exec(code, module.__dict__)
|
||||||
except Exception as e:
|
except Exception as e:
|
||||||
|
if raising:
|
||||||
|
raise
|
||||||
api.errors.append(configexc.ConfigErrorDesc(
|
api.errors.append(configexc.ConfigErrorDesc(
|
||||||
"Unhandled exception",
|
"Unhandled exception",
|
||||||
exception=e, traceback=traceback.format_exc()))
|
exception=e, traceback=traceback.format_exc()))
|
||||||
|
@ -222,7 +222,7 @@ class ConfPy:
|
|||||||
|
|
||||||
def read(self, error=False):
|
def read(self, error=False):
|
||||||
"""Read the config.py via configfiles and check for errors."""
|
"""Read the config.py via configfiles and check for errors."""
|
||||||
api = configfiles.read_config_py(self.filename)
|
api = configfiles.read_config_py(self.filename, raising=not error)
|
||||||
assert len(api.errors) == (1 if error else 0)
|
assert len(api.errors) == (1 if error else 0)
|
||||||
return api
|
return api
|
||||||
|
|
||||||
@ -309,9 +309,8 @@ class TestConfigPy:
|
|||||||
def test_assertions(self, confpy):
|
def test_assertions(self, confpy):
|
||||||
"""Make sure assertions in config.py work for these tests."""
|
"""Make sure assertions in config.py work for these tests."""
|
||||||
confpy.write('assert False')
|
confpy.write('assert False')
|
||||||
api = confpy.read(error=True)
|
with pytest.raises(AssertionError):
|
||||||
error = api.errors[0]
|
confpy.read() # no errors=True so it gets raised
|
||||||
assert isinstance(error.exception, AssertionError)
|
|
||||||
|
|
||||||
@pytest.mark.parametrize('line', [
|
@pytest.mark.parametrize('line', [
|
||||||
'c.colors.hints.bg = "red"',
|
'c.colors.hints.bg = "red"',
|
||||||
|
Loading…
Reference in New Issue
Block a user