Fix NUL byte error handling on Python 3.4

Looks like Python 3.4 raises TypeError and not ValueError...
This commit is contained in:
Florian Bruhin 2017-09-15 19:46:38 +02:00
parent d901bee88e
commit a7d5a98cc4
2 changed files with 2 additions and 2 deletions

View File

@ -198,7 +198,7 @@ def read_config_py(filename=None):
try:
code = compile(source, filename, 'exec')
except ValueError as e:
except (ValueError, TypeError) as e:
# source contains NUL bytes
desc = configexc.ConfigErrorDesc("Error while compiling", e)
raise configexc.ConfigFileErrors(basename, [desc])

View File

@ -236,7 +236,7 @@ class TestConfigPy:
assert len(excinfo.value.errors) == 1
error = excinfo.value.errors[0]
assert isinstance(error.exception, ValueError)
assert isinstance(error.exception, (TypeError, ValueError))
assert error.text == "Error while compiling"
exception_text = 'source code string cannot contain null bytes'
assert str(error.exception) == exception_text