[Piglit] [PATCH 04/20] framework: Update import statements to support Python 3.x in addition to 2.x.
Jon Severinsson
jon at severinsson.net
Fri Apr 12 16:39:46 PDT 2013
---
framework/core.py | 11 ++++++++---
framework/exectest.py | 2 ++
framework/gleantest.py | 2 ++
framework/glsl_parser_test.py | 20 +++++++++++++-------
framework/log.py | 6 +++++-
framework/shader_test.py | 2 +-
framework/summary.py | 4 ++++
framework/threadpool.py | 29 +++++++++++++++--------------
framework/threads.py | 11 ++++++++---
piglit-merge-results.py | 2 +-
piglit-print-commands.py | 2 +-
piglit-run.py | 2 +-
piglit-summary-html.py | 2 +-
piglit-summary-junit.py | 2 +-
14 filer ändrade, 63 tillägg(+), 34 borttagningar(-)
diff --git a/framework/core.py b/framework/core.py
index 497bb36..4fc9a2f 100644
--- a/framework/core.py
+++ b/framework/core.py
@@ -33,12 +33,17 @@ import string
import sys
import time
import traceback
-from log import log
-from cStringIO import StringIO
+import threading
from textwrap import dedent
+try:
+ from cStringIO import StringIO
+except ImportError:
+ from io import StringIO
+
+sys.path.append(os.path.dirname(__file__))
+from log import log
from threads import ConcurrentTestPool
from threads import synchronized_self
-import threading
__all__ = [
'Environment',
diff --git a/framework/exectest.py b/framework/exectest.py
index a8ed861..1f97f12 100644
--- a/framework/exectest.py
+++ b/framework/exectest.py
@@ -23,8 +23,10 @@
import os
import subprocess
import shlex
+import sys
import types
+sys.path.append(os.path.dirname(__file__))
from core import Test, testBinDir, TestResult
#############################################################################
diff --git a/framework/gleantest.py b/framework/gleantest.py
index 1143ebf..9fcee9b 100644
--- a/framework/gleantest.py
+++ b/framework/gleantest.py
@@ -22,7 +22,9 @@
import os
import subprocess
+import sys
+sys.path.append(os.path.dirname(__file__))
from core import checkDir, testBinDir, Test, TestResult
from exectest import ExecTest
diff --git a/framework/glsl_parser_test.py b/framework/glsl_parser_test.py
index 66e6dd3..920b394 100755
--- a/framework/glsl_parser_test.py
+++ b/framework/glsl_parser_test.py
@@ -31,16 +31,22 @@ standalone tests on the command line. To add a test to a Piglit group, us
usage_message = "usage: glsl_parser_test.py TEST_FILE"
-import ConfigParser
import os
import os.path as path
import re
import subprocess
import sys
-
-from ConfigParser import SafeConfigParser
+try:
+ import configparser
+except ImportError:
+ import ConfigParser as configparser
+try:
+ from cStringIO import StringIO
+except ImportError:
+ from io import StringIO
+
+sys.path.append(os.path.dirname(__file__))
from core import Test, testBinDir, TestResult
-from cStringIO import StringIO
from exectest import PlainExecTest
def add_glsl_parser_test(group, filepath, test_name):
@@ -108,7 +114,7 @@ class GLSLParserTest(PlainExecTest):
comments. This section can appear anywhere in the file: above,
within, or below the actual GLSL source code. The syntax of the config
section is essentially the syntax of
- ``ConfigParser.SafeConfigParser``.
+ ``configparser.SafeConfigParser``.
The beginning of the config section is marked by a comment line that
contains only '[config]'. The end of the config section is marked by
@@ -293,12 +299,12 @@ class GLSLParserTest(PlainExecTest):
else:
assert(False)
- config = ConfigParser.SafeConfigParser(cls.__config_defaults)
+ config = configparser.SafeConfigParser(cls.__config_defaults)
try:
text = text_io.getvalue()
text_io.close()
config.readfp(StringIO(text))
- except ConfigParser.Error as e:
+ except configparser.Error as e:
self.result = TestResult()
self.result['result'] = 'fail'
self.result['errors'] = ['Errors exist in config section of test file']
diff --git a/framework/log.py b/framework/log.py
index e90137a..443dd71 100644
--- a/framework/log.py
+++ b/framework/log.py
@@ -21,9 +21,13 @@
# IN THE SOFTWARE.
#
+import os
+import logging
+import sys
+
+sys.path.append(os.path.dirname(__file__))
from threads import synchronized_self
from patterns import Singleton
-import logging
class Logger(Singleton):
@synchronized_self
diff --git a/framework/shader_test.py b/framework/shader_test.py
index 48a9085..37ed0f2 100755
--- a/framework/shader_test.py
+++ b/framework/shader_test.py
@@ -25,12 +25,12 @@
import json
import os
-import os.path
import os.path as path
import re
import sys
import textwrap
+sys.path.append(os.path.dirname(__file__))
from core import testBinDir, Group, Test, TestResult
from exectest import PlainExecTest
diff --git a/framework/summary.py b/framework/summary.py
index a72bb4b..c7f436f 100644
--- a/framework/summary.py
+++ b/framework/summary.py
@@ -20,6 +20,10 @@
# OR IN CONNECTION WITH THE SOFTWARE OR THE USE OR OTHER
# DEALINGS IN THE SOFTWARE.
+import os
+import sys
+
+sys.path.append(os.path.dirname(__file__))
import core
diff --git a/framework/threadpool.py b/framework/threadpool.py
index 1b4c12c..41b7105 100644
--- a/framework/threadpool.py
+++ b/framework/threadpool.py
@@ -31,6 +31,15 @@ See the end of the module code for a brief, annotated usage example.
Website : http://chrisarndt.de/projects/threadpool/
"""
+
+import sys
+import threading
+import traceback
+try:
+ import queue
+except ImportError:
+ import Queue as queue
+
__docformat__ = "restructuredtext en"
__all__ = [
@@ -48,14 +57,6 @@ __revision__ = "$Revision: 416 $"
__date__ = "$Date: 2009-10-07 05:41:27 +0200 (Wed, 07 Oct 2009) $"
__license__ = "MIT license"
-
-# standard library modules
-import sys
-import threading
-import Queue
-import traceback
-
-
# exceptions
class NoResultsPending(Exception):
"""All work requests have been processed."""
@@ -122,7 +123,7 @@ class WorkerThread(threading.Thread):
"""Set up thread in daemonic mode and start it immediatedly.
``requests_queue`` and ``results_queue`` are instances of
- ``Queue.Queue`` passed by the ``ThreadPool`` class when it creates a new
+ ``queue.Queue`` passed by the ``ThreadPool`` class when it creates a new
worker thread.
"""
@@ -145,7 +146,7 @@ class WorkerThread(threading.Thread):
# the while loop again, to give the thread a chance to exit.
try:
request = self._requests_queue.get(True, self._poll_timeout)
- except Queue.Empty:
+ except queue.Empty:
continue
else:
if self._dismissed.isSet():
@@ -244,11 +245,11 @@ class ThreadPool:
the possibilty of a deadlock, when the results queue is not pulled
regularly and too many jobs are put in the work requests queue.
To prevent this, always set ``timeout > 0`` when calling
- ``ThreadPool.putRequest()`` and catch ``Queue.Full`` exceptions.
+ ``ThreadPool.putRequest()`` and catch ``queue.Full`` exceptions.
"""
- self._requests_queue = Queue.Queue(q_size)
- self._results_queue = Queue.Queue(resq_size)
+ self._requests_queue = queue.Queue(q_size)
+ self._results_queue = queue.Queue(resq_size)
self.workers = []
self.dismissedWorkers = []
self.workRequests = {}
@@ -315,7 +316,7 @@ class ThreadPool:
(request.exception and request.exc_callback):
request.callback(request, result)
del self.workRequests[request.requestID]
- except Queue.Empty:
+ except queue.Empty:
break
def wait(self):
diff --git a/framework/threads.py b/framework/threads.py
index 724e84e..71ba502 100644
--- a/framework/threads.py
+++ b/framework/threads.py
@@ -21,11 +21,16 @@
# IN THE SOFTWARE.
#
-from threadpool import ThreadPool, WorkRequest
-from patterns import Singleton
+import multiprocessing
+import os
+import sys
+
from threading import RLock
from weakref import WeakKeyDictionary
-import multiprocessing
+
+sys.path.append(os.path.dirname(__file__))
+from threadpool import ThreadPool, WorkRequest
+from patterns import Singleton
def synchronized_self(function):
'''
diff --git a/piglit-merge-results.py b/piglit-merge-results.py
index 26d5881..fea2307 100755
--- a/piglit-merge-results.py
+++ b/piglit-merge-results.py
@@ -25,7 +25,7 @@
from getopt import getopt, GetoptError
import sys, os.path
-sys.path.append(os.path.dirname(os.path.realpath(sys.argv[0])))
+sys.path.append(os.path.dirname(__file__))
import framework.core as core
diff --git a/piglit-print-commands.py b/piglit-print-commands.py
index 228ac84..c1eddbb 100755
--- a/piglit-print-commands.py
+++ b/piglit-print-commands.py
@@ -29,7 +29,7 @@ import time
import traceback
import json
-sys.path.append(path.dirname(path.realpath(sys.argv[0])))
+sys.path.append(os.path.dirname(__file__))
import framework.core as core
from framework.exectest import ExecTest
from framework.gleantest import GleanTest
diff --git a/piglit-run.py b/piglit-run.py
index 6d6ec77..0a8ebc5 100755
--- a/piglit-run.py
+++ b/piglit-run.py
@@ -29,7 +29,7 @@ import time
import traceback
import json
-sys.path.append(path.dirname(path.realpath(sys.argv[0])))
+sys.path.append(os.path.dirname(__file__))
import framework.core as core
from framework.threads import synchronized_self
diff --git a/piglit-summary-html.py b/piglit-summary-html.py
index 087b503..299d4f9 100755
--- a/piglit-summary-html.py
+++ b/piglit-summary-html.py
@@ -26,7 +26,7 @@ import cgi
import os, os.path
import sys
-sys.path.append(os.path.dirname(os.path.realpath(sys.argv[0])))
+sys.path.append(os.path.dirname(__file__))
import framework.core as core
import framework.summary
diff --git a/piglit-summary-junit.py b/piglit-summary-junit.py
index 6520888..d071f09 100755
--- a/piglit-summary-junit.py
+++ b/piglit-summary-junit.py
@@ -28,7 +28,7 @@ import optparse
import os
import sys
-sys.path.append(os.path.dirname(os.path.realpath(sys.argv[0])))
+sys.path.append(os.path.dirname(__file__))
import framework.core
import framework.summary
from framework import junit
--
1.7.10.4
More information about the Piglit
mailing list