1. Ned Batchelder
  2. coverage.py

Commits

Ned Batchelder  committed bd90702

When executing files, open them in Universal Newline mode, just as Python itself does. Makes it possible to run Python from Windows on Mac, for example.

  • Participants
  • Parent commits 6560fe2
  • Branches default

Comments (0)

Files changed (2)

File coverage/execfile.py

View file
     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__

File test/test_execfile.py

View file
         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)
+