[Piglit] [PATCH 25/44] unittest/utils.py: fix tempfile modes for python3

baker.dylan.c at gmail.com baker.dylan.c at gmail.com
Wed Jan 27 16:06:33 PST 2016


From: Dylan Baker <baker.dylan.c at gmail.com>

By default in python 3 write modes for tempfile are bytes, but piglit
uses unicode. This fixes that.

Signed-off-by: Dylan Baker <dylanx.c.baker at intel.com>
---
 unittests/utils.py | 7 +++++--
 1 file changed, 5 insertions(+), 2 deletions(-)

diff --git a/unittests/utils.py b/unittests/utils.py
index f3834ef..8e05fdc 100644
--- a/unittests/utils.py
+++ b/unittests/utils.py
@@ -58,6 +58,9 @@ __all__ = [
 
 core.get_config()
 
+_WRITE_MODE = 'w'
+_READ_MODE = 'r'
+
 
 class _Tree(dict):
     """Private helper to make JSON_DATA easier to work with."""
@@ -246,7 +249,7 @@ def resultfile():
     data['tests']['sometest'] = results.TestResult('pass')
     data['tests']['sometest'].time = 1.2
     data = results.TestrunResult.from_dict(data)
-    with tempfile_.NamedTemporaryFile(delete=False) as f:
+    with tempfile_.NamedTemporaryFile(mode=_WRITE_MODE, delete=False) as f:
         json.dump(data, f, default=backends.json.piglit_encoder)
 
     yield f
@@ -268,7 +271,7 @@ def tempfile(contents):
 
     """
     # Do not delete the tempfile as soon as it is closed
-    temp = tempfile_.NamedTemporaryFile(delete=False)
+    temp = tempfile_.NamedTemporaryFile(mode=_WRITE_MODE, delete=False)
     temp.write(contents)
     temp.close()
 
-- 
2.7.0



More information about the Piglit mailing list