an added dot rather than simply appended, so that .coveragerc files will not
be confused for data files.
+- Python source files that don't end with a newline can now be executed, fixing
- Added an AUTHORS.txt file.
.. _issue 39: http://bitbucket.org/ned/coveragepy/issue/39
.. _issue 40: http://bitbucket.org/ned/coveragepy/issue/40
+.. _issue 47: http://bitbucket.org/ned/coveragepy/issue/47
Version 3.2, 5 December 2009
# Exec is a statement in Py2, a function in Py3
if sys.version_info >= (3, 0):
- def exec_
function(source, filename, global_map):
+ def exec_e, global_map):
"""A wrapper around exec()."""
mpile(source, filename, "exec"), global_map)
# OK, this is pretty gross. In Py2, exec was a statement, but that will
# be a syntax error if we try to put it in a Py3 file, even if it is never
# executed. So hide it inside an evaluated string literal instead.
-def exec_function(source, filename, global_map):
- exec compile(source, filename, "exec") in global_map
- "<exec_function>", "exec"
+ "def exec_code_object(code, global_map):\n"
+ " exec code in global_map\n",
+ "<exec_function>", "exec"
# ConfigParser was renamed to the more-standard configparser
-from coverage.backward import exec_
+from coverage.backward import exec_
from coverage.misc import NoSource, ExceptionDuringRun
raise NoSource("No file to run: %r" % filename)
+ # We have the source. `compile` still needs the last line to be clean,
+ # so make sure it is, then compile a code object from it.
+ code = compile(source, filename, "exec")
# Execute the source file.
function(source, filename, main_mod.__dict__)
+ exec_e, main_mod.__dict__)
# Something went wrong while executing the user code.
# Get the exc_info, and pack them into an exception that we can
self.assertEqual(self.stdout(), "Hello, world!\n"*3)
+ def test_missing_final_newline(self):
+ # Make sure we can deal with a Python file with no final newline.
+ self.make_file("abrupt.py", """\
+ abrupt = open("abrupt.py").read()
+ self.assertEqual(abrupt[-1], '#')
+ run_python_file("abrupt.py", ["abrupt.py"])
+ self.assertEqual(self.stdout(), "a is 1\n")
self.assertRaises(NoSource, run_python_file, "xyzzy.py", )