[Piglit] [PATCH 08/44] python: use six.moves.cStringIO

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


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

This is the fast C based version on python 2, and is adapative on
python3, importing the C based version if it's available and falling
back if necessary.

Signed-off-by: Dylan Baker <dylanx.c.baker at intel.com>
---
 framework/backends/compression.py  | 10 ++++------
 unittests/oglconform_tests.py      |  6 +++---
 unittests/summary_console_tests.py |  2 +-
 3 files changed, 8 insertions(+), 10 deletions(-)

diff --git a/framework/backends/compression.py b/framework/backends/compression.py
index 7ca6c0c..ab85a17 100644
--- a/framework/backends/compression.py
+++ b/framework/backends/compression.py
@@ -44,6 +44,9 @@ import functools
 import gzip
 import os
 import subprocess
+import contextlib
+
+from six.moves import cStringIO as StringIO
 
 from framework import exceptions
 from framework.core import PIGLIT_CONFIG
@@ -99,11 +102,6 @@ except ImportError:
     except OSError:
         pass
     else:
-        import contextlib
-        try:
-            import cStringIO as StringIO
-        except ImportError:
-            import StringIO
 
         @contextlib.contextmanager
         def _compress_xz(filename):
@@ -162,7 +160,7 @@ except ImportError:
 
             # We need a file-like object, so the contents must be placed in
             # a StringIO object.
-            io = StringIO.StringIO()
+            io = StringIO()
             io.write(string)
             io.seek(0)
 
diff --git a/unittests/oglconform_tests.py b/unittests/oglconform_tests.py
index 5ccb999..4b94a16 100644
--- a/unittests/oglconform_tests.py
+++ b/unittests/oglconform_tests.py
@@ -21,10 +21,10 @@
 """Tests for the oglconform integration."""
 
 from __future__ import absolute_import, division, print_function
-from StringIO import StringIO
 
 import mock
 import nose.tools as nt
+from six.moves import cStringIO as StringIO
 
 from . import utils
 from framework import grouptools
@@ -40,7 +40,7 @@ with mock.patch('framework.core.PIGLIT_CONFIG.required_get',
 @mock.patch.object(oglconform.tempfile, 'NamedTemporaryFile')
 def test_make_profile(mock_temp):
     """tests.oglconform._make_profile: Adds test names"""
-    io_ = StringIO('group test.name\n')
+    io_ = mock.Mock(wraps=StringIO(u'group test.name\n'))
     io_.name = mock.Mock()
     mock_file = mock.MagicMock()
     mock_file.__enter__.return_value = io_
@@ -58,7 +58,7 @@ def test_make_profile(mock_temp):
 @mock.patch.object(oglconform.tempfile, 'NamedTemporaryFile')
 def test_make_profile_missing(mock_temp):
     """tests.oglconform._make_profile: handles missing groups"""
-    io_ = StringIO('test.name\n')
+    io_ = mock.Mock(wraps=StringIO(u'test.name\n'))
     io_.name = mock.Mock()
     mock_file = mock.MagicMock()
     mock_file.__enter__.return_value = io_
diff --git a/unittests/summary_console_tests.py b/unittests/summary_console_tests.py
index 53ecdf1..507a551 100644
--- a/unittests/summary_console_tests.py
+++ b/unittests/summary_console_tests.py
@@ -29,9 +29,9 @@ generator.
 
 from __future__ import absolute_import, division, print_function
 import sys
-from cStringIO import StringIO
 
 import nose.tools as nt
+from six.moves import cStringIO as StringIO
 
 from . import utils
 from framework import results, grouptools
-- 
2.7.0



More information about the Piglit mailing list