]> git.proxmox.com Git - mirror_edk2.git/commitdiff
BaseTools: update Test scripts support python3
authorYunhua Feng <yunhuax.feng@intel.com>
Fri, 12 Oct 2018 01:19:03 +0000 (09:19 +0800)
committerYonghong Zhu <yonghong.zhu@intel.com>
Sat, 13 Oct 2018 01:57:19 +0000 (09:57 +0800)
update Test scripts support python3

Cc: Liming Gao <liming.gao@intel.com>
Cc: Yonghong Zhu <yonghong.zhu@intel.com>
Contributed-under: TianoCore Contribution Agreement 1.1
Signed-off-by: Yunhua Feng <yunhuax.feng@intel.com>
Reviewed-by: Liming Gao <liming.gao@intel.com>
BaseTools/Tests/CheckUnicodeSourceFiles.py
BaseTools/Tests/GNUmakefile
BaseTools/Tests/TestTools.py

index 6ae62f180a840090141d4fdf23aafe0e3a7e99c8..c76b2bc20eb8a78dcd47f8fffd4f73ae76aeb888 100644 (file)
@@ -110,7 +110,7 @@ class Tests(TestTools.BaseToolsTest):
         # This test makes sure that BaseTools rejects these characters\r
         # if seen in a .uni file.\r
         #\r
-        data = codecs.BOM_UTF16_LE + '//\x01\xd8 '\r
+        data = codecs.BOM_UTF16_LE + b'//\x01\xd8 '\r
 \r
         self.CheckFile(encoding=None, shouldPass=False, string=data)\r
 \r
@@ -161,7 +161,7 @@ class Tests(TestTools.BaseToolsTest):
         # This test makes sure that BaseTools rejects these characters\r
         # if seen in a .uni file.\r
         #\r
-        data = '\xed\xa0\x81'\r
+        data = b'\xed\xa0\x81'\r
 \r
         self.CheckFile(encoding=None, shouldPass=False, string=data)\r
 \r
@@ -170,7 +170,7 @@ class Tests(TestTools.BaseToolsTest):
         # Same test as testSurrogatePairUnicodeCharInUtf8File, but add\r
         # the UTF-8 BOM\r
         #\r
-        data = codecs.BOM_UTF8 + '\xed\xa0\x81'\r
+        data = codecs.BOM_UTF8 + b'\xed\xa0\x81'\r
 \r
         self.CheckFile(encoding=None, shouldPass=False, string=data)\r
 \r
index 0c11f6aae94652caab22c79fbba5a492153e3565..af334a8ac2cc7a8fd39d4778b442aa665c12d38d 100644 (file)
@@ -14,7 +14,7 @@
 all: test\r
 \r
 test:\r
-       @if command -v python2 >/dev/null 2>&1; then python2 RunTests.py; else python RunTests.py; fi\r
+       @if command -v $(PYTHON3) >/dev/null 2>&1; then $(PYTHON3) RunTests.py; else python RunTests.py; fi\r
 \r
 clean:\r
        find . -name '*.pyc' -exec rm '{}' ';'\r
index e16e993048e469ea58481e40955375deb40ba298..65948a7ae2ec039f8dd089673b5e659510cb57f1 100644 (file)
@@ -40,7 +40,7 @@ if PythonSourceDir not in sys.path:
 \r
 def MakeTheTestSuite(localItems):\r
     tests = []\r
-    for name, item in localItems.iteritems():\r
+    for name, item in localItems.items():\r
         if isinstance(item, type):\r
             if issubclass(item, unittest.TestCase):\r
                 tests.append(unittest.TestLoader().loadTestsFromTestCase(item))\r
@@ -146,9 +146,12 @@ class BaseToolsTest(unittest.TestCase):
         return data\r
 \r
     def WriteTmpFile(self, fileName, data):\r
-        f = open(self.GetTmpFilePath(fileName), 'w')\r
-        f.write(data)\r
-        f.close()\r
+        if isinstance(data, bytes):\r
+            with open(self.GetTmpFilePath(fileName), 'wb') as f:\r
+                f.write(data)\r
+        else:\r
+            with open(self.GetTmpFilePath(fileName), 'w') as f:\r
+                f.write(data)\r
 \r
     def GenRandomFileData(self, fileName, minlen = None, maxlen = None):\r
         if maxlen is None: maxlen = minlen\r
@@ -161,7 +164,7 @@ class BaseToolsTest(unittest.TestCase):
         if maxlen is None: maxlen = minlen\r
         return ''.join(\r
             [chr(random.randint(0, 255))\r
-             for x in xrange(random.randint(minlen, maxlen))\r
+             for x in range(random.randint(minlen, maxlen))\r
             ])\r
 \r
     def setUp(self):\r
@@ -183,4 +186,3 @@ class BaseToolsTest(unittest.TestCase):
 \r
         os.environ['PATH'] = self.savedEnvPath\r
         sys.path = self.savedSysPath\r
-\r