summaryrefslogtreecommitdiffstats
path: root/BaseTools/Tests/TestTools.py
diff options
context:
space:
mode:
Diffstat (limited to 'BaseTools/Tests/TestTools.py')
-rw-r--r--BaseTools/Tests/TestTools.py14
1 files changed, 8 insertions, 6 deletions
diff --git a/BaseTools/Tests/TestTools.py b/BaseTools/Tests/TestTools.py
index e16e993048..65948a7ae2 100644
--- a/BaseTools/Tests/TestTools.py
+++ b/BaseTools/Tests/TestTools.py
@@ -40,7 +40,7 @@ if PythonSourceDir not in sys.path:
def MakeTheTestSuite(localItems):
tests = []
- for name, item in localItems.iteritems():
+ for name, item in localItems.items():
if isinstance(item, type):
if issubclass(item, unittest.TestCase):
tests.append(unittest.TestLoader().loadTestsFromTestCase(item))
@@ -146,9 +146,12 @@ class BaseToolsTest(unittest.TestCase):
return data
def WriteTmpFile(self, fileName, data):
- f = open(self.GetTmpFilePath(fileName), 'w')
- f.write(data)
- f.close()
+ if isinstance(data, bytes):
+ with open(self.GetTmpFilePath(fileName), 'wb') as f:
+ f.write(data)
+ else:
+ with open(self.GetTmpFilePath(fileName), 'w') as f:
+ f.write(data)
def GenRandomFileData(self, fileName, minlen = None, maxlen = None):
if maxlen is None: maxlen = minlen
@@ -161,7 +164,7 @@ class BaseToolsTest(unittest.TestCase):
if maxlen is None: maxlen = minlen
return ''.join(
[chr(random.randint(0, 255))
- for x in xrange(random.randint(minlen, maxlen))
+ for x in range(random.randint(minlen, maxlen))
])
def setUp(self):
@@ -183,4 +186,3 @@ class BaseToolsTest(unittest.TestCase):
os.environ['PATH'] = self.savedEnvPath
sys.path = self.savedSysPath
-