summaryrefslogtreecommitdiff
path: root/framework
diff options
context:
space:
mode:
authorJussi Kukkonen <jussi.kukkonen@intel.com>2016-07-06 13:25:28 +0300
committerDylan Baker <dylan@pnwbakers.com>2016-07-06 10:27:50 -0700
commit98f68579e13d8f1110885714659fc48cc4832704 (patch)
tree3ecfb14e30035ed26eca64f1edef915cd651b384 /framework
parent85143c1bc53b8e64256265b6b4510cd3c89467cf (diff)
framework: Read test files as utf-8
Make sure test files are always considered utf-8 to avoid a UnicodeDecodeError when e.g. locale is unset. This requires using io.open() as python2 open() does not support "encoding". The upside of this is that same code paths should now work for both python2 and python3. v2: Fix unittests that now need to mock io.open instead of __builtins__.open (Dylan) Signed-off-by: Jussi Kukkonen <jussi.kukkonen@intel.com> Signed-off-by: Dylan Baker <dylanx.c.baker@intel.com> Reviewed-by: Dylan Baker <dylan@pnwbakers.com>
Diffstat (limited to 'framework')
-rw-r--r--framework/test/glsl_parser_test.py11
-rw-r--r--framework/test/shader_test.py11
2 files changed, 6 insertions, 16 deletions
diff --git a/framework/test/glsl_parser_test.py b/framework/test/glsl_parser_test.py
index cd1693c47..df08672f6 100644
--- a/framework/test/glsl_parser_test.py
+++ b/framework/test/glsl_parser_test.py
@@ -26,7 +26,7 @@ from __future__ import (
)
import os
import re
-
+import io
import six
from framework import exceptions
@@ -98,13 +98,8 @@ class GLSLParserTest(FastSkipMixin, PiglitBaseTest):
# Parse the config file and get the config section, then write this
# section to a StringIO and pass that to ConfigParser
try:
- with open(filepath, 'r') as testfile:
- # Python 2 returns a bytes instance, but python 3 returns str
- # (unicode) instance.
- if six.PY2:
- testfile = testfile.read().decode('utf-8')
- elif six.PY3:
- testfile = testfile.read()
+ with io.open(filepath, mode='r', encoding='utf-8') as testfile:
+ testfile = testfile.read()
config = self.__parser(testfile, filepath)
command = self.__get_command(config, filepath)
except GLSLParserInternalError as e:
diff --git a/framework/test/shader_test.py b/framework/test/shader_test.py
index 4fb33a081..f3c945c06 100644
--- a/framework/test/shader_test.py
+++ b/framework/test/shader_test.py
@@ -27,8 +27,7 @@ from __future__ import (
absolute_import, division, print_function, unicode_literals
)
import re
-
-import six
+import io
from framework import exceptions
from .opengl import FastSkipMixin
@@ -60,14 +59,10 @@ class ShaderTest(FastSkipMixin, PiglitBaseTest):
# cost. The first one looks for the start of the config block or raises
# an exception. The second looks for the GL version or raises an
# exception
- with open(filename, 'r') as shader_file:
+ with io.open(filename, mode='r', encoding='utf-8') as shader_file:
# The mock in python 3.3 doesn't support readlines(), so use
# read().split() as a workaround
- if six.PY3:
- lines = (l for l in shader_file.read().split('\n'))
- elif six.PY2:
- lines = (l.decode('utf-8') for l in
- shader_file.read().split(b'\n'))
+ lines = (l for l in shader_file.read().split('\n'))
# Find the config section
for line in lines: