diff options
author | Ned Batchelder <ned@nedbatchelder.com> | 2016-12-17 16:14:58 -0500 |
---|---|---|
committer | Ned Batchelder <ned@nedbatchelder.com> | 2016-12-17 16:14:58 -0500 |
commit | 3f320139291a93beccea0089c5a843c1e38bd356 (patch) | |
tree | f096c09fcd54ccf8e475cb967b08a2b3d23d2465 /tests/test_execfile.py | |
parent | 51ee731f82f2e562741d91e930bb59358bc64805 (diff) | |
download | python-coveragepy-git-3f320139291a93beccea0089c5a843c1e38bd356.tar.gz |
Provide a more useful error message if failing to run a non-Python file. #514
Diffstat (limited to 'tests/test_execfile.py')
-rw-r--r-- | tests/test_execfile.py | 19 |
1 files changed, 19 insertions, 0 deletions
diff --git a/tests/test_execfile.py b/tests/test_execfile.py index 889d6cfd..8585b16d 100644 --- a/tests/test_execfile.py +++ b/tests/test_execfile.py @@ -145,6 +145,25 @@ class RunPycFileTest(CoverageTest): with self.assertRaisesRegex(NoCode, "No file to run: 'xyzzy.pyc'"): run_python_file("xyzzy.pyc", []) + def test_running_py_from_binary(self): + # Use make_file to get the bookkeeping. Ideally, it would + # be able to write binary files. + bf = self.make_file("binary") + with open(bf, "wb") as f: + f.write(b'\x7fELF\x02\x01\x01\x00\x00\x00') + + msg = ( + r"Couldn't run 'binary' as Python code: " + r"(TypeError|ValueError): " + r"(" + r"compile\(\) expected string without null bytes" # for py2 + r"|" + r"source code string cannot contain null bytes" # for py3 + r")" + ) + with self.assertRaisesRegex(Exception, msg): + run_python_file(bf, [bf]) + class RunModuleTest(CoverageTest): """Test run_python_module.""" |