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

Jon Severinsson jon at severinsson.net
Fri Apr 12 16:39:56 PDT 2013


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

diff --git a/framework/glsl_parser_test.py b/framework/glsl_parser_test.py
index 920b394..b5b1cad 100755
--- a/framework/glsl_parser_test.py
+++ b/framework/glsl_parser_test.py
@@ -49,6 +49,11 @@ sys.path.append(os.path.dirname(__file__))
 from core import Test, testBinDir, TestResult
 from exectest import PlainExecTest
 
+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 b273f88..9f04c9c 100755
--- a/piglit-summary-html.py
+++ b/piglit-summary-html.py
@@ -32,6 +32,10 @@ sys.path.append(os.path.dirname(__file__))
 import framework.core as core
 import framework.summary
 
+try:
+	string_type = basestring
+except NameError:
+	string_type = str
 
 #############################################################################
 ##### Auxiliary functions
@@ -92,7 +96,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 +105,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