summaryrefslogtreecommitdiff
diff options
context:
space:
mode:
-rw-r--r--coverage/execfile.py2
-rw-r--r--test/test_execfile.py11
2 files changed, 12 insertions, 1 deletions
diff --git a/coverage/execfile.py b/coverage/execfile.py
index d6bcdceb..43bdc5c3 100644
--- a/coverage/execfile.py
+++ b/coverage/execfile.py
@@ -24,7 +24,7 @@ def run_python_file(filename, args):
sys.path[0] = os.path.dirname(filename)
try:
- source = open(filename).read()
+ source = open(filename, 'rU').read()
exec compile(source, filename, "exec") in main_mod.__dict__
finally:
# Restore the old __main__
diff --git a/test/test_execfile.py b/test/test_execfile.py
index eae227a1..6cc7cab8 100644
--- a/test/test_execfile.py
+++ b/test/test_execfile.py
@@ -46,3 +46,14 @@ class RunTest(CoverageTest):
self.assertEqual(os.listdir("."), ["xxx"])
run_python_file("xxx", ["xxx"])
self.assertEqual(os.listdir("."), ["xxx"])
+
+ def test_universal_newlines(self):
+ # Make sure we can read any sort of line ending.
+ pylines = """# try newlines|print 'Hello, world!'|""".split('|')
+ for nl in ('\n', '\r\n', '\r'):
+ fpy = open('nl.py', 'wb')
+ fpy.write(nl.join(pylines))
+ fpy.close()
+ run_python_file('nl.py', ['nl.py'])
+ self.assertEqual(self.stdout(), "Hello, world!\n"*3)
+