diff options
author | Ned Batchelder <ned@nedbatchelder.com> | 2010-02-22 20:35:45 -0500 |
---|---|---|
committer | Ned Batchelder <ned@nedbatchelder.com> | 2010-02-22 20:35:45 -0500 |
commit | b007d17e5e2da220c57920b84c7f337bc8b378d0 (patch) | |
tree | 2aeb27234b8ba1c2ae7e25c2f73c370816e29b41 /coverage/execfile.py | |
parent | bf001ce15db6a5847fa41919474d9d007d2d49d3 (diff) | |
download | python-coveragepy-b007d17e5e2da220c57920b84c7f337bc8b378d0.tar.gz |
Python source files that don't end with a newline can now be executed, fixing #47.
Diffstat (limited to 'coverage/execfile.py')
-rw-r--r-- | coverage/execfile.py | 10 |
1 files changed, 8 insertions, 2 deletions
diff --git a/coverage/execfile.py b/coverage/execfile.py index f04840b..1a2ffad 100644 --- a/coverage/execfile.py +++ b/coverage/execfile.py @@ -2,7 +2,7 @@ import imp, os, sys -from coverage.backward import exec_function +from coverage.backward import exec_code_object from coverage.misc import NoSource, ExceptionDuringRun @@ -42,9 +42,15 @@ def run_python_file(filename, args): except IOError: 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. + if source[-1] != '\n': + source += '\n' + code = compile(source, filename, "exec") + # Execute the source file. try: - exec_function(source, filename, main_mod.__dict__) + exec_code_object(code, main_mod.__dict__) except: # Something went wrong while executing the user code. # Get the exc_info, and pack them into an exception that we can |