[Piglit] [PATCH 13/20] framework: Update string type checking to work on both Python 2.x and Python 3.x

Jon Severinsson jon at severinsson.net
Wed Apr 17 09:14:52 PDT 2013


---
 framework/glsl_parser_test.py |    7 ++++++-
 piglit-summary-html.py        |    9 +++++++--
 2 filer ändrade, 13 tillägg(+), 3 borttagningar(-)

diff --git a/framework/glsl_parser_test.py b/framework/glsl_parser_test.py
index 6f7d4df..1c7863a 100755
--- a/framework/glsl_parser_test.py
+++ b/framework/glsl_parser_test.py
@@ -49,6 +49,11 @@ try:
 except ImportError:
     from io import StringIO # The Python 3.x import
 
+try:
+	string_type = basestring
+except NameError:
+	string_type = str
+
 def add_glsl_parser_test(group, filepath, test_name):
 	"""Add an instance of GLSLParserTest to the given group."""
 	group[test_name] = GLSLParserTest(filepath)
@@ -82,7 +87,7 @@ def import_glsl_parser_tests(group, basepath, subdirectories):
 						filepath, basepath)
 					if os.path.sep != '/':
 						testname = testname.replace(os.path.sep, '/', -1)
-					assert isinstance(testname, basestring)
+					assert isinstance(testname, string_type)
 					add_glsl_parser_test(
 						group,
 						filepath,
diff --git a/piglit-summary-html.py b/piglit-summary-html.py
index 5ca8eb4..2fd6cb9 100755
--- a/piglit-summary-html.py
+++ b/piglit-summary-html.py
@@ -32,6 +32,11 @@ sys.path.append(os.path.dirname(os.path.realpath(sys.argv[0])))
 import framework.core as core
 import framework.summary
 
+try:
+	string_type = basestring
+except NameError:
+	string_type = str
+
 
 #############################################################################
 ##### Auxiliary functions
@@ -92,7 +97,7 @@ def buildDetailValue(detail):
 		items = map(buildResultListItem, detail)
 		return ResultList % { 'items': "".join(items) }
 
-	elif isinstance(detail, basestring):
+	elif isinstance(detail, string_type):
 		return ResultMString % { 'detail': cgi.escape(detail) }
 
 	return cgi.escape(str(detail))
@@ -101,7 +106,7 @@ def buildDetailValue(detail):
 def buildDetails(testResult):
 	details = []
 	for name in testResult:
-		assert(isinstance(name, basestring))
+		assert(isinstance(name, string_type))
 
 		if name == 'result':
 			continue
-- 
1.7.10.4



More information about the Piglit mailing list