Avoid opening files with deprecated 'U' mode (#269)
Opening files with 'U' mode is deprecated. When running tests with
Python warnings enabled, the warnings of the following form are emitted:
DeprecationWarning: 'U' mode is deprecated
return open(name, 'rU')
To open files with universal newlines on both Ptyhon 2 & 3, use the io
module. It defaults to opening with universal newlines and doesn't emit
a warning.
https://docs.python.org/3/library/io.html
> When reading input from the stream, if newline is None, universal
> newlines mode is enabled.
diff --git a/tests/test_c_parser.py b/tests/test_c_parser.py
index fd85c0d..7dad124 100755
--- a/tests/test_c_parser.py
+++ b/tests/test_c_parser.py
@@ -3,6 +3,7 @@
import pprint
import re
import os, sys
+import io
import unittest
sys.path[0:0] = ['.', '..']
@@ -1772,7 +1773,7 @@
testdir = os.path.dirname(__file__)
name = os.path.join(testdir, 'c_files', name)
assert os.path.exists(name)
- return open(name, 'rU')
+ return io.open(name)
def test_whole_file(self):
# See how pycparser handles a whole, real C file.