Mesa (master): python: Disable universal newlines

GitLab Mirror gitlab-mirror at kemper.freedesktop.org
Wed Aug 22 15:42:34 UTC 2018


Module: Mesa
Branch: master
Commit: ff0ce31e2a9135c3fcc3243773c442bc48f46b53
URL:    http://cgit.freedesktop.org/mesa/mesa/commit/?id=ff0ce31e2a9135c3fcc3243773c442bc48f46b53

Author: Mathieu Bridon <bochecha at daitauha.fr>
Date:   Fri Aug 17 21:32:17 2018 +0200

python: Disable universal newlines

We are testing the behaviour of a tool, for different input files, each
one using a different newline sequence. ('\n' on UNIX, '\r\n' on
Windows, …)

Unfortunately, when opening a file in text mode, Python 3 will by
default enable the "universal newlines" mode, which means it replaces
all the known newline sequences by '\n'.

This (usually useful) behaviour breaks the tests, which are specifically
trying to handle files with newline sequences different from '\n'.

Disabling the universal newlines mode fixes the tests.

However, to keep the script compatible with both Python 2 and 3, we must
use the io.open() function instead of the open() builtin, as the latter
only knows about the `newline` argument on Python 3.

Reviewed-by: Dylan Baker <dylan at pnwbakers.com>

---

 src/compiler/glsl/glcpp/tests/glcpp_test.py | 5 ++++-
 1 file changed, 4 insertions(+), 1 deletion(-)

diff --git a/src/compiler/glsl/glcpp/tests/glcpp_test.py b/src/compiler/glsl/glcpp/tests/glcpp_test.py
index e27391093c..1481eed618 100755
--- a/src/compiler/glsl/glcpp/tests/glcpp_test.py
+++ b/src/compiler/glsl/glcpp/tests/glcpp_test.py
@@ -46,7 +46,10 @@ def arg_parser():
 
 def parse_test_file(filename, nl_format):
     """Check for any special arguments and return them as a list."""
-    with open(filename) as f:
+    # Disable "universal newlines" mode; we can't directly use `nl_format` as
+    # the `newline` argument, because the "bizarro" test uses something Python
+    # considers invalid.
+    with io.open(filename, newline='') as f:
         for l in f.read().split(nl_format):
             if 'glcpp-args:' in l:
                 return l.split('glcpp-args:')[1].strip().split()




More information about the mesa-commit mailing list